Skip to content

Commit c99a16e

Browse files
author
Alan Lam
committed
fix
1 parent a88315b commit c99a16e

File tree

2 files changed

+6
-40
lines changed

2 files changed

+6
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ example1
55
example2
66
*.a
77
.DS_Store
8+
.*.swp
89

910
/SQLiteCpp.sln
1011
*.ncb

examples/example2/main.cpp

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,9 @@ static inline std::string getExamplePath()
4242

4343
/// Example Database
4444
static const std::string filename_example_db3 = getExamplePath() + "/example.db3";
45-
/// Image
46-
static const std::string filename_logo_png = getExamplePath() + "/logo.png";
4745

4846

4947
/// 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-
8648
int main ()
8749
{
8850
// Using SQLITE_VERSION would require #include <sqlite3.h> which we want to avoid: use SQLite::VERSION if possible.
@@ -91,6 +53,10 @@ int main ()
9153
std::cout << "SQliteC++ version " << SQLITECPP_VERSION << std::endl;
9254

9355
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+
}
9460
std::string line;
9561
////////////////////////////////////////////////////////////////////////////
9662
// Simple batch queries example (5/7) :
@@ -100,13 +66,12 @@ int main ()
10066
SQLite::Database db("test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
10167
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
10268

103-
// Create a new table with an explicit "id" column aliasing the underlying rowid
10469
db.exec("DROP TABLE IF EXISTS en");
10570
db.exec("CREATE TABLE en (sentence TEXT)");
10671
SQLite::Statement query(db, "INSERT INTO en VALUES(?)");
10772

10873
while (std::getline(infile,line)) {
109-
SQLite::bind(query,line.c_str());
74+
query.bindNoCopy(1,line);
11075
query.exec();
11176
query.reset();
11277
}

0 commit comments

Comments
 (0)