这里主要是对sqlite数据库数据的增、改、删、查操作的介绍:
下面是使用的实例代码:
void OperationData()
{
// Open a database file in create/write mode
SQLite::Database db("test.db", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
string strName = db.getFilename().c_str();
// Create a new table with an explicit "id" column aliasing the underlying rowid
db.exec("DROP TABLE IF EXISTS test");
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)");
// first row
int nb = db.exec("INSERT INTO test VALUES (NULL, \"test\")");
// second row
nb = db.exec("INSERT INTO test VALUES (NULL, \"second\")");
// update the second row
nb = db.exec("UPDATE test SET value=\"second-updated\" WHERE id='2'");
// Check the results : expect two row of result
SQLite::Statement query(db, "SELECT * FROM test");
while (query.executeStep())
{
int nId = query.getColumn(0);
SQLite::Column column = query.getColumn(1);
const char* strText = column.getText();
int yyy = 55;
}
db.exec("DROP TABLE test");
}
从建库建表建字段到增加记录修改记录的一个完整操作。