SQLITE noobfrage



  • Sorry für die Frage aber ich versuche eine Datenbankverbindung mit SQLite herzustellen. Leider krieg ich das nicht ganz hin...

    Die sqlite3.lib habe ich ins libverzeichnis reinkopiert. Und im Viusalstudio (6.0) unter Einstellungen habe ich die Lib auch eingetragen. Jedoch bekomme ich immer noch Fehlermeldungen:

    test.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: __thiscall sqlite3::connection::~connection(void)" (??1connection@sqlite3@@QAE@XZ)

    Folgenden Beispielcode habe ich

    test.cpp

    #include <iostream>
    #include <stdexcept>
    using namespace std;
    
    #include "sqlite3_plus.h"
    
    int main(void) {
    	try {
    		sqlite3::connection con("test.db");
    
    		sqlite3::reader reader=con.executereader("select * from t_test;");
    
    		while(reader.read())
    			cout << reader.getcolname(0) << ": " << reader.getint32(0) << endl;
    
    		reader.close();
    		con.close();
    	}
    	catch(exception &ex) {
    		cerr << "Exception Occured: " << ex.what() << endl;
    	}
    
    	return 0;
    }
    
    /*
    	Copyright (c) 2004 Cory Nelson
    
    	Permission is hereby granted, free of charge, to any person obtaining
    	a copy of this software and associated documentation files (the
    	"Software"), to deal in the Software without restriction, including
    	without limitation the rights to use, copy, modify, merge, publish,
    	distribute, sublicense, and/or sell copies of the Software, and to
    	permit persons to whom the Software is furnished to do so, subject to
    	the following conditions:
    
    	The above copyright notice and this permission notice shall be included
    	in all copies or substantial portions of the Software.
    
    	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    	MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    	IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    	CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    	TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    	SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */
    
    #ifndef __SQLITE3_PLUS_H__
    #define __SQLITE3_PLUS_H__
    
    #include <string>
    #include <vector>
    #include <cstdarg>
    
    namespace sqlite3 {
    	class connection {
    		friend class reader;
    		friend class command;
    	private:
    		void *db;
    
    		class reader _executereader(const char *fmt, va_list args);
    
    	public:
    		connection();
    		connection(const char *db);
    		~connection();
    
    		void open(const char *db);
    		void close();
    
    		__int64 insertid() const;
    
    		int executenonquery(const char *fmt, ...);
    		class reader executereader(const char *fmt, ...);
    
    		int executeint32(const char *fmt, ...);
    		__int64 executeint64(const char *fmt, ...);
    		double executedouble(const char *fmt, ...);
    		std::string executestring(const char *fmt, ...);
    		std::string executeblob(const char *fmt, ...);
    	};
    
    	struct parameter {
    		typedef enum {
    			dt_blob, dt_double, dt_int32, dt_int64, dt_null, dt_text
    		} datatype;
    
    		int index;
    		datatype type;
    		union {
    			struct {
    				union {
    					const void *data_blob;
    					const char *data_text;
    				};
    				int data_length;
    			};
    			double data_double;
    			int data_int32;
    			__int64 data_int64;
    		};
    
    		parameter() {};
    		parameter(int index) : index(index),type(dt_null) {};
    		parameter(int index, const void *data, int length) : index(index),type(dt_blob),data_blob(data),data_length(length) {};
    		parameter(int index, const char *data, int length) : index(index),type(dt_text),data_text(data),data_length(length) {};
    		parameter(int index, double data) : index(index),type(dt_double),data_double(data) {};
    		parameter(int index, int data) : index(index),type(dt_int32),data_int32(data) {};
    		parameter(int index, __int64 data) : index(index),type(dt_int64),data_int64(data) {};
    	};
    
    	class command {
    	private:
    		class connection &con;
    
    	public:
    		std::string cmdstr;
    		std::vector<parameter> parameters;
    
    		command(connection &c) : con(c) {};
    		command(connection &c, const char *sql) : con(c),cmdstr(sql) {};
    
    		int executenonquery();
    		class reader executereader();
    
    		int executeint32();
    		__int64 executeint64();
    		double executedouble();
    		std::string executestring();
    		std::string executeblob();
    	};
    
    	class reader {
    		friend class connection;
    		friend class command;
    
    	private:
    		class connection *con;
    		void *vm;
    		int argc;
    
    	public:
    		reader();
    		bool read();
    		void close();
    		void reset();
    
    		int getint32(int index) const;
    		__int64 getint64(int index) const;
    		double getdouble(int index) const;
    		std::string getstring(int index) const;
    		std::string getblob(int index) const;
    		std::string getcolname(int index) const;
    
    		std::string operator[](int index) const;
    	};
    };
    
    #endif
    


  • hi,

    hast du den C++ Wrapper für SQLite auch kompiliert oder einfach nur den Header eingebunden?
    Oder hast du überhaupt den Sourcecode für SQLite3 bzw. die richtige Lib dafür?

    Du solltest mal nen Blick auch auf http://sqlite.org werfen.

    MfG eViLiSSiMo



  • hmm habe einfach die lib aus einem sqlite beispiel kopiert. das scheint wohl faltsch zu sein?! 😕



  • Du musst das verzeichnis wo die lib liegt bei deinem compiler angeben, damit er sie verwenden kann.



  • habe ich im viusalstudio projekt>einstellungen/linker>sqlite3.lib. die lib habe ich ins lib verzeichnis vom viusalstudio reinkopiert.
    Muss ich da nichts mehr mit der DLL oder so machen? Ich bin mir nicht sicher ob ich das ganze richtig verstanden habe. suche nun schon lange auf sqlite.org etc. rum aber komme auf keinen grünen zweig.



  • ohne grad zeit zu haben zum lesen..
    leg mal die lib und die dll neben die exe.. projektverzeichnis bzw..



  • hat nichts gebracht. aber muss ich die dll auch noch irgendwo angeben oder so?



  • so habe noch etwas rumprobiert. folgendes problem habe ich noch

    insert.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: __thiscall sqlite3::connection::~connection(void)" (??1connection@sqlite3@@QAE@XZ)
    insert.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: void __thiscall sqlite3::connection::close(void)" (?close@connection@sqlite3@@QAEXXZ)
    insert.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: int __cdecl sqlite3::connection::executenonquery(char const *,...)" (?executenonquery@connection@sqlite3@@QAAHPBDZZ)
    insert.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: int __cdecl sqlite3::connection::executeint32(char const *,...)" (?executeint32@connection@sqlite3@@QAAHPBDZZ)
    insert.obj : error LNK2001: Nichtaufgeloestes externes Symbol "public: __thiscall sqlite3::connection::connection(char const *)" (??0connection@sqlite3@@QAE@PBD@Z)
    Debug/insert.exe : fatal error LNK1120: 5 unaufgeloeste externe Verweise
    Fehler beim Ausführen von link.exe.

    irgendwie fehlt ihm da doch was nocht?!



  • Komisch, da gibt es so viele sqlite Befürworter / Fans aber niemand hat Erfahrungen oder will wenigstens ein tipp dazuabgeben 😞 ...



  • bedenke, die meisten mit sqlite arbeiten unter linux.

    du machst es unter win mit visual studio. da musst du auf der entsprechenden seite erstmal schaun, ob das unterstützt wird.

    wird es. seit noch nicht so langem, aber nun ist es dabei. du hast glück.

    wenn du dann mal schaust, findest du auf der sqlite seite dieses:

    MSVC and SQLite DLL

    Creation of an import library from the sqlitedll.zip (http://www.sqlite.org/sqlitedll.zip) for MS Visual C++ is achieved by the
    following command:

    LIB /DEF:sqlite.def

    This makes the files sqlite.lib and sqlite.exp files. The sqlite.lib can then be
    used to link your programs against the SQLite DLL.

    http://www.sqlite.org/cvstrac/wiki?p=HowToCompile

    ps: ich selber habe sqlite nicht zu laufen, aber wenn du dich auf sowas einläßt, musst du nach dem jeweiligen compiler recherchieren, und schaun, ob er unterstützt wird, und wie.

    so long


Anmelden zum Antworten