|
UniSet
2.2.1
|
00001 /* This file is part of the UniSet project 00002 * Copyright (c) 2002 Free Software Foundation, Inc. 00003 * Copyright (c) 2002 Pavel Vainerman 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 // -------------------------------------------------------------------------- 00023 //---------------------------------------------------------------------------- 00024 #ifndef SQLiteInterface_H_ 00025 #define SQLiteInterface_H_ 00026 // --------------------------------------------------------------------------- 00027 #include <string> 00028 #include <deque> 00029 #include <vector> 00030 #include <iostream> 00031 #include <sqlite3.h> 00032 #include "PassiveTimer.h" 00033 #include <DBInterface.h> 00034 // ---------------------------------------------------------------------------- 00079 // ---------------------------------------------------------------------------- 00080 // Памятка: 00081 // Включение режима для журнала - "вести в памяти" (чтобы поберечь CompactFlash) 00082 // PRAGMA journal_mode = MEMORY 00083 // При этом конечно есть риск потерять данные при выключении.. 00084 // ---------------------------------------------------------------------------- 00085 class SQLiteInterface: 00086 public DBInterface 00087 { 00088 public: 00089 00090 SQLiteInterface(); 00091 ~SQLiteInterface(); 00092 00093 virtual bool connect( const std::string& param ) override; 00094 bool connect( const std::string& dbfile, bool create ); 00095 virtual bool close() override; 00096 virtual bool isConnection() override; 00097 virtual bool ping() override; // проверка доступности БД 00098 00099 void setOperationTimeout( timeout_t msec ); 00100 inline timeout_t getOperationTimeout() 00101 { 00102 return opTimeout; 00103 } 00104 00105 inline void setOperationCheckPause( timeout_t msec ) 00106 { 00107 opCheckPause = msec; 00108 } 00109 inline timeout_t getOperationCheckPause() 00110 { 00111 return opCheckPause; 00112 } 00113 00114 virtual DBResult query( const std::string& q ) override; 00115 virtual const std::string lastQuery() override; 00116 00117 virtual bool insert( const std::string& q ) override; 00118 virtual double insert_id() override; 00119 00120 virtual const std::string error() override; 00121 00122 protected: 00123 00124 bool wait( sqlite3_stmt* stmt, int result ); 00125 static bool checkResult( int rc ); 00126 00127 private: 00128 00129 void makeResult(DBResult& dbres, sqlite3_stmt* s, bool finalize = true ); 00130 sqlite3* db; 00131 // sqlite3_stmt* curStmt; 00132 00133 std::string lastQ; 00134 std::string lastE; 00135 bool queryok; // успешность текущего запроса 00136 bool connected; 00137 00138 timeout_t opTimeout; 00139 timeout_t opCheckPause; 00140 }; 00141 // ---------------------------------------------------------------------------- 00142 // ---------------------------------------------------------------------------- 00143 #endif 00144 // ----------------------------------------------------------------------------------
1.7.6.1