gorexy
asked on
SQLite and VC++
hi
I want to use SQLite and VC++ to develop an application
I am new in SQLite but when I compile its example it got errors
#include <stdio.h>
#include "sqlite3.h"
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc, char **argv){
sqlite3* db;
char *zErrMsg = 0;
int rc;
if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
//exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
// exit(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
sqlite3_close(db);
return 0;
}
but i always get the build error
test2.obj : error LNK2019: unresolved external symbol _sqlite3_exec referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _sqlite3_close referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _sqlite3_errmsg referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _sqlite3_open referenced in function _main
the same problem has been posted here
https://www.experts-exchange.com/questions/21835887/XML-as-database.html
but no reply
so ask here
I want to use SQLite and VC++ to develop an application
I am new in SQLite but when I compile its example it got errors
#include <stdio.h>
#include "sqlite3.h"
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("\n");
return 0;
}
int main(int argc, char **argv){
sqlite3* db;
char *zErrMsg = 0;
int rc;
if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
//exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
// exit(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
}
sqlite3_close(db);
return 0;
}
but i always get the build error
test2.obj : error LNK2019: unresolved external symbol _sqlite3_exec referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _sqlite3_close referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _sqlite3_errmsg referenced in function _main
test2.obj : error LNK2019: unresolved external symbol _sqlite3_open referenced in function _main
the same problem has been posted here
https://www.experts-exchange.com/questions/21835887/XML-as-database.html
but no reply
so ask here
it is not enough to include the "sqlite3.h" header file into your source code, you will need also to LINK the SQLite library into your project (sqlite.lib).
ASKER
can you tell me the step?
ASKER
oh it is in project->properties->linke r->additio nal dependencies
Sorry, gone to lunch, have you successfully compiled?
ASKER
YES! but don't know why the exe can perform properly
i type
test2 mydb select * from mytable
but it keeps showing the usage
not the result
i type
test2 mydb select * from mytable
but it keeps showing the usage
not the result
try with:
test2 mydb "select * from mytable"
test2 mydb "select * from mytable"
ASKER
oh it works...u are a SQLite experienced user!
I still have questions on creating SQLite application, may I ask you later here? and grant you poitns?
I still have questions on creating SQLite application, may I ask you later here? and grant you poitns?
ASKER
I want to do that.
I take the SQL statement as a variable instead of hardcoded inside the program and then the retrieved results as another variable as well for my other applications. So teh SQLite will be like a black box only.
is it possible to do so in SQLite?
I take the SQL statement as a variable instead of hardcoded inside the program and then the retrieved results as another variable as well for my other applications. So teh SQLite will be like a black box only.
is it possible to do so in SQLite?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok I post another topic and hope you can advise as I am new in using SQLite and C++