00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Exception.h>
00018 #include <spl/io/File.h>
00019 #include <spl/Int32.h>
00020 #include <spl/data/SqlLiteCommand.h>
00021 #include <spl/data/SqlLiteConnection.h>
00022 #include <spl/data/SqlLiteTransaction.h>
00023
00024 #include "src/sqllite/sqlite3.h"
00025
00026 SqlLiteConnection::SqlLiteConnection(const String& databaseFilename)
00027 : Connection("", databaseFilename, "", ""), m_db(NULL)
00028 {
00029 ChangeDatabase(databaseFilename);
00030 }
00031
00032 SqlLiteConnection::~SqlLiteConnection()
00033 {
00034 Close();
00035 }
00036
00038 void SqlLiteConnection::Open()
00039 {
00040 if (NULL == m_db)
00041 {
00042 int sres = sqlite3_open(m_database.GetChars(), (sqlite3 **)&m_db);
00043 if (0 != sres)
00044 {
00045 throw new SqlException(String("Can't open database: ") + sqlite3_errmsg((sqlite3 *)m_db));
00046 }
00047 }
00048 }
00049
00051 void SqlLiteConnection::Close()
00052 {
00053 if (NULL != m_db)
00054 {
00055 sqlite3_close((sqlite3 *)m_db);
00056 m_db = NULL;
00057 }
00058 }
00059
00061 void SqlLiteConnection::ChangeDatabase(const String& databaseFilename)
00062 {
00063 m_database = databaseFilename;
00064 if (NULL != m_db)
00065 {
00066 Close();
00067 Open();
00068 }
00069 }
00070
00071 TransactionPtr SqlLiteConnection::BeginTransaction()
00072 {
00073 return SqlLiteTransactionPtr (new SqlLiteTransaction(m_db));
00074 }
00075
00076 CommandPtr SqlLiteConnection::CreateCommand()
00077 {
00078 return SqlLiteCommandPtr(new SqlLiteCommand(m_db, ""));
00079 }
00080
00081 CommandPtr SqlLiteConnection::CreateCommand(const String& cmdText)
00082 {
00083 return SqlLiteCommandPtr(new SqlLiteCommand(m_db, cmdText));
00084 }
00085
00086 int SqlLiteConnection::ExecuteNonQuery(const String& sql)
00087 {
00088 SqlLiteCommand cmd(m_db, sql);
00089 return cmd.ExecuteNonQuery();
00090 }
00091
00092 RecordSetPtr SqlLiteConnection::ExecuteQuery(const String& sql)
00093 {
00094 SqlLiteCommand cmd(m_db, sql);
00095 return cmd.ExecuteQuery();
00096 }
00097
00098 void SqlLiteConnection::RegisterThread()
00099 {
00100 }
00101
00102 void SqlLiteConnection::RegisterThreadExit()
00103 {
00104 }
00105
00106 void SqlLiteConnection::AllowOutOfOrderCommandParameters(bool allow)
00107 {
00108 }
00109
00110 #if defined(DEBUG)
00111 void SqlLiteConnection::CheckMem() const
00112 {
00113 Connection::CheckMem();
00114 }
00115
00116 void SqlLiteConnection::ValidateMem() const
00117 {
00118 Connection::ValidateMem();
00119 }
00120 #endif
00121