我使用c:\ tmp中的以下代码在C ++中创建了数据库。还创建了表,可以在C ++中访问表。但是当我尝试通过SQLite命令行访问该表时,我得到了#34;没有这样的表"错误。
以下是我在C ++中创建数据库的方法
rc = sqlite3_open_v2("file:///C:/tmp/myTest1.db", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE| SQLITE_OPEN_URI, NULL );
if( rc ){
printf( "Can't open database: %s\n", sqlite3_errmsg(db));
return(0);
}else{
printf( "Opened database successfully\n");
}
/* Create SQL statement */
sql = "CREATE TABLE LoadDates(" \
"ID TEXT NOT NULL," \
"DT INT NOT NULL );";
/* Execute SQL statement */
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
printf( "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
printf( "Table created successfully\n");
}
sql = "INSERT INTO LoadDates (ID,DT) " \
"VALUES ('A1', 20160701 ); " \
"INSERT INTO LoadDates (ID,DT) " \
"VALUES ('A2', 20160601 ); " \
"INSERT INTO LoadDates (ID,DT) " \
"VALUES ('A3', 20160801 );";
/* Execute SQL statement */
rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
if( rc != SQLITE_OK ){
printf( "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}else{
printf( "Records created successfully\n");
}
然后当我通过命令行访问LoadDates时,我得到以下错误。我可以在c:\ tmp目录中看到myTest1.db
c:\tmp>sqlite3.exe myTest1
SQLite version 3.13.0 2016-05-18 10:57:30
Enter ".help" for usage hints.
sqlite> select * from LoadDates;
Error: no such table: LoadDates
答案 0 :(得分:1)
在命令行上调用sqlite3.exe
时使用完整文件名:
C:\temp> sqlite3.exe myTest1.db