@@ -42,47 +42,9 @@ static inline std::string getExamplePath()
42
42
43
43
// / Example Database
44
44
static const std::string filename_example_db3 = getExamplePath() + " /example.db3" ;
45
- // / Image
46
- static const std::string filename_logo_png = getExamplePath() + " /logo.png" ;
47
45
48
46
49
47
// / Object Oriented Basic example
50
- class Example
51
- {
52
- public:
53
- // Constructor
54
- Example () :
55
- mDb (filename_example_db3), // Open a database file in readonly mode
56
- mQuery (mDb , " SELECT * FROM test WHERE weight > :min_weight" )// Compile a SQL query, containing one parameter (index 1)
57
- {
58
- }
59
- virtual ~Example ()
60
- {
61
- }
62
-
63
- // / List the rows where the "weight" column is greater than the provided aParamValue
64
- void ListGreaterThan (const int aParamValue)
65
- {
66
- std::cout << " ListGreaterThan (" << aParamValue << " )\n " ;
67
-
68
- // Bind the integer value provided to the first parameter of the SQL query
69
- mQuery .bind (" :min_weight" , aParamValue); // same as mQuery.bind(1, aParamValue);
70
-
71
- // Loop to execute the query step by step, to get one a row of results at a time
72
- while (mQuery .executeStep ())
73
- {
74
- std::cout << " row (" << mQuery .getColumn (0 ) << " , \" " << mQuery .getColumn (1 ) << " \" , " << mQuery .getColumn (2 ) << " )\n " ;
75
- }
76
-
77
- // Reset the query to be able to use it again later
78
- mQuery .reset ();
79
- }
80
-
81
- private:
82
- SQLite::Database mDb ; // /< Database connection
83
- SQLite::Statement mQuery ; // /< Database prepared SQL query
84
- };
85
-
86
48
int main ()
87
49
{
88
50
// Using SQLITE_VERSION would require #include <sqlite3.h> which we want to avoid: use SQLite::VERSION if possible.
@@ -91,6 +53,10 @@ int main ()
91
53
std::cout << " SQliteC++ version " << SQLITECPP_VERSION << std::endl;
92
54
93
55
std::ifstream infile (" /home/alan/Downloads/tmp/en-zh/UNv1.0.en-zh.en" );
56
+ if ( infile.fail ()) {
57
+ std::cout << " fail to open file" <<std::endl;
58
+ return EXIT_FAILURE;
59
+ }
94
60
std::string line;
95
61
// //////////////////////////////////////////////////////////////////////////
96
62
// Simple batch queries example (5/7) :
@@ -100,13 +66,12 @@ int main ()
100
66
SQLite::Database db (" test.db3" , SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
101
67
std::cout << " SQLite database file '" << db.getFilename ().c_str () << " ' opened successfully\n " ;
102
68
103
- // Create a new table with an explicit "id" column aliasing the underlying rowid
104
69
db.exec (" DROP TABLE IF EXISTS en" );
105
70
db.exec (" CREATE TABLE en (sentence TEXT)" );
106
71
SQLite::Statement query (db, " INSERT INTO en VALUES(?)" );
107
72
108
73
while (std::getline (infile,line)) {
109
- SQLite::bind ( query,line. c_str () );
74
+ query. bindNoCopy ( 1 ,line );
110
75
query.exec ();
111
76
query.reset ();
112
77
}
0 commit comments