Using SQLite?

This is a discussion on Using SQLite? within the C++ Programming forums, part of the General Programming Boards category; A few days ago I ran into SQLite, I was looking for a database system to include into my project. ...

  1. #1
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30

    Question Using SQLite?

    A few days ago I ran into SQLite, I was looking for a database system to include into my project. Well I don't really get the point how this works, does SQLite supports C++, what WIN Binaries do I have to download?

    SQLite download page

    And what does it mean: "This is a DLL of the SQLite library without the TCL bindings. The only external dependency is MSVCRT.DLL". What is TCL and what does dependency to MSVCRT.DLL mean? I'm really new to this, so if anybody allready used this could he point me to the right direction? I just want my command line prog. to be able to write and read some data from a database...Is SQLite portable, because I use Linux and Win together, and I want it to be portable, with a .dll or something?
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,185
    does SQLite supports C++
    Yes, under the C API.

    what WIN Binaries do I have to download?
    hmm... I thought that was idiot proof, but maybe not :P
    Download sqlite-3_1_5.zip to get you started with working with SQLite databases.
    Download sqlitedll-3_1_5.zip so as to get the, um, dll.

    Now here comes the part that I'm not sure of:
    I also downloaded the source, in this case sqlite-source-3_1_5.zip
    I extracted sqlite3.h from the source, and placed it in MinGW's include directory.
    Then I did a:
    dlltool -D sqlite3.dll -d sqlite3.def -l libsqlite3.a
    on the contents of the sqlitedll zip (with MSYS, but I dont think that's needed).
    I moved libsqlite3.a to MinGW's lib directory, and placed sqlite3.dll in Window's system32 directory.
    sqlite3.exe I used for my own evil purposes (in MinGW's bin directory).

    It works for me, but I'm not sure if it's the canonical way to go about it.
    Oh, and for reference I'm using the MinGW port of GCC 3.4.2 on Windows XP.

    What is TCL and what does dependency to MSVCRT.DLL mean?
    TCL is a programming/scripting language.
    You most probably have 'MSVCRT.DLL' on your system.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    Well I use Borland C++ Compiler
    1. Well i downloaded the sorces to, but how do I use it under win, do I have to move the header files into my include folder?
    2... but how do I use the .dlls?
    Last edited by IM!; 03-13-2005 at 08:29 AM.
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,185
    I'm assuming you're using MinGW too, since you didnt say otherwise when I mentioned it.

    in the second the .dll and some .def (what is this for?).
    You can use the def and the dll together with dlltool to create libsqlite3.a
    dlltool -D sqlite3.dll -d sqlite3.def -l libsqlite3.a
    Then move libsqlite3.a to C:\MinGW\lib
    Move sqlite3.dll to somewhere in your system path, probably in C:\Windows\system32

    Well I got them both but I was expecting to get some header files, where should I start? What to include?
    That's why I downloaded sqlite-source-3_1_5.zip and extracted sqlite3.h (not the whole source tree, only that file) to C:\MinGW\include

    In my source files I #include <sqlite3.h>
    At linktime, I pass GCC the parameter -lsqlite3 to link with libsqlite3.a

    If you happen to be using the Dev-C++ IDE, you can try the SQLite devpak available at devpaks.org
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    I just edited my previos post ...got it, well I use Borland C++ Compiler...should I try to set the header file into my include folder? What are the other files in the source zip for?
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,185
    I use Borland C++ Compiler
    hmm... I have no experience with Borland.

    should I try to set the header file into my include folder?
    Yes, I suppose.
    You might try a:
    implib -a -c -f sqlite3.lib sqlite3.dll
    Then place sqlite3.lib in lib, and add it to your project.
    I'm adapting zlib's dll usage file instructions here, so this is just a guess.
    There is also the note that you might need to pass the -a parameter to Borland's compiler so as to compile "using a 4-byte alignment" for modules that are linked to this library file.

    That said, since you're using both Linux and MS Windows, why not go the MinGW route?

    What are the other files in the source zip for?
    Compiling from scratch.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    I guess MinGW would be the right choice, well I also wanted to try DevC++ but in the app. description there was "The executables compiled by Dev-C++ will need MSVCRT.DLL", well I really don't like Microsoft, I want to make software that works on both systems, like for the graphical interface i use QT, works great on both systems!
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  8. #8
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    Ok I placed the header file into my include folder, then I tryed to compile the following code:

    Code:
    #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;
    }
    and of course I got the following error:

    Code:
    > Executing: D:\Programm Files\ConTEXT\ConExec.exe "D:\BorlandCompiler\Bin\bcc32.exe" "sqlite.cpp"
    
    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    sqlite.cpp:
    Warning W8057 sqlite.cpp 11: Parameter 'NotUsed' is never used in function callback(void *,int,char * *,char * *)
    Error E2268 sqlite.cpp 20: Call to undefined function 'exit' in function main(int,char * *)
    *** 1 errors in Compile ***
    > Execution finished.
    Oh yeah... what do you mean by include the lib in your project? Maybe I should really get to DevC++...and get the damn pack from devpaks.org
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,185
    and of course I got the following error:
    heh, I think it's a bug in the example code.
    You should #include <stdlib.h> (or <cstdlib> for exit()

    what do you mean by include the lib in your project?
    That's specific to Borland, so I dont know as I was paraphrasing from another library's docs.
    In any case, just try the #include <stdlib.h> and see if it works.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    Ok I tryed various of combinations: I added another include, replaced stdio.h with stdlib.h, well I get the following error:

    Code:
    > Executing: D:\Programm Files\ConTEXT\ConExec.exe "D:\BorlandCompiler\Bin\bcc32.exe" "SQLITE.cpp"
    
    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    SQLITE.cpp:
    Warning W8057 SQLITE.cpp 12: Parameter 'NotUsed' is never used in function callback(void *,int,char * *,char * *)
    Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
    Error: Unresolved external '_sqlite3_open' referenced from C:\DOCUMENTS AND SETTINGS\SQLITE MAJIC IM\DESKTOP\SQLITE.OBJ
    Error: Unresolved external '_sqlite3_errmsg' referenced from C:\DOCUMENTS AND SETTINGS\SQLITE MAJIC IM\DESKTOP\SQLITE.OBJ
    Error: Unresolved external '_sqlite3_exec' referenced from C:\DOCUMENTS AND SETTINGS\SQLITE MAJIC IM\DESKTOP\SQLITE.OBJ
    Error: Unresolved external '_sqlite3_close' referenced from C:\DOCUMENTS AND SETTINGS\SQLITE MAJIC IM\DESKTOP\SQLITE.OBJ
    > Execution finished.
    I think it's a error in the SQLite configuration, maybe it misses something...
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,185
    What if you try a:
    bcc32 -a -c sqlite.cpp
    bcc32 sqlite.obj sqlite3.lib
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    Nope! It's still not working, but don't worry I will get this to work! Maybe I should just switch to DevC++, is it really true that non of their compiled progs work without that MS .dll?
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  13. #13
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    Allright I installed DevC++ and the SQLite Pack...and it's still not working, same error as the one in my last post...ok...prelast... Any ideas, I'm new to DevC++?
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  14. #14
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    With devc++, are you generating the .a library file? MSVCRT is just the microsoft's c library or its some foundational library. That's not where the problem is because the functions in the error message are SQLite functions. You must not be linking in the sqlite's library or you've downloaded the old API with sqlite_ functions sqlite3 functions. Try reading this site and see if you generate a .lib file for borland. http://www.xploiter.com/programming/c/borland/3173.html

  15. #15
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    Well I can use the IMPDEF command, but the LIB command is not working, it says that it can't recognize it?
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ & Sqlite3
    By Sparrowhawk in forum Windows Programming
    Replies: 2
    Last Post: 03-11-2009, 02:33 PM
  2. SQLite not performing update
    By OnionKnight in forum C Programming
    Replies: 0
    Last Post: 01-21-2009, 04:21 PM
  3. setting up SQLite with Visual C++ Express
    By ac251404 in forum Windows Programming
    Replies: 6
    Last Post: 08-25-2006, 05:54 PM
  4. SQLite questions
    By ac251404 in forum C++ Programming
    Replies: 6
    Last Post: 08-22-2006, 12:00 PM
  5. How to using SQLite with WINAPI
    By nostromos in forum Windows Programming
    Replies: 1
    Last Post: 10-02-2005, 02:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21