• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1577
  • Last Modified:

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
http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21835887.html
but no reply
so ask here
0
gorexy
Asked:
gorexy
  • 6
  • 4
1 Solution
 
Jaime OlivaresCommented:
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).


0
 
gorexyAuthor Commented:
can you tell me the step?
0
 
gorexyAuthor Commented:
oh it is in project->properties->linker->additional dependencies
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 
Jaime OlivaresCommented:
Sorry, gone to lunch, have you successfully compiled?
0
 
gorexyAuthor Commented:
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
0
 
Jaime OlivaresCommented:
try with:
test2 mydb "select * from mytable"
0
 
gorexyAuthor Commented:
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?
0
 
gorexyAuthor Commented:
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?
0
 
Jaime OlivaresCommented:
>u are a SQLite experienced user!
Sincerely I have never used it, just I am an old programmer.

>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
This is perfect possible. You just have to learn to build strings in C/C++.
By example, instead of this:
      rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
You can build your own SQL sentence on the fly:
      char mysentence[255];
      int testcode = 54327;  // test code, can be obtained from anywhere
      sprintf(mysentence, "SELECT * FROM MYTABLE WHERE CODE='%i'", testcode);
      rc = sqlite3_exec(db, mysentence, callback, 0, &zErrMsg);
But you must post a different question for this.....
0
 
gorexyAuthor Commented:
ok I post another topic and hope you can advise as I am new in using SQLite and C++
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now