diff --git a/Data/samples/Binding/Binding_vs71.vcproj b/Data/samples/Binding/Binding_vs71.vcproj new file mode 100644 index 000000000..90ae76549 --- /dev/null +++ b/Data/samples/Binding/Binding_vs71.vcproj @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Data/samples/Binding/Binding_vs80.vcproj b/Data/samples/Binding/Binding_vs80.vcproj new file mode 100644 index 000000000..4c805c9a3 --- /dev/null +++ b/Data/samples/Binding/Binding_vs80.vcproj @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Data/samples/Binding/Makefile b/Data/samples/Binding/Makefile new file mode 100644 index 000000000..2319ef6cd --- /dev/null +++ b/Data/samples/Binding/Makefile @@ -0,0 +1,17 @@ +# +# Makefile +# +# $Id: //poco/Main/Data/samples/Binding/Makefile#1 $ +# +# Makefile for Poco Data Binding sample +# + +include $(POCO_BASE)/build/rules/global + +objects = Binding + +target = Binding +target_version = 1 +target_libs = PocoFoundation PocoData PocoSQLite + +include $(POCO_BASE)/build/rules/exec diff --git a/Data/samples/Binding/src/Binding.cpp b/Data/samples/Binding/src/Binding.cpp new file mode 100644 index 000000000..822cdc82d --- /dev/null +++ b/Data/samples/Binding/src/Binding.cpp @@ -0,0 +1,100 @@ +// +// Binding.cpp +// +// $Id: //poco/Main/Data/samples/Binding/src/Binding.cpp#1 $ +// +// This sample demonstrates the Data library. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// All rights reserved. +// +// This is unpublished proprietary source code of Applied Informatics +// Software Engineering GmbH. +// The contents of this file may not be disclosed to third parties, +// copied or duplicated in any form, in whole or in part, without +// prior written permission from Applied Informatics. +// + + +#include "Poco/SharedPtr.h" +#include "Poco/Data/SessionFactory.h" +#include "Poco/Data/Session.h" +#include "Poco/Data/SQLite/Connector.h" +#include +#include + + +using namespace Poco::Data; + + +struct Person +{ + std::string name; + std::string address; + int age; +}; + + +int main(int argc, char** argv) +{ + // register SQLite connector + Poco::Data::SQLite::Connector::registerConnector(); + + // create a session + Session session("SQLite", "sample.db"); + + // drop sample table, if it exists + session << "DROP TABLE IF EXISTS Person", now; + + // (re)create table + session << "CREATE TABLE Person (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3))", now; + + // insert some rows + Person person = + { + "Bart Simpson", + "Springfield", + 12 + }; + + Statement insert(session); + insert << "INSERT INTO Person VALUES(:name, :address, :age)", + use(person.name), + use(person.address), + use(person.age); + + insert.execute(); + + person.name = "Lisa Simpson"; + person.address = "Springfield"; + person.age = 10; + + insert.execute(); + + // a simple query + Statement select(session); + select << "SELECT Name, Address, Age FROM Person", + into(person.name), + into(person.address), + into(person.age), + range(0, 1); // iterate over result set one row at a time + + while (!select.done()) + { + select.execute(); + std::cout << person.name << " " << person.address << " " << person.age << std::endl; + } + + // another query - store the result in a container + std::vector names; + session << "SELECT Name FROM Person", + into(names), + now; + + for (std::vector::const_iterator it = names.begin(); it != names.end(); ++it) + { + std::cout << *it << std::endl; + } + + return 0; +} diff --git a/Data/samples/Makefile b/Data/samples/Makefile new file mode 100644 index 000000000..70541c870 --- /dev/null +++ b/Data/samples/Makefile @@ -0,0 +1,14 @@ +# +# Makefile +# +# $Id: //poco/Main/Data/samples/Makefile#1 $ +# +# Makefile for Poco Data Samples +# + +.PHONY: projects +clean all: projects +projects: + $(MAKE) -C Binding $(MAKECMDGOALS) + $(MAKE) -C TypeHandler $(MAKECMDGOALS) + $(MAKE) -C RecordSet $(MAKECMDGOALS) diff --git a/Data/samples/RecordSet/Makefile b/Data/samples/RecordSet/Makefile new file mode 100644 index 000000000..ce4660f35 --- /dev/null +++ b/Data/samples/RecordSet/Makefile @@ -0,0 +1,17 @@ +# +# Makefile +# +# $Id: //poco/Main/Data/samples/RecordSet/Makefile#1 $ +# +# Makefile for Poco Data RecordSet sample +# + +include $(POCO_BASE)/build/rules/global + +objects = RecordSet + +target = RecordSet +target_version = 1 +target_libs = PocoFoundation PocoData PocoSQLite + +include $(POCO_BASE)/build/rules/exec diff --git a/Data/samples/RecordSet/RecordSet_vs71.vcproj b/Data/samples/RecordSet/RecordSet_vs71.vcproj new file mode 100644 index 000000000..cfd4990d1 --- /dev/null +++ b/Data/samples/RecordSet/RecordSet_vs71.vcproj @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Data/samples/RecordSet/RecordSet_vs80.vcproj b/Data/samples/RecordSet/RecordSet_vs80.vcproj new file mode 100644 index 000000000..627437832 --- /dev/null +++ b/Data/samples/RecordSet/RecordSet_vs80.vcproj @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Data/samples/RecordSet/src/RecordSet.cpp b/Data/samples/RecordSet/src/RecordSet.cpp new file mode 100644 index 000000000..4ea25bdd8 --- /dev/null +++ b/Data/samples/RecordSet/src/RecordSet.cpp @@ -0,0 +1,77 @@ +// +// RecordSet.cpp +// +// $Id: //poco/Main/Data/samples/RecordSet/src/RecordSet.cpp#1 $ +// +// This sample demonstrates the Data library. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// All rights reserved. +// +// This is unpublished proprietary source code of Applied Informatics +// Software Engineering GmbH. +// The contents of this file may not be disclosed to third parties, +// copied or duplicated in any form, in whole or in part, without +// prior written permission from Applied Informatics. +// + + +#include "Poco/SharedPtr.h" +#include "Poco/Data/SessionFactory.h" +#include "Poco/Data/Session.h" +#include "Poco/Data/RecordSet.h" +#include "Poco/Data/Column.h" +#include "Poco/Data/SQLite/Connector.h" +#include + + +using namespace Poco::Data; + + +struct Person +{ + std::string name; + std::string address; + int age; +}; + + +int main(int argc, char** argv) +{ + // register SQLite connector + Poco::Data::SQLite::Connector::registerConnector(); + + // create a session + Session session("SQLite", "sample.db"); + + // drop sample table, if it exists + session << "DROP TABLE IF EXISTS Person", now; + + // (re)create table + session << "CREATE TABLE Person (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3))", now; + + // insert some rows + session << "INSERT INTO Person VALUES('Bart Simpson', 'Springfield', 12)", now; + session << "INSERT INTO Person VALUES('Lisa Simpson', 'Springfield', 10)", now; + + // a simple query + Statement select(session); + select << "SELECT * FROM Person"; + select.execute(); + + // create a RecordSet and iterate over it + RecordSet rs(select); + std::size_t cols = rs.columnCount(); + bool more = rs.moveFirst(); + while (more) + { + for (std::size_t col = 1; col <= cols; ++col) + { + std::cout << rs[col].convert() << " "; + } + std::cout << std::endl; + more = rs.moveNext(); + } + + return 0; +} diff --git a/Data/samples/TypeHandler/Makefile b/Data/samples/TypeHandler/Makefile new file mode 100644 index 000000000..221e3cf33 --- /dev/null +++ b/Data/samples/TypeHandler/Makefile @@ -0,0 +1,17 @@ +# +# Makefile +# +# $Id: //poco/Main/Data/samples/TypeHandler/Makefile#1 $ +# +# Makefile for Poco Data TypeHandler sample +# + +include $(POCO_BASE)/build/rules/global + +objects = TypeHandler + +target = TypeHandler +target_version = 1 +target_libs = PocoFoundation PocoData PocoSQLite + +include $(POCO_BASE)/build/rules/exec diff --git a/Data/samples/TypeHandler/TypeHandler_vs71.vcproj b/Data/samples/TypeHandler/TypeHandler_vs71.vcproj new file mode 100644 index 000000000..399691f1a --- /dev/null +++ b/Data/samples/TypeHandler/TypeHandler_vs71.vcproj @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Data/samples/TypeHandler/TypeHandler_vs80.vcproj b/Data/samples/TypeHandler/TypeHandler_vs80.vcproj new file mode 100644 index 000000000..d1f2497cd --- /dev/null +++ b/Data/samples/TypeHandler/TypeHandler_vs80.vcproj @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Data/samples/TypeHandler/src/TypeHandler.cpp b/Data/samples/TypeHandler/src/TypeHandler.cpp new file mode 100644 index 000000000..bda92bc10 --- /dev/null +++ b/Data/samples/TypeHandler/src/TypeHandler.cpp @@ -0,0 +1,138 @@ +// +// Binding.cpp +// +// $Id: //poco/Main/Data/samples/TypeHandler/src/TypeHandler.cpp#1 $ +// +// This sample demonstrates the Data library. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// All rights reserved. +// +// This is unpublished proprietary source code of Applied Informatics +// Software Engineering GmbH. +// The contents of this file may not be disclosed to third parties, +// copied or duplicated in any form, in whole or in part, without +// prior written permission from Applied Informatics. +// + + +#include "Poco/SharedPtr.h" +#include "Poco/Data/SessionFactory.h" +#include "Poco/Data/Session.h" +#include "Poco/Data/TypeHandler.h" +#include "Poco/Data/SQLite/Connector.h" +#include +#include + + +using namespace Poco::Data; + + +struct Person +{ + std::string name; + std::string address; + int age; +}; + + +namespace Poco { +namespace Data { + + +template <> +class TypeHandler + /// Defining a specialization of TypeHandler for Person allows us + /// to use the Person struct in use and into clauses. +{ +public: + static std::size_t size() + { + return 3; + } + + static void bind(std::size_t pos, const Person& person, AbstractBinder* pBinder) + { + TypeHandler::bind(pos++, person.name, pBinder); + TypeHandler::bind(pos++, person.address, pBinder); + TypeHandler::bind(pos++, person.age, pBinder); + } + + static void extract(std::size_t pos, Person& person, const Person& deflt, AbstractExtractor* pExtr) + { + TypeHandler::extract(pos++, person.name, deflt.name, pExtr); + TypeHandler::extract(pos++, person.address, deflt.address, pExtr); + TypeHandler::extract(pos++, person.age, deflt.age, pExtr); + } + + static void prepare(std::size_t pos, const Person& person, AbstractPreparation* pPrep) + { + TypeHandler::prepare(pos++, person.name, pPrep); + TypeHandler::prepare(pos++, person.address, pPrep); + TypeHandler::prepare(pos++, person.age, pPrep); + } +}; + + +} } // namespace Poco::Data + + +int main(int argc, char** argv) +{ + // register SQLite connector + Poco::Data::SQLite::Connector::registerConnector(); + + // create a session + Session session("SQLite", "sample.db"); + + // drop sample table, if it exists + session << "DROP TABLE IF EXISTS Person", now; + + // (re)create table + session << "CREATE TABLE Person (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3))", now; + + // insert some rows + Person person = + { + "Bart Simpson", + "Springfield", + 12 + }; + + Statement insert(session); + insert << "INSERT INTO Person VALUES(:name, :address, :age)", + use(person); + + insert.execute(); + + person.name = "Lisa Simpson"; + person.address = "Springfield"; + person.age = 10; + + insert.execute(); + + // a simple query + Statement select(session); + select << "SELECT Name, Address, Age FROM Person", + into(person), + range(0, 1); // iterate over result set one row at a time + + while (!select.done()) + { + select.execute(); + std::cout << person.name << " " << person.address << " " << person.age << std::endl; + } + + // another query - store the result in a container + std::vector persons; + session << "SELECT Name, Address, Age FROM Person", + into(persons), + now; + + for (std::vector::const_iterator it = persons.begin(); it != persons.end(); ++it) + { + std::cout << it->name << " " << it->address << " " << it->age << std::endl; + } + + return 0; +} diff --git a/Data/samples/samples_vs71.sln b/Data/samples/samples_vs71.sln new file mode 100644 index 000000000..35dfdc8da --- /dev/null +++ b/Data/samples/samples_vs71.sln @@ -0,0 +1,37 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Binding", "Binding\Binding_vs71.vcproj", "{54BCEDA8-C241-4DCF-AEAD-6177F115B0D0}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TypeHandler", "TypeHandler\TypeHandler_vs71.vcproj", "{822AEE4A-48B6-4B45-AB04-5C3C21C365C5}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RecordSet", "RecordSet\RecordSet_vs71.vcproj", "{56F66D36-F11E-4AA1-AD37-4518A253059D}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + debug_shared = debug_shared + release_shared = release_shared + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {54BCEDA8-C241-4DCF-AEAD-6177F115B0D0}.debug_shared.ActiveCfg = debug_shared|Win32 + {54BCEDA8-C241-4DCF-AEAD-6177F115B0D0}.debug_shared.Build.0 = debug_shared|Win32 + {54BCEDA8-C241-4DCF-AEAD-6177F115B0D0}.release_shared.ActiveCfg = release_shared|Win32 + {54BCEDA8-C241-4DCF-AEAD-6177F115B0D0}.release_shared.Build.0 = release_shared|Win32 + {822AEE4A-48B6-4B45-AB04-5C3C21C365C5}.debug_shared.ActiveCfg = debug_shared|Win32 + {822AEE4A-48B6-4B45-AB04-5C3C21C365C5}.debug_shared.Build.0 = debug_shared|Win32 + {822AEE4A-48B6-4B45-AB04-5C3C21C365C5}.release_shared.ActiveCfg = release_shared|Win32 + {822AEE4A-48B6-4B45-AB04-5C3C21C365C5}.release_shared.Build.0 = release_shared|Win32 + {56F66D36-F11E-4AA1-AD37-4518A253059D}.debug_shared.ActiveCfg = debug_shared|Win32 + {56F66D36-F11E-4AA1-AD37-4518A253059D}.debug_shared.Build.0 = debug_shared|Win32 + {56F66D36-F11E-4AA1-AD37-4518A253059D}.release_shared.ActiveCfg = release_shared|Win32 + {56F66D36-F11E-4AA1-AD37-4518A253059D}.release_shared.Build.0 = release_shared|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/Data/samples/samples_vs80.sln b/Data/samples/samples_vs80.sln new file mode 100644 index 000000000..043272891 --- /dev/null +++ b/Data/samples/samples_vs80.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Binding", "Binding\Binding_vs80.vcproj", "{F2972327-DCA7-49BB-B55D-66C554CF1205}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TypeHandler", "TypeHandler\TypeHandler_vs80.vcproj", "{822AEE4A-48B6-4B45-AB04-5C3C21C365C5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RecordSet", "RecordSet\RecordSet_vs80.vcproj", "{56F66D36-F11E-4AA1-AD37-4518A253059D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + debug_shared|Win32 = debug_shared|Win32 + release_shared|Win32 = release_shared|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F2972327-DCA7-49BB-B55D-66C554CF1205}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {F2972327-DCA7-49BB-B55D-66C554CF1205}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {F2972327-DCA7-49BB-B55D-66C554CF1205}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {F2972327-DCA7-49BB-B55D-66C554CF1205}.release_shared|Win32.Build.0 = release_shared|Win32 + {822AEE4A-48B6-4B45-AB04-5C3C21C365C5}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {822AEE4A-48B6-4B45-AB04-5C3C21C365C5}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {822AEE4A-48B6-4B45-AB04-5C3C21C365C5}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {822AEE4A-48B6-4B45-AB04-5C3C21C365C5}.release_shared|Win32.Build.0 = release_shared|Win32 + {56F66D36-F11E-4AA1-AD37-4518A253059D}.debug_shared|Win32.ActiveCfg = debug_shared|Win32 + {56F66D36-F11E-4AA1-AD37-4518A253059D}.debug_shared|Win32.Build.0 = debug_shared|Win32 + {56F66D36-F11E-4AA1-AD37-4518A253059D}.release_shared|Win32.ActiveCfg = release_shared|Win32 + {56F66D36-F11E-4AA1-AD37-4518A253059D}.release_shared|Win32.Build.0 = release_shared|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal