WORM 0.2
A C++ DAL/ORM code generation framework
|
00001 /* 00002 WORM - a DAL/ORM code generation framework 00003 Copyright (C) 2011 Erik Winn <erikwinnmail@yahoo.com> 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 3 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, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 00020 #ifndef WSQLITEDRIVER_H 00021 #define WSQLITEDRIVER_H 00022 00023 #include "wsqldriver.h" 00024 #include <map> 00025 00026 #include <sqlite3.h> 00027 00028 namespace WSql 00029 { 00030 00031 class WSqlDatabase; 00032 00033 class WSqliteDriver : public WSqlDriver 00034 { 00035 public: 00036 // WSqliteDriver(); 00037 WSqliteDriver( WSqlDatabase* db ); 00038 ~WSqliteDriver(); 00039 bool open(); 00040 void close(); 00041 bool query( std::string sql ); 00042 WSqlResult* result(bool iscached=true); 00043 00044 std::vector<std::string> tableNames(); 00045 WSqlTable tableMetaData( const std::string &tableName ); 00046 00047 private: 00048 bool _isUtf8; 00049 sqlite3 *_objSqlite; 00050 00051 bool init(); 00052 00053 WSqlDataType::Type sqlite3TypeToWSqlType( std::string tname) const; 00054 WSqlDataType::Type sqlite3TypeToWSqlType(int dtype)const; 00055 std::string fetchTableCreateStatement(const std::string& tablename)const; 00056 std::string extractStatement(const std::string& sql, const char start='(', const char end=')') const; 00057 void parseSchema( std::string& sql); 00058 bool columnIsAutoIncrement(const std::string& columnname)const; 00059 void mapColumns(std::vector<std::string> &column_definitions); 00060 //temporary buffers; cleared after each metatable init .. 00061 std::map<std::string, std::string> _columns_map; 00062 std::vector<WSqlForeignKey> _foreign_keys; 00063 }; 00064 00065 }//namespace WSql 00066 00067 #endif // WSQLITEDRIVER_H