mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
updated Data samples; updated SQlite to 3.5.5
This commit is contained in:
parent
be815af919
commit
cf60e2a5d8
150806
Data/SQLite/src/sqlite3.c
150806
Data/SQLite/src/sqlite3.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
//
|
||||
// Binding.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/samples/Binding/src/Binding.cpp#1 $
|
||||
// $Id: //poco/Main/Data/samples/Binding/src/Binding.cpp#2 $
|
||||
//
|
||||
// This sample demonstrates the Data library.
|
||||
//
|
||||
@ -15,6 +15,7 @@
|
||||
// prior written permission from Applied Informatics.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/SQLite/Connector.h"
|
||||
#include <vector>
|
||||
@ -55,7 +56,7 @@ int main(int argc, char** argv)
|
||||
};
|
||||
|
||||
Statement insert(session);
|
||||
insert << "INSERT INTO Person VALUES(:name, :address, :age)",
|
||||
insert << "INSERT INTO Person VALUES(?, ?, ?)",
|
||||
use(person.name),
|
||||
use(person.address),
|
||||
use(person.age);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#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 <iostream>
|
||||
|
||||
@ -27,6 +28,14 @@
|
||||
using namespace Poco::Data;
|
||||
|
||||
|
||||
struct Person
|
||||
{
|
||||
std::string name;
|
||||
std::string address;
|
||||
int age;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// register SQLite connector
|
||||
@ -42,20 +51,33 @@ int main(int argc, char** argv)
|
||||
session << "CREATE TABLE Person (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3))", now;
|
||||
|
||||
// insert some rows
|
||||
session << "INSERT INTO Person VALUES('Homer Simpson', 'Springfield', 42)", now;
|
||||
session << "INSERT INTO Person VALUES('Marge Simpson', 'Springfield', 38)", now;
|
||||
session << "INSERT INTO Person VALUES('Bart Simpson', 'Springfield', 12)", now;
|
||||
session << "INSERT INTO Person VALUES('Lisa Simpson', 'Springfield', 10)", now;
|
||||
|
||||
// create a recordset and print the column names and data
|
||||
RecordSet rs(session, "SELECT * FROM Person");
|
||||
std::cout << rs;
|
||||
// a simple query
|
||||
Statement select(session);
|
||||
select << "SELECT * FROM Person";
|
||||
select.execute();
|
||||
|
||||
// print just two middle rows
|
||||
std::cout << std::endl << "Middle rows :" << std::endl;
|
||||
rs.copyValues(std::cout, 1, 2);
|
||||
|
||||
std::cout << "---" << std::endl << "Thats all, folks!" << std::endl;
|
||||
// create a RecordSet
|
||||
RecordSet rs(select);
|
||||
std::size_t cols = rs.columnCount();
|
||||
// print all column names
|
||||
for (std::size_t col = 0; col < cols; ++col)
|
||||
{
|
||||
std::cout << rs.columnName(col) << std::endl;
|
||||
}
|
||||
// iterate over all rows and columns
|
||||
bool more = rs.moveFirst();
|
||||
while (more)
|
||||
{
|
||||
for (std::size_t col = 0; col < cols; ++col)
|
||||
{
|
||||
std::cout << rs[col].convert<std::string>() << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
more = rs.moveNext();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// Binding.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/samples/TypeHandler/src/TypeHandler.cpp#2 $
|
||||
// $Id: //poco/Main/Data/samples/TypeHandler/src/TypeHandler.cpp#3 $
|
||||
//
|
||||
// This sample demonstrates the Data library.
|
||||
//
|
||||
@ -100,7 +100,7 @@ int main(int argc, char** argv)
|
||||
};
|
||||
|
||||
Statement insert(session);
|
||||
insert << "INSERT INTO Person VALUES(:name, :address, :age)",
|
||||
insert << "INSERT INTO Person VALUES(?, ?, ?)",
|
||||
use(person);
|
||||
|
||||
insert.execute();
|
||||
|
Loading…
Reference in New Issue
Block a user