Changeset 1413:90ddaec5a31a
- Timestamp:
- 01/04/10 23:08:12 (2 years ago)
- Branch:
- default
- Location:
- sources
- Files:
-
- 3 deleted
- 20 edited
-
examples/db/test.cc (modified) (9 diffs)
-
examples/db_mysql/test.cc (modified) (9 diffs)
-
examples/db_postgresql/test.cc (modified) (5 diffs)
-
examples/db_sqlite/test.cc (modified) (5 diffs)
-
include/libdodo/data.h (modified) (2 diffs)
-
include/libdodo/dataBaseAccumulator.h (deleted)
-
include/libdodo/dataBaseConnector.h (modified) (4 diffs)
-
include/libdodo/dataBaseMysql.h (modified) (6 diffs)
-
include/libdodo/dataBaseMysqlEx.h (modified) (1 diff)
-
include/libdodo/dataBasePostgresql.h (modified) (6 diffs)
-
include/libdodo/dataBasePostgresqlEx.h (modified) (1 diff)
-
include/libdodo/dataBaseSqlConstructor.h (modified) (8 diffs)
-
include/libdodo/dataBaseSqlConstructorEx.h (deleted)
-
include/libdodo/dataBaseSqlite.h (modified) (5 diffs)
-
include/libdodo/dataBaseSqliteEx.h (modified) (1 diff)
-
include/libdodo/exceptionBasic.h (modified) (1 diff)
-
src/dataBaseAccumulator.cc (deleted)
-
src/dataBaseConnector.cc (modified) (5 diffs)
-
src/dataBaseMysql.cc (modified) (11 diffs)
-
src/dataBasePostgresql.cc (modified) (19 diffs)
-
src/dataBaseSqlConstructor.cc (modified) (11 diffs)
-
src/dataBaseSqlite.cc (modified) (27 diffs)
-
src/exceptionBasic.cc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sources/examples/db/test.cc
r1406 r1413 16 16 17 17 #ifndef DATABASE_WO_XEXEC 18 19 18 void 20 19 hook(xexec::__collected_data__ *odata, … … 23 22 void *udata) 24 23 { 25 accumulator::__collected_data__ *sql = (accumulator::__collected_data__ *)odata;24 sql::constructor::__collected_data__ *sql = (sql::constructor::__collected_data__ *)odata; 26 25 27 if (operation == data::base::connector::OPERATION_EXEC) { 28 cout << endl << endl << "request: " << dynamic_cast<sql::constructor *>(sql->executor)->construct() << endl << endl; 29 } 26 if (operation == data::base::connector::OPERATION_EXEC && sql->query) 27 cout << endl << endl << "request: " << sql->query->sql.data() << endl << endl; 30 28 } 31 32 29 #endif 33 30 … … 37 34 { 38 35 if (argc == 1) { 39 cout << "usage: " << argv[0] << " [postgresql |mysql|sqlite]" << endl;36 cout << "usage: " << argv[0] << " [postgresql [host]|mysql [host]|sqlite]" << endl; 40 37 41 38 return 1; 42 39 } 43 40 41 __connection_options__ *ci; 42 connector *db; 43 44 44 try { 45 __connection__ info;46 info.db = "test";47 45 if (strcasecmp(argv[1], "postgresql") == 0) { 48 info.host = "127.0.0.1"; 49 info.port = 5432; 50 info.user = "postgres"; 51 } else if (strcasecmp(argv[1], "mysql") == 0) { 52 info.path = "/var/run/mysqld/mysqld.sock"; 53 info.user = "root"; 54 info.password = "password"; 55 } else if (strcasecmp(argv[1], "sqlite") == 0) { 56 info.path = "test.lite"; 57 } 46 #ifdef POSTGRESQL_EXT 47 ci = new postgresql::__connection_options__("test", argc>2?argv[2]:"localhost", "postgres", "", 5432); 58 48 59 connector *db; 60 61 ///parse command line arguments to figure out what db to use 62 if (strcasecmp(argv[1], "postgresql") == 0) 63 #ifdef POSTGRESQL_EXT 64 db = new postgresql(info); 49 db = new postgresql(*ci); 65 50 #else 66 51 return 1; 67 52 #endif 53 } else if (strcasecmp(argv[1], "mysql") == 0) { 54 #ifdef MYSQL_EXT 55 ci = new mysql::__connection_options__("test", argc>2?argv[2]:"localhost", "root", "password", "", 3306); 68 56 69 else if (strcasecmp(argv[1], "mysql") == 0) 70 #ifdef MYSQL_EXT 71 db = new mysql(info); 57 db = new mysql(*ci); 72 58 #else 73 59 return 1; 74 60 #endif 61 } else if (strcasecmp(argv[1], "sqlite") == 0) { 62 #ifdef SQLITE3_EXT 63 ci = new sqlite::__connection_options__("test.lite"); 75 64 76 else if (strcasecmp(argv[1], "sqlite") == 0) 77 #ifdef SQLITE3_EXT 78 db = new sqlite(info); 65 db = new sqlite(*ci); 79 66 #else 80 67 return 1; 81 68 #endif 82 83 else 84 return 1; 69 } 85 70 86 71 #ifndef DATABASE_WO_XEXEC … … 88 73 #endif 89 74 90 ///define session charset75 ///define session charset 91 76 if (strcasecmp(argv[1], "postgresql") == 0) { 92 77 #ifdef POSTGRESQL_EXT 93 94 ((postgresql *)db)->setCharset("UTF-8"); 78 ((postgresql *)db)->setCharset("UTF-8"); 95 79 96 80 cout << "Encoding: " << ((postgresql *)db)->charset() << endl; 97 98 81 #endif 99 82 } else if (strcasecmp(argv[1], "mysql") == 0) { 100 83 #ifdef MYSQL_EXT 101 102 ((mysql *)db)->setCharset("UTF-8"); 84 ((mysql *)db)->setCharset("UTF-8"); 103 85 104 86 cout << "Encoding: " << ((mysql *)db)->charset() << endl; 105 106 87 #endif 107 88 } 108 89 109 90 try { 110 db->exec( "DROP TABLE test");91 db->exec(sql::query("DROP TABLE test")); 111 92 } catch (dodo::exception::basic &ex) { 112 93 cout << (dodoString)ex << endl << ex.file << endl << ex.message << endl << ex.line << endl << endl; … … 114 95 115 96 if (strcasecmp(argv[1], "postgresql") == 0) 116 db->exec( "CREATE TABLE test (t0 text NOT NULL, t1 text NOT NULL, id integer default NULL, i integer default NULL, b bytea)");97 db->exec(sql::query("CREATE TABLE test (t0 text NOT NULL, t1 text NOT NULL, id integer default NULL, i integer default NULL, b bytea)")); 117 98 else 118 db->exec( "CREATE TABLE test (t0 text NOT NULL, t1 text NOT NULL, id integer default NULL, i integer default NULL, b longblob)");99 db->exec(sql::query("CREATE TABLE test (t0 text NOT NULL, t1 text NOT NULL, id integer default NULL, i integer default NULL, b longblob)")); 119 100 120 101 try { … … 135 116 array["i"] = "1"; 136 117 137 dodoArray<dodoString> select;138 select.push_back("t0");139 select.push_back("t1");140 select.push_back("b");118 dodoArray<dodoString> fields; 119 fields.push_back("t0"); 120 fields.push_back("t1"); 121 fields.push_back("b"); 141 122 142 __tuples__ store;123 sql::rows rows; 143 124 144 125 for (int i = 0; i < 10; i++) { 145 db->select( "test", select, "id<20 or t1='def'");126 db->select(sql::condition("test", fields, "id<20 or t1='def'")); 146 127 db->exec(); 147 128 148 store = db->fetch();129 db->fetchedRows(rows); 149 130 150 db->insert( "test", array);131 db->insert(sql::rows(array), sql::condition("test")); 151 132 db->exec(); 152 133 153 134 array["i"] = "i+1"; 154 135 array["t1"] = "def"; 155 db->update( "test", array);136 db->update(sql::rows(array), sql::condition("test")); 156 137 db->exec(); 157 138 … … 160 141 } 161 142 162 db->select( "test", select, "t1='def'");143 db->select(sql::condition("test", fields, "t1='def'")); 163 144 db->exec(); 164 145 165 store = db->fetch();146 db->fetchedRows(rows); 166 147 167 cout << store.rows.size() << endl;148 cout << rows.values.size() << endl; 168 149 169 dodoArray<dodoStringArray>::iterator i( store.rows.begin()), j(store.rows.end());150 dodoArray<dodoStringArray>::iterator i(rows.values.begin()), j(rows.values.end()); 170 151 dodoStringArray::iterator m, n; 171 152 for (; i != j; i++) { … … 181 162 #endif 182 163 164 ///put binary data into data base 183 165 tools::filesystem::unlink("test.db"); 184 166 dodoString b = tools::filesystem::fileContents("test"); … … 190 172 array["t1"] = ""; 191 173 192 db->insert( "test", array);174 db->insert(sql::rows(array), sql::condition("test")); 193 175 db->exec(); 194 176 195 177 db->disconnect(); 196 db->connect( info);178 db->connect(*ci); 197 179 198 db->select( "test", select, "t0='blob'");180 db->select(sql::condition("test", fields, "t0='blob'")); 199 181 db->exec(); 200 182 201 store = db->fetch();183 db->fetchedRows(rows); 202 184 203 ///put fetched binary data to file204 if ( store.fields.size() == 3 && store.rows.size() > 0)205 tools::filesystem::writeToFile("test.db", (* store.rows.begin())[2]);185 ///put fetched binary data to file 186 if (rows.fields.size() == 3 && rows.values.size() > 0) 187 tools::filesystem::writeToFile("test.db", (*rows.values.begin())[2]); 206 188 207 189 delete db; 190 delete ci; 208 191 } catch (dodo::exception::basic &ex) { 209 192 cout << (dodoString)ex << endl << ex.file << endl << ex.message << endl << ex.line << endl << endl; -
sources/examples/db_mysql/test.cc
r1406 r1413 23 23 void *udata) 24 24 { 25 accumulator::__collected_data__ *sql = (accumulator::__collected_data__ *)odata;25 sql::constructor::__collected_data__ *sql = (sql::constructor::__collected_data__ *)odata; 26 26 27 if (operation == data::base::connector::OPERATION_EXEC) { 28 cout << endl << endl << "request: " << dynamic_cast<sql::constructor *>(sql->executor)->construct() << endl << endl; 29 } 27 if (operation == data::base::connector::OPERATION_EXEC && sql->query) 28 cout << endl << endl << "request: " << sql->query->sql.data() << endl << endl; 30 29 } 31 30 #endif … … 38 37 long now = tools::time::now(); 39 38 39 mysql::__connection_options__ ci("test", argc>1?argv[1]:"localhost", "root", "password", "", 3306); 40 40 41 #ifdef MYSQL_EXT 41 42 try { 42 mysql db( __connection__("test", "localhost", "root", "password", "", 3306));43 mysql db(ci); 43 44 44 45 #ifndef DATABASE_WO_XEXEC … … 47 48 48 49 try { 49 db.exec( "DROP TABLE test0");50 db.exec(sql::query("DROP TABLE test0")); 50 51 } catch (...) { 51 52 } 52 53 try { 53 db.exec( "DROP TABLE test1");54 db.exec(sql::query("DROP TABLE test1")); 54 55 } catch (...) { 55 56 } 56 57 57 db.exec( "CREATE TABLE test0 (id int(11) NOT NULL auto_increment, i int(11), t0 text NOT NULL, t1 text NOT NULL, PRIMARY KEY (id))");58 db.exec( "CREATE TABLE test1 (id int(11) NOT NULL auto_increment, i int(11), t0 text NOT NULL, t1 text NOT NULL, PRIMARY KEY (id))");58 db.exec(sql::query("CREATE TABLE test0 (id int(11) NOT NULL auto_increment, i int(11), t0 text NOT NULL, t1 text NOT NULL, PRIMARY KEY (id))")); 59 db.exec(sql::query("CREATE TABLE test1 (id int(11) NOT NULL auto_increment, i int(11), t0 text NOT NULL, t1 text NOT NULL, PRIMARY KEY (id))")); 59 60 60 61 db.requestFieldsTypes("test0"); 61 62 db.requestFieldsTypes("test1"); 62 63 64 sql::rows rows; 63 65 dodoStringArray fields; 64 __tuples__ storage;65 66 66 db.select("test0"); 67 db.join("test1", JOIN_JOIN, "test0.t0 = test1.t0"); 68 db.limit(10); 67 db.select(sql::condition("test0").limit(10).join("test1", "test0.t0 = test1.t0")); 69 68 db.exec(); 70 69 71 storage = db.fetch();70 db.fetchedRows(rows); 72 71 73 dodoStringArray::iterator i = storage.fields.begin(), j = storage.fields.end();72 dodoStringArray::iterator i = rows.fields.begin(), j = rows.fields.end(); 74 73 for (; i != j; ++i) 75 74 cout << "[" << *i << "]\t"; … … 89 88 mapArray.push_back(array); 90 89 91 db.insert( "test0", mapArray);90 db.insert(sql::rows(mapArray), sql::condition("test0")); 92 91 db.exec(); 93 92 … … 95 94 96 95 db.disconnect(); 97 db.connect( __connection__("test", "localhost", "root", "password", "", 3306));96 db.connect(ci); 98 97 99 98 array["i"] = "100000"; 100 db.update( "test0", array);99 db.update(sql::rows(array), sql::condition("test0")); 101 100 db.exec(); 102 101 … … 105 104 fields.push_back("t1"); 106 105 107 db.insert( "test0", values, fields);106 db.insert(sql::rows(values, fields), sql::condition("test0")); 108 107 db.exec(); 109 108 … … 113 112 114 113 for (int o = 0; o < 100000; o++) { 115 db.insert( "test0", values, fields);114 db.insert(sql::rows(values, fields), sql::condition("test0")); 116 115 db.exec(); 117 116 } … … 121 120 #endif 122 121 123 dodoStringArray u; 122 dodoString u; 123 db.select(sql::condition("test0", "id>1").limit(10).offset(20)); 124 u = db.construct(); 125 u += " union all "; 126 db.select(sql::condition("test0", "id<100")); 127 u += db.construct(); 128 db.exec(sql::query(u)); 124 129 125 db.select("test0", dodoStringArray(), "id>1"); 126 db.limit(10); 127 db.offset(23); 128 129 dodoString subrequest = db.construct(); 130 u.push_back(subrequest); 131 u.push_back(subrequest); 132 db.subquery(u); 133 subrequest = db.construct(); 134 135 db.select("test0", dodoStringArray(), "id<100"); 136 137 u.clear(); 138 u.push_back(subrequest); 139 u.push_back(db.construct()); 140 db.subquery(u, SUBREQUEST_UNION_ALL); 141 142 db.order("id desc"); 143 db.limit(5); 130 db.select(sql::condition("test0").limit(10)); 144 131 db.exec(); 145 132 146 db.select("test0"); 147 db.limit(10); 148 db.exec(); 133 db.fetchedRows(rows); 149 134 150 storage = db.fetch(); 151 152 dodoArray<dodoStringArray>::iterator o(storage.rows.begin()), p(storage.rows.end()); 135 dodoArray<dodoStringArray>::iterator o(rows.values.begin()), p(rows.values.end()); 153 136 dodoStringArray::iterator m, n; 154 137 for (; o != p; o++) { … … 160 143 } 161 144 } catch (dodo::exception::basic &ex) { 162 cout << (dodoString)ex << "\t" << ex.line << "\t" << ex.file << endl ;145 cout << (dodoString)ex << "\t" << ex.line << "\t" << ex.file << endl << ex.backtrace(); 163 146 } 164 147 #else -
sources/examples/db_postgresql/test.cc
r1406 r1413 23 23 void *udata) 24 24 { 25 accumulator::__collected_data__ *sql = (accumulator::__collected_data__ *)odata;25 sql::constructor::__collected_data__ *sql = (sql::constructor::__collected_data__ *)odata; 26 26 27 if (operation == data::base::connector::OPERATION_EXEC) { 28 cout << endl << endl << "request: " << dynamic_cast<sql::constructor *>(sql->executor)->construct() << endl << endl; 29 } 27 if (operation == data::base::connector::OPERATION_EXEC && sql->query) 28 cout << endl << endl << "request: " << sql->query->sql.data() << endl << endl; 30 29 } 31 30 #endif … … 38 37 #ifdef POSTGRESQL_EXT 39 38 try { 40 __connection__ info; 41 info.db = "test"; 42 info.host = "localhost"; 43 info.port = 5432; 44 info.user = "postgres"; 39 postgresql::__connection_options__ ci("test", argc>1?argv[1]:"localhost", "postgres", "", 5432); 45 40 46 postgresql db( info);41 postgresql db(ci); 47 42 48 43 #ifndef DATABASE_WO_XEXEC … … 51 46 52 47 try { 53 db.exec( "DROP TABLE test");48 db.exec(sql::query("DROP TABLE test")); 54 49 } catch (...) { 55 50 } 56 51 57 db.exec( "CREATE TABLE test (t0 text NOT NULL, t1 text NOT NULL, id integer default NULL, i integer default NULL, b bytea)");52 db.exec(sql::query("CREATE TABLE test (t0 text NOT NULL, t1 text NOT NULL, id integer default NULL, i integer default NULL, b bytea)")); 58 53 59 __tuples__ store;54 sql::rows rows; 60 55 61 56 dodoStringMap array; … … 63 58 array["t1"] = "abc"; 64 59 65 dodoStringArray select;66 select.push_back("t0");67 select.push_back("t1");60 dodoStringArray fields; 61 fields.push_back("t0"); 62 fields.push_back("t1"); 68 63 69 64 for (int i = 0; i < 10; i++) { 70 db.select( "test", select, "id<20 or t1='abc'");65 db.select(sql::condition("test", fields, "id<20 or t1='abc'")); 71 66 db.exec(); 72 67 73 store = db.fetch();68 db.fetchedRows(rows); 74 69 75 db.insert( "test", array);70 db.insert(sql::rows(array), sql::condition("test")); 76 71 db.exec(); 77 72 78 73 array["t1"] = "def"; 79 db.update( "test", array);74 db.update(sql::rows(array), sql::condition("test")); 80 75 db.exec(); 81 76 … … 84 79 85 80 db.disconnect(); 86 db.connect( info);81 db.connect(ci); 87 82 88 db.select( "test", select, "t1='def'");83 db.select(sql::condition("test", fields, "t1='def'")); 89 84 db.exec(); 90 85 91 cout << db.fetch().rows.size() << endl;86 db.fetchedRows(rows); 92 87 93 store = db.fetch();88 cout << rows.values.size() << endl; 94 89 95 dodoArray<dodoStringArray>::iterator i( store.rows.begin()), j(store.rows.end());90 dodoArray<dodoStringArray>::iterator i(rows.values.begin()), j(rows.values.end()); 96 91 dodoStringArray::iterator m, n; 97 92 for (; i != j; i++) { -
sources/examples/db_sqlite/test.cc
r1406 r1413 23 23 void *udata) 24 24 { 25 accumulator::__collected_data__ *sql = (accumulator::__collected_data__ *)odata;25 sql::constructor::__collected_data__ *sql = (sql::constructor::__collected_data__ *)odata; 26 26 27 if (operation == data::base::connector::OPERATION_EXEC) { 28 cout << endl << endl << "request: " << dynamic_cast<sql::constructor *>(sql->executor)->construct() << endl << endl; 29 } 27 if (operation == data::base::connector::OPERATION_EXEC && sql->query) 28 cout << endl << endl << "request: " << sql->query->sql.data() << endl << endl; 30 29 } 31 30 #endif … … 40 39 tools::filesystem::unlink("test.lite", true); 41 40 42 __connection__ info; 43 info.path = "test.lite"; 41 sqlite::__connection_options__ ci("test.lite"); 44 42 45 sqlite db( info);43 sqlite db(ci); 46 44 47 45 #ifndef DATABASE_WO_XEXEC … … 50 48 51 49 try { 52 db.exec( "DROP TABLE test");50 db.exec(sql::query("DROP TABLE test")); 53 51 } catch (...) { 54 52 } 55 53 56 db.exec("CREATE TABLE test (t0 text NOT NULL, t1 text NOT NULL, id int default NULL, i int default NULL, b longblob)"); 54 db.exec(sql::query("CREATE TABLE test (t0 text NOT NULL, t1 text NOT NULL, id int default NULL, i int default NULL, b longblob)")); 55 56 sql::rows rows; 57 57 58 58 dodoStringMap array; … … 60 60 array["t1"] = "abc"; 61 61 62 dodoArray<dodoString> select;63 select.push_back("t0");64 select.push_back("t1");62 dodoArray<dodoString> fields; 63 fields.push_back("t0"); 64 fields.push_back("t1"); 65 65 66 66 for (int i = 0; i < 10; i++) { 67 db.select( "test", select, "`id`<20 or `t1`='abc'");67 db.select(sql::condition("test", fields, "id<20 or t1='abc'")); 68 68 db.exec(); 69 69 70 70 cout << "Selected: \n"; 71 cout << "Rows: " << db.requestedRows() << endl; 72 cout << "Fields: " << db.requestedFields() << endl; 71 cout << "Rows: " << db.fetchedRows() << endl; 73 72 74 db.insert( "test", array);73 db.insert(sql::rows(array), sql::condition("test")); 75 74 db.exec(); 76 75 77 76 array["t1"] = "def"; 78 db.update( "test", array);77 db.update(sql::rows(array), sql::condition("test")); 79 78 db.exec(); 80 79 … … 85 84 86 85 db.disconnect(); 87 db.connect( info);86 db.connect(ci); 88 87 89 db.select( "test", select, "`id`<20 or `t1`='def'");88 db.select(sql::condition("test", fields, "`id`<20 or `t1`='def'")); 90 89 db.exec(); 91 90 92 cout << db.fetch().rows.size() << endl;91 db.fetchedRows(rows); 93 92 94 __tuples__ store = db.fetch();93 cout << rows.values.size() << endl; 95 94 96 dodoArray<dodoStringArray>::iterator i( store.rows.begin()), j(store.rows.end());95 dodoArray<dodoStringArray>::iterator i(rows.values.begin()), j(rows.values.end()); 97 96 98 97 dodoStringArray::iterator m, n; -
sources/include/libdodo/data.h
r1406 r1413 31 31 #define _DATA_H_ 1 32 32 33 #include <libdodo/dataBaseAccumulator.h>34 33 #include <libdodo/dataBaseConnector.h> 35 34 #include <libdodo/dataBaseMysql.h> … … 38 37 #include <libdodo/dataBasePostgresqlEx.h> 39 38 #include <libdodo/dataBaseSqlConstructor.h> 40 #include <libdodo/dataBaseSqlConstructorEx.h>41 39 #include <libdodo/dataBaseSqlite.h> 42 40 #include <libdodo/dataBaseSqliteEx.h> -
sources/include/libdodo/dataBaseConnector.h
r1406 r1413 40 40 namespace base { 41 41 /** 42 * @enum joinEnum defines join types 42 * @struct __connection_options__ 43 * @brief defines connection options for the server 43 44 */ 44 enum joinEnum { 45 JOIN_JOIN, 46 JOIN_LEFTOUTER, 47 JOIN_RIGHTOUTER, 48 JOIN_FULLOUTER, 49 JOIN_INNER, 50 JOIN_CROSS, 45 struct __connection_options__ { 51 46 52 JOIN_ENUMSIZE 47 /** 48 * destructor 49 */ 50 virtual ~__connection_options__() = 0; 53 51 }; 54 52 55 53 /** 56 * @enum subrequestEnum defines type of sub request 54 * @class condition 55 * @brief defines condition for data base operations 57 56 */ 58 enum subrequestEnum { 59 SUBREQUEST_UNION = 1, 60 SUBREQUEST_UNION_ALL, 61 SUBREQUEST_MINUS, 62 SUBREQUEST_INTERSECT, 57 class condition { 58 public: 63 59 64 SUBREQUEST_ENUMSIZE 60 /** 61 * destructor 62 */ 63 virtual ~condition() = 0; 65 64 }; 66 65 67 66 /** 68 * @ struct __tuples__69 * @brief defines fetched data from db67 * @class row 68 * @brief defines rows of data base 70 69 */ 71 struct __tuples__ { 72 /** 73 * constructor 74 * @param rows defines rows of data 75 * @param fields defines names of fields 76 */ 77 __tuples__(dodoArray<dodoStringArray> rows, 78 dodoStringArray fields); 70 class rows { 71 public: 79 72 80 73 /** 81 * constructor74 * destructor 82 75 */ 83 __tuples__(); 84 85 dodoArray<dodoStringArray> rows; ///< rows of data 86 dodoStringArray fields; ///< names of fields 76 virtual ~rows() = 0; 87 77 }; 88 78 89 79 /** 90 * @ struct __connection__91 * @brief defines connection options for the server80 * @class query 81 * @brief defines data base query 92 82 */ 93 struct __connection__ { 94 /** 95 * constructor 96 */ 97 __connection__(); 83 class query { 84 public: 98 85 99 86 /** 100 * constructor 101 * @param db defines name of db 102 * @param host defines host 103 * @param user defines user 104 * @param password defines password 105 * @param path defines path to db or unix socket 106 * @param port defines port 87 * destructor 107 88 */ 108 __connection__(const dodoString &db, 109 const dodoString &host, 110 const dodoString &user, 111 const dodoString &password, 112 const dodoString &path = __dodostring__, 113 int port = 0); 114 115 dodoString db; ///< database name 116 dodoString host; ///< hostname 117 dodoString user; ///< username 118 dodoString password; ///< password 119 dodoString path; ///< path to db or unix socket 120 unsigned int port; ///< port 89 virtual ~query() = 0; 121 90 }; 122 91 123 92 /** 124 93 * @class connector 125 * @brief implements an interface to db through sql and database independent interfaces94 * @brief implements data base interface 126 95 */ 127 96 class connector … … 137 106 enum operationEnum { 138 107 OPERATION_CONNECT, 108 OPERATION_DISCONNECT, 109 OPERATION_SELECT, 110 OPERATION_INSERT, 111 OPERATION_UPDATE, 112 OPERATION_REMOVE, 139 113 OPERATION_EXEC, 140 OPERATION_DISCONNECT, 141 OPERATION_FETCHROWS, 142 OPERATION_FETCHFIELDS, 114 OPERATION_FETCHEDROWS, 143 115 }; 144 116 … … 155 127 /** 156 128 * connect to the database 157 * @param dbInfo defines connection information129 * @param info defines information for connection to db 158 130 */ 159 virtual void connect(const __connection_ _ &dbInfo) = 0;131 virtual void connect(const __connection_options__ &info) = 0; 160 132 161 133 /** … … 165 137 166 138 /** 167 * call stored function 168 * @param name defines function name 169 * @param arguments defines arguments 170 * @param as defines name of the result row 139 * @param condition defines row selection condition 171 140 */ 172 virtual void function(const dodoString &name, 173 const dodoStringArray &arguments, 174 const dodoString &as = __dodostring__) = 0; 141 virtual void select(const condition &condition) = 0; 175 142 176 143 /** 177 * call stored procedure 178 * @param name is procedure name 179 * @param arguments is array of arguments 144 * @param rows defines rows for insertion into data base 145 * @param condition defines row insertion condition 180 146 */ 181 virtual void procedure(const dodoString &name,182 const dodoStringArray &arguments) = 0;147 virtual void insert(const rows &rows, 148 const condition &condition) = 0; 183 149 184 150 /** 185 * @param table defines table name 186 * @param fields defines names of fields 187 * @param where defines `where` statement 188 * @note if param table is empty 'from `table`' is not used 189 * if param fields is empty all fields are fetched 151 * @param rows defines values of row for update 152 * @param condition defines row update condition 190 153 */ 191 virtual void select(const dodoString &table, 192 const dodoStringArray &fields = __dodostringarray__, 193 const dodoString &where = __dodostring__) = 0; 154 virtual void update(const rows &rows, 155 const condition &condition) = 0; 194 156 195 157 /** 196 * @param table defines table name 197 * @param fields defines hash of field=>value 158 * @param condition defines row remove condition 198 159 */ 199 virtual void insert(const dodoString &table, 200 const dodoStringMap &fields) = 0; 160 virtual void remove(const condition &condition) = 0; 201 161 202 162 /** 203 * @param table defines table name 204 * @param fields defines set of hashes of field=>value 163 * @param rows defines rows got from the request 205 164 */ 206 virtual void insert(const dodoString &table, 207 const dodoArray<dodoStringMap> &fields) = 0; 165 virtual void fetchedRows(rows &rows) const = 0; 208 166 209 167 /** 210 * @param table defines table name 211 * @param values defines values 212 * @param fields defines names of fields 168 * execute request for data base 169 * @param query contains query for data base 213 170 */ 214 virtual void insert(const dodoString &table, 215 const dodoStringArray &values, 216 const dodoStringArray &fields = __dodostringarray__) = 0; 171 virtual void exec(const query &query) = 0; 217 172 218 173 /** 219 * @param table defines table name 220 * @param values defines values 221 * @param fields defines names of fields 174 * execute constructed request for data base 222 175 */ 223 virtual void insert(const dodoString &table, 224 const dodoArray<dodoStringArray> &values, 225 const dodoStringArray &fields = __dodostringarray__) = 0; 226 227 /** 228 * @param table defines table name 229 * @param fields defines hash of field=>value 230 * @param where defines `where` statement 231 */ 232 virtual void update(const dodoString &table, 233 const dodoStringMap &fields, 234 const dodoString &where = __dodostring__) = 0; 235 236 /** 237 * @param table defines table name 238 * @param values defines values 239 * @param fields defines names of fields 240 * @param where defines `where` statement 241 */ 242 virtual void update(const dodoString &table, 243 const dodoStringArray &values, 244 const dodoStringArray &fields, 245 const dodoString &where = __dodostring__) = 0; 246 247 /** 248 * @param table defines table name 249 * @param where defines `where` statement 250 */ 251 virtual void del(const dodoString &table, 252 const dodoString &where = __dodostring__) = 0; 253 254 /** 255 * store query, made from subquery with requested method 256 * @param subqueries defines subqueries 257 * @param type defines type of combining subqueries, @see data::base::subrequestEnum 258 */ 259 virtual void subquery(const dodoStringArray &subqueries, 260 int type = SUBREQUEST_UNION) = 0; 261 262 /** 263 * set `limit` property 264 * @param number defines `limit` value 265 */ 266 virtual void limit(unsigned int number) = 0; 267 268 /** 269 * set `offset` property 270 * @param number defines `offset` value 271 */ 272 virtual void offset(unsigned int number) = 0; 273 274 /** 275 * set `order` property 276 * @param order defines `order` value 277 */ 278 virtual void order(const dodoString &order) = 0; 279 280 /** 281 * set `group` property 282 * @param group defines `group` value 283 */ 284 virtual void group(const dodoString &group) = 0; 285 286 /** 287 * set having property 288 * @param having defines having value 289 */ 290 virtual void having(const dodoString &having) = 0; 291 292 /** 293 * append join statement 294 * @param table defines table to join 295 * @param condition defines condition for joining 296 * @param type defines join type, @see data::base::joinEnum 297 */ 298 virtual void join(const dodoString &table, 299 int type, 300 const dodoString &condition) = 0; 301 302 /** 303 * @return amount of affected rows 304 */ 305 virtual unsigned int affectedRows() const = 0; 306 307 /** 308 * @return amount of rows got from the request 309 */ 310 virtual unsigned int requestedRows() const = 0; 311 312 /** 313 * @return amount of fields got from the request 314 */ 315 virtual unsigned int requestedFields() const = 0; 316 317 /** 318 * @return rows got from the request 319 */ 320 virtual dodoArray<dodoStringArray> fetchRows() const = 0; 321 322 /** 323 * @return fields got from the request 324 */ 325 virtual dodoStringArray fetchFields() const = 0; 326 327 /** 328 * @return result got from the request 329 */ 330 virtual __tuples__ fetch() const = 0; 331 332 /** 333 * @return set of hashes of field=>value 334 */ 335 virtual dodoStringMapArray fetchFieldsToRows() const = 0; 336 337 /** 338 * execute collected request 339 * @param query contains query for DB 340 * @param result defines type of result(true for quering data, false for data operation) 341 * @note if query is empty request will be constructed from the data that was defined using object's methods 342 */ 343 virtual void exec(const dodoString &query = __dodostring__, 344 bool result = false) = 0; 176 virtual void exec() = 0; 345 177 346 178 bool reconnect; ///< if true tries to reconect in case when `exec` failed with connection error[true by default] -
sources/include/libdodo/dataBaseMysql.h
r1406 r1413 50 50 51 51 /** 52 * @struct __ssl_options__ 53 * @brief defines SSL mySQL options 54 */ 55 struct __ssl_options__ { 56 dodoString key; ///< pathname to the key file 57 dodoString cert; ///< pathname to the certificate file 58 dodoString ca; ///< pathname to the certificate authority file 59 dodoString capath; ///< pathname to a directory that contains trusted SSL CA certificates in pem format 60 dodoString cipher; ///< allowed SSL ciphers 52 * @struct __connection_options__ 53 * @brief defines connection options for the server 54 */ 55 struct __connection_options__ : public data::base::__connection_options__ { 56 /** 57 * @enum typeEnum defines connection type 58 */ 59 enum typeEnum { 60 TYPE_COMPRESS = 2, 61 TYPE_MULTI_STATEMENTS = 4, 62 }; 63 64 /** 65 * @struct __ssl_options__ 66 * @brief defines SSL mySQL options 67 */ 68 struct __ssl_options__ { 69 dodoString key; ///< pathname to the key file 70 dodoString cert; ///< pathname to the certificate file 71 dodoString ca; ///< pathname to the certificate authority file 72 dodoString capath; ///< pathname to a directory that contains trusted SSL CA certificates in pem format 73 dodoString cipher; ///< allowed SSL ciphers 74 }; 75 76 /** 77 * constructor 78 */ 79 __connection_options__(); 80 81 /** 82 * constructor 83 * @param db defines name of db 84 * @param host defines host 85 * @param user defines user 86 * @param password defines password 87 * @param path defines path to db or unix socket 88 * @param port defines port 89 * @param type defines type of connection 90 */ 91 __connection_options__(const dodoString &db, 92 const dodoString &host, 93 const dodoString &user, 94 const dodoString &password, 95 const dodoString &path = __dodostring__, 96 unsigned int port = 0, 97 unsigned long type = TYPE_MULTI_STATEMENTS); 98 99 unsigned long type; ///< type of connection [@see __connection_options__::typeEnum] 100 101 dodoString db; ///< database name 102 dodoString host; ///< hostname 103 dodoString user; ///< username 104 dodoString password; ///< password 105 dodoString path; ///< path to db or unix socket 106 unsigned int port; ///< port 107 __ssl_options__ ssl; ///< SSL options 61 108 }; 62 109 … … 78 125 /** 79 126 * constructor 80 * @param dbInfo defines information for connection to db81 */ 82 mysql(const __connection__ &dbInfo);127 * @param info defines information for connection to db 128 */ 129 mysql(const data::base::__connection_options__ &info); 83 130 84 131 /** … … 87 134 virtual ~mysql(); 88 135 89 /*90 * set connection settings91 * @param type defines type of connection, @see mySQL documentation92 * @param options defines options of ssl connection93 * @note type can be:94 * CLIENT_COMPRESS Use compression protocol95 * CLIENT_MULTI_STATEMENTS Tell the server that the client may send multiple statements in a single string (separated by ?;?). If this flag is not set, multiple-statement execution is disabled. New in 4.1.96 */97 void setConnectionSettings(unsigned long type,98 const __ssl_options__ &options = __ssl_options__());99 100 136 /** 101 137 * connect to the database 102 * @param dbInfo defines information for connection to db103 */ 104 virtual void connect(const __connection__ &dbInfo);138 * @param info defines information for connection to db 139 */ 140 virtual void connect(const data::base::__connection_options__ &info); 105 141 106 142 /** … … 116 152 117 153 /** 154 * @param rows defines rows got from the request 155 */ 156 virtual void fetchedRows(data::base::rows &rows) const; 157 158 /** 118 159 * @return amount of affected rows from the evaluated request 119 160 */ … … 123 164 * @return amount of received rows from the evaluated request 124 165 */ 125 virtual unsigned int requestedRows() const; 126 127 /** 128 * @return amount of received fields from the evaluated request 129 */ 130 virtual unsigned int requestedFields() const; 131 132 /** 133 * @return received rows from the evaluated request 134 */ 135 virtual dodoArray<dodoStringArray> fetchRows() const; 136 137 /** 138 * @return received fields from the evaluated request 139 */ 140 virtual dodoStringArray fetchFields() const; 141 142 /** 143 * @return structure received rows and fields from the evaluated request 144 */ 145 virtual __tuples__ fetch() const; 146 147 /** 148 * @return received rows and fields from the evaluated request using hash `key`=>`value` 149 */ 150 virtual dodoStringMapArray fetchFieldsToRows() const; 151 152 /** 153 * execute request 154 * @param query defines query; you may define it if you don't use db methods like select, update 155 * @param result defines type of result; if true query return the result 156 */ 157 virtual void exec(const dodoString &query = __dodostring__, 158 bool result = false); 166 virtual unsigned int fetchedRows() const; 167 168 /** 169 * execute request for data base 170 * @param query contains query for data base 171 */ 172 virtual void exec(const data::base::query &query); 173 174 /** 175 * execute collected request for data base 176 */ 177 virtual void exec(); 159 178 160 179 /** … … 177 196 private: 178 197 179 bool empty; ///< true id mysqlRes is empty180 181 198 __mysql__ *handle; ///< DB handle 182 199 183 unsigned long type; ///< connection type200 __connection_options__ info; ///< DB connection information 184 201 }; 185 202 }; -
sources/include/libdodo/dataBaseMysqlEx.h
r1406 r1413 57 57 MYSQLEX_EXEC, 58 58 MYSQLEX_MYSQL, 59 MYSQLEX_GETFIELDSTYPES, 59 MYSQLEX_REQUESTFIELDSTYPES, 60 MYSQLEX_FETCHEDROWS, 61 MYSQLEX_AFFECTEDROWS, 62 MYSQLEX_SETCONNECTIONTIMEOUT, 63 MYSQLEX_CHARSET, 64 MYSQLEX_SETCHARSET, 60 65 }; 61 66 }; -
sources/include/libdodo/dataBasePostgresql.h
r1406 r1413 47 47 */ 48 48 class postgresql : public sql::constructor { 49 public: 50 51 /** 52 * @struct __connection_options__ 53 * @brief defines connection options for the server 54 */ 55 struct __connection_options__ : public data::base::__connection_options__ { 56 /** 57 * constructor 58 */ 59 __connection_options__(); 60 61 /** 62 * constructor 63 * @param db defines name of db 64 * @param host defines host 65 * @param user defines user 66 * @param password defines password 67 * @param path defines path to db or unix socket 68 * @param port defines port 69 */ 70 __connection_options__(const dodoString &db, 71 const dodoString &host, 72 const dodoString &user, 73 const dodoString &password, 74 unsigned int port = 0); 75 76 dodoString db; ///< database name 77 dodoString host; ///< hostname 78 dodoString user; ///< username 79 dodoString password; ///< password 80 unsigned int port; ///< port 81 }; 82 49 83 private: 50 84 … … 64 98 /** 65 99 * constructor 66 * @param dbInfo defines information for connection to db67 */ 68 postgresql(const __connection__ &dbInfo);100 * @param info defines information for connection to db 101 */ 102 postgresql(const data::base::__connection_options__ &info); 69 103 70 104 /** … … 75 109 /** 76 110 * connect to the database 77 * @param dbInfo defines information for connection to db78 */ 79 virtual void connect(const __connection__ &dbInfo);111 * @param info defines information for connection to db 112 */ 113 virtual void connect(const data::base::__connection_options__ &info); 80 114 81 115 /** … … 98 132 * @return amount of received rows from the evaluated request 99 133 */ 100 virtual unsigned int requestedRows() const; 101 102 /** 103 * @return amount of received fields from the evaluated request 104 */ 105 virtual unsigned int requestedFields() const; 106 107 /** 108 * @return received rows from the evaluated request 109 */ 110 virtual dodoArray<dodoStringArray> fetchRows() const; 111 112 /** 113 * @return received fields from the evaluated request 114 */ 115 virtual dodoStringArray fetchFields() const; 116 117 /** 118 * @return structure received rows and fields from the evaluated request 119 */ 120 virtual __tuples__ fetch() const; 121 122 /** 123 * @return received rows and fields from the evaluated request using hash `key`=>`value` 124 */ 125 virtual dodoStringMapArray fetchFieldsToRows() const; 126 127 /** 128 * execute request 129 * @param query defines query; you may define it if you don't use db methods like select, update 130 * @param result defines type of result; if true query return the result 131 */ 132 virtual void exec(const dodoString &query = __dodostring__, 133 bool result = false); 134 virtual unsigned int fetchedRows() const; 135 136 /** 137 * @param rows defines rows got from the request 138 */ 139 virtual void fetchedRows(data::base::rows &rows) const; 140 141 /** 142 * execute request for data base 143 * @param query contains query for data base 144 */ 145 virtual void exec(const data::base::query &query); 146 147 /** 148 * execute collected request for data base 149 */ 150 virtual void exec(); 134 151 135 152 /** … … 144 161 dodoString charset() const; 145 162 163 /** 164 * @param rows defines rows for insertion into data base 165 * @param condition defines row insertion condition 166 */ 167 virtual void insert(const data::base::rows &rows, 168 const data::base::condition &condition); 169 170 /** 171 * @param rows defines values of row for update 172 * @param condition defines row update condition 173 */ 174 virtual void update(const data::base::rows &rows, 175 const data::base::condition &condition); 176 146 177 protected: 147 178 148 179 /** 149 * construct `insert`statement150 */ 151 virtual void insertCollect();152 153 /** 154 * construct `update`statement155 */ 156 virtual void updateCollect();180 * @return insert SQL statement 181 */ 182 virtual dodoString insert(); 183 184 /** 185 * @return update SQL statement 186 */ 187 virtual dodoString update(); 157 188 158 189 #ifdef POSTGRESQL_NO_ENCODINGTOCHAR … … 223 254 private: 224 255 225 bool empty; ///< true id pgResult is empty226 227 256 __postgresql__ *handle; ///< DB handle 257 258 __connection_options__ info; ///< DB connection information 228 259 }; 229 260 }; -
sources/include/libdodo/dataBasePostgresqlEx.h
r1406 r1413 58 58 POSTGRESQLEX_POSTGRESQL, 59 59 POSTGRESQLEX_SETCHARSET, 60 POSTGRESQLEX_GETFIELDSTYPES, 60 POSTGRESQLEX_CHARSET, 61 POSTGRESQLEX_REQUESTFIELDSTYPES, 62 POSTGRESQLEX_FETCHEDROWS, 63 POSTGRESQLEX_AFFECTEDROWS, 61 64 }; 62 65 }; -
sources/include/libdodo/dataBaseSqlConstructor.h
r1406 r1413 34 34 35 35 #include <libdodo/types.h> 36 #include <libdodo/dataBase Accumulator.h>36 #include <libdodo/dataBaseConnector.h> 37 37 38 38 namespace dodo { … … 40 40 namespace base { 41 41 namespace sql { 42 /** 43 * @class condition 44 * @brief defines condition for data base operations 45 */ 46 class condition : public data::base::condition { 47 public: 48 49 /* 50 * @enum orderDirectionEnum defines order condition direction 51 */ 52 enum orderDirectionEnum { 53 ORDER_DIRECTION_ASC, 54 ORDER_DIRECTION_DESC, 55 }; 56 57 /** 58 * constructor 59 */ 60 condition(); 61 62 /** 63 * constructor 64 * @param table defines query table 65 * @param statement defines query condition 66 */ 67 condition(const dodoString &table, 68 const dodoString &statement = __dodostring__); 69 70 /** 71 * constructor 72 * @param table defines query table 73 * @param fields defines fields in table that correspond to data in rows 74 * @param statement defines query condition 75 */ 76 condition(const dodoString &table, 77 const dodoStringArray &fields, 78 const dodoString &statement = __dodostring__); 79 80 /** 81 * destructor 82 */ 83 virtual ~condition(); 84 85 /** 86 * @return condition 87 * @param limit defines limit condition 88 */ 89 const condition &limit(long limit) const; 90 91 /** 92 * @return condition 93 * @param offset defines offset condition 94 */ 95 const condition &offset(long offset) const; 96 97 /** 98 * @return condition 99 * @param field defines field name for order condition 100 * @param direction defines direction for order condition[@see enum orderDirectionEnum] 101 */ 102 const condition &order(const dodoString &field, 103 short direction = ORDER_DIRECTION_ASC) const; 104 105 /** 106 * @enum joinEnum defines JOIN types 107 */ 108 enum joinEnum { 109 JOIN_INNER, 110 JOIN_OUTER, 111 JOIN_LEFT, 112 JOIN_RIGHT, 113 }; 114 115 /** 116 * @return condition 117 * @param table defines table to join with 118 * @param condition defines JOIN condition 119 * @param type defines JOIN type 120 */ 121 const condition &join(const dodoString &table, 122 const dodoString &condition, 123 short type = JOIN_INNER) const; 124 125 /** 126 * @struct __join__ 127 * @brief defines JOIN statement 128 */ 129 struct __join__ { 130 short type; ///< JOIN type [@see condition::joinEnum] 131 dodoString table; ///< table to join with 132 dodoString condition; ///< JOIN condition 133 }; 134 135 mutable dodoArray<__join__> _join; 136 mutable dodoString _orderby; ///< order condition 137 mutable long _limit; ///< limit condition 138 mutable long _offset; ///< offset condition 139 dodoString _table; ///< table in data base 140 dodoString _statement; ///< SQL request condition 141 dodoStringArray _fields; ///< names of fiels 142 }; 143 144 /** 145 * @class row 146 * @brief defines rows of data base 147 */ 148 class rows : public data::base::rows { 149 public: 150 151 /** 152 * constructor 153 */ 154 rows(); 155 156 /** 157 * constructor 158 * @param values defines data in rows 159 * @param fields defines fields in table that correspond to data in rows 160 */ 161 rows(const dodoArray<dodoStringArray> &values, 162 const dodoStringArray &fields = __dodostringarray__); 163 164 /** 165 * constructor 166 * @param values defines data in rows 167 * @param fields defines fields in table that correspond to data in rows 168 */ 169 rows(const dodoStringArray &values, 170 const dodoStringArray &fields = __dodostringarray__); 171 172 /** 173 * constructor 174 * @param map defines array of mapping of fields to data in row 175 */ 176 rows(const dodoArray<dodoStringMap> &map); 177 178 /** 179 * constructor 180 * @param map defines mapping of fields to data in row 181 */ 182 rows(const dodoStringMap &map); 183 184 /** 185 * destructor 186 */ 187 virtual ~rows(); 188 189 dodoStringArray fields; ///< names of fiels 190 dodoArray<dodoStringArray> values; ///< data in rows 191 }; 192 193 /** 194 * @class query 195 * @brief defines data base query 196 */ 197 class query: public data::base::query { 198 public: 199 200 /** 201 * constructor 202 */ 203 query(); 204 205 /** 206 * constructor 207 * @param sql defines data base request in SQL form 208 */ 209 query(const dodoString &sql); 210 211 /** 212 * destructor 213 */ 214 virtual ~query(); 215 216 dodoString sql; 217 }; 218 42 219 /** 43 220 * @enum fieldEnum defines field type … … 55 232 * If you want to prevent data framing define preventFraming sqlConstructor class propertie as true but remember 56 233 */ 57 class constructor : public accumulator {234 class constructor : public connector { 58 235 public: 59 236 237 /** 238 * @enum requestEnum defines type of request 239 */ 240 enum requestEnum { 241 REQUEST_NONE, 242 REQUEST_SELECT, 243 REQUEST_INSERT, 244 REQUEST_UPDATE, 245 REQUEST_REMOVE, 246 }; 247 248 /** 249 * @class __collected_data__ 250 * @brief defines data that could be retrieved from the db object 251 */ 252 class __collected_data__ 253 #ifndef DATABASE_WO_XEXEC 254 : public xexec::__collected_data__ 255 #endif 256 { 257 public: 258 259 #ifndef DATABASE_WO_XEXEC 260 /** 261 * constructor 262 * @param executor defines class that executed hook 263 * @param execObject defines type of object that executed a hook, @see xexec::objectEnum 264 */ 265 __collected_data__(xexec *executor, 266 short execObject); 267 #else 268 /** 269 * constructor 270 */ 271 __collected_data__(); 272 #endif 273 /** 274 * clear collected data 275 */ 276 void clear(); 277 278 int type; ///< type of request @see constructor::requestEnum 279 280 sql::condition condition; ///< request condition 281 sql::rows rows; ///< request data 282 283 const sql::query *query; ///< ready for execution query 284 }; 285 60 286 /* 61 287 * constructor … … 67 293 */ 68 294 virtual ~constructor(); 295 296 /** 297 * @param fields defines fields to select 298 * @param condition defines row selection condition 299 * @note if param fields is empty all fields are fetched 300 */ 301 virtual void select(const data::base::condition &condition); 302 303 /** 304 * @param rows defines rows for insertion into data base 305 * @param condition defines row insertion condition 306 */ 307 virtual void insert(const data::base::rows &rows, 308 const data::base::condition &condition); 309 310 /** 311 * @param rows defines values of row for update 312 * @param condition defines row update condition 313 */ 314 virtual void update(const data::base::rows &rows, 315 const data::base::condition &condition); 316 317 /** 318 * @param condition defines row remove condition 319 */ 320 virtual void remove(const data::base::condition &condition); 69 321 70 322 /** … … 100 352 dodoMap<dodoString, dodoMap<dodoString, short, dodoMapICaseStringCompare>, dodoMapICaseStringCompare> fieldTypes; ///< hash of 'db:table' => 'field => 'type'' 101 353 102 dodoString request; ///< SQL statement 103 104 /** 105 * construct `SELECT function` statement 106 */ 107 virtual void functionCollect(); 108 109 /** 110 * construct `select procedure` statement 111 */ 112 virtual void procedureCollect(); 113 114 /** 115 * construct `select` statement 116 */ 117 virtual void selectCollect(); 118 119 /** 120 * construct `join` statement 121 */ 122 virtual void joinCollect(); 123 124 /** 125 * construct `insert` statement 126 */ 127 virtual void insertCollect(); 128 129 /** 130 * construct `update` statement 131 */ 132 virtual void updateCollect(); 133 134 /** 135 * construct `delete` statement 136 */ 137 virtual void delCollect(); 138 139 /** 140 * construct `union`, `minus`, `intersect` statements 141 */ 142 virtual void subCollect(); 143 144 /** 145 * add additional statements for query 146 * @param qTypeToCheck defines type of additional info to check 147 * @param collectedString defines string that defines additional statement 148 */ 149 virtual void additionalCollect(unsigned int qTypeToCheck, 150 const dodoString &collectedString); 354 /** 355 * @return select SQL statement 356 */ 357 virtual dodoString select(); 358 359 /** 360 * @return insert SQL statement 361 */ 362 virtual dodoString insert(); 363 364 /** 365 * @return update SQL statement 366 */ 367 virtual dodoString update(); 368 369 /** 370 * @return delete SQL statement 371 */ 372 virtual dodoString remove(); 151 373 152 374 /** … … 174 396 STATEMENT_RIGHTBRACKET, 175 397 STATEMENT_SELECT, 176 STATEMENT_CALL,177 398 STATEMENT_FROM, 399 STATEMENT_STAR, 178 400 STATEMENT_COLON, 179 401 STATEMENT_APOSTROPHECOMA, … … 186 408 STATEMENT_SET, 187 409 STATEMENT_DELETE, 410 STATEMENT_WHERE, 411 STATEMENT_LIMIT, 412 STATEMENT_OFFSET, 413 STATEMENT_ORDERBY, 414 STATEMENT_JOININNER, 415 STATEMENT_JOINOUTER, 416 STATEMENT_JOINLEFT, 417 STATEMENT_JOINRIGHT, 418 STATEMENT_ON, 188 419 STATEMENT_NULL, 189 420 … … 191 422 }; 192 423 193 static const dodoString statements[STATEMENT_ENUMSIZE]; ///< constructor statements 194 195 static const dodoString additionalRequestStatements[ADDITIONAL_REQUEST_ENUMSIZE]; ///< additional statements(`where`, `limit`, ...) 196 197 static const dodoString subrequestStatements[SUBREQUEST_ENUMSIZE]; ///< statements for complex queries(`union`, ...) 198 199 static const dodoString joinStatements[JOIN_ENUMSIZE]; ///< statements for `join` queries 424 static const dodoString statements[STATEMENT_ENUMSIZE]; ///< constructor statements 425 426 bool result; ///< if true try to get result from the request 427 428 __collected_data__ collectedData; ///< data collected 200 429 }; 201 430 }; -
sources/include/libdodo/dataBaseSqlite.h
r1406 r1413 47 47 */ 48 48 class sqlite : public sql::constructor { 49 public: 50 51 /** 52 * @struct __connection_options__ 53 * @brief defines connection options for the server 54 */ 55 struct __connection_options__ : public data::base::__connection_options__ { 56 /** 57 * constructor 58 */ 59 __connection_options__(); 60 61 /** 62 * constructor 63 * @param path defines path to db or unix socket 64 */ 65 __connection_options__(const dodoString &path); 66 67 dodoString path; ///< path to db or unix socket 68 }; 69 49 70 private: 50 71 … … 64 85 /** 65 86 * constructor 66 * @param dbInfo defines information for connection to db87 * @param info defines information for connection to db 67 88 */ 68 sqlite(const __connection__ &dbInfo);89 sqlite(const data::base::__connection_options__ &info); 69 90 70 91 /** … … 75 96 /** 76 97 * connect to the database 77 * @param dbInfo defines information for connection to db98 * @param info defines information for connection to db 78 99 */ 79 virtual void connect(const __connection__ &dbInfo);100 virtual void connect(const data::base::__connection_options__ &info); 80 101 81 102 /** … … 98 119 * @return amount of received rows from the evaluated request 99 120 */ 100 virtual unsigned int requestedRows() const;121 virtual unsigned int fetchedRows() const; 101 122 102 123 /** 103 * @ return amount of received fields from the evaluatedrequest124 * @param rows defines rows got from the request 104 125 */ 105 virtual unsigned int requestedFields() const;126 virtual void fetchedRows(data::base::rows &rows) const; 106 127 107 128 /** 108 * @return received rows from the evaluated request 129 * execute request for data base 130 * @param query contains query for data base 109 131 */ 110 virtual dodoArray<dodoStringArray> fetchRows() const;132 virtual void exec(const data::base::query &query); 111 133 112 134 /** 113 * @return received fields from the evaluated request135 * execute collected request for data base 114 136 */ 115 virtual dodoStringArray fetchFields() const;137 virtual void exec(); 116 138 117 139 /** 118 * @return structure received rows and fields from the evaluated request 140 * @param rows defines rows for insertion into data base 141 * @param condition defines row insertion condition 119 142 */ 120 virtual __tuples__ fetch() const; 143 virtual void insert(const data::base::rows &rows, 144 const data::base::condition &condition); 121 145 122 146 /** 123 * @return received rows and fields from the evaluated request using hash `key`=>`value` 147 * @param rows defines values of row for update 148 * @param condition defines row update condition 124 149 */ 125 virtual dodoStringMapArray fetchFieldsToRows() const; 126 127 /** 128 * execute request 129 * @param query defines query; you may define it if you don't use db methods like select, update 130 * @param result defines type of result; if true query return the result 131 */ 132 virtual void exec(const dodoString &query = __dodostring__, 133 bool result = false); 150 virtual void update(const data::base::rows &rows, 151 const data::base::condition &condition); 134 152 135 153 protected: 136 154 137 155 /** 138 * construct `insert`statement156 * @return insert SQL statement 139 157 */ 140 virtual void insertCollect();158 virtual dodoString insert(); 141 159 142 160 /** 143 * construct `update`statement161 * @return update SQL statement 144 162 */ 145 virtual void updateCollect();163 virtual dodoString update(); 146 164 147 165 /** … … 160 178 __sqlite__ *handle; ///< DB handle 161 179 162 bool empty; ///< true if liteStmt is empty180 __connection_options__ info; ///< DB connection information 163 181 }; 164 182 }; -
sources/include/libdodo/dataBaseSqliteEx.h
r1406 r1413 58 58 SQLITEEX_EXEC, 59 59 SQLITEEX_SQLITE, 60 SQLITEEX_FETCH ROWS,61 SQLITEEX_ FETCHFIELDSTOROWS,62 SQLITEEX_ GETFIELDSTYPES,60 SQLITEEX_FETCHEDROWS, 61 SQLITEEX_AFFECTEDROWS, 62 SQLITEEX_REQUESTFIELDSTYPES, 63 63 }; 64 64 }; -
sources/include/libdodo/exceptionBasic.h
r1410 r1413 65 65 MODULE_DATABASEMYSQL = 0, 66 66 MODULE_DATABASEPOSTGRESQL, 67 MODULE_DATABASESQLCONSTRUCTOR,68 67 MODULE_DATABASESQLITE, 69 68 MODULE_DATAFORMATXMLPROCESSOR, -
sources/src/dataBaseConnector.cc
r1406 r1413 35 35 using namespace dodo::data::base; 36 36 37 __connection__::__connection__(const dodoString &a_db, 38 const dodoString &a_host, 39 const dodoString &a_user, 40 const dodoString &a_password, 41 const dodoString &a_path, 42 int a_port) : db(a_db), 43 host(a_host), 44 user(a_user), 45 password(a_password), 46 path(a_path), 47 port(a_port) 37 __connection_options__::~__connection_options__() 48 38 { 49 39 } … … 51 41 //------------------------------------------------------------------- 52 42 53 __connection__::__connection__()43 condition::~condition() 54 44 { 55 45 } … … 57 47 //------------------------------------------------------------------- 58 48 59 __tuples__::__tuples__(dodoArray<dodoStringArray> a_rows, dodoStringArray a_fields) : rows(a_rows), 60 fields(a_fields) 49 rows::~rows() 61 50 { 62 51 } … … 64 53 //------------------------------------------------------------------- 65 54 66 __tuples__::__tuples__()55 query::~query() 67 56 { 68 57 } … … 81 70 82 71 //------------------------------------------------------------------- 83 -
sources/src/dataBaseMysql.cc
r1406 r1413 63 63 using namespace dodo::data::base; 64 64 65 mysql::mysql() : empty(true), 66 handle(new __mysql__), 67 type(CLIENT_MULTI_STATEMENTS) 65 mysql::__connection_options__::__connection_options__(const dodoString &db, 66 const dodoString &host, 67 const dodoString &user, 68 const dodoString &password, 69 const dodoString &path, 70 unsigned int port, 71 unsigned long type) : type(type), 72 db(db), 73 host(host), 74 user(user), 75 password(password), 76 path(path), 77 port(port) 78 { 79 } 80 81 //------------------------------------------------------------------- 82 83 mysql::__connection_options__::__connection_options__() : type(TYPE_MULTI_STATEMENTS) 84 { 85 } 86 87 //------------------------------------------------------------------- 88 89 mysql::mysql() : handle(new __mysql__) 68 90 69 91 { … … 77 99 //------------------------------------------------------------------- 78 100 79 mysql::mysql(const __connection__ &info) : empty(true), 80 handle(new __mysql__), 81 type(CLIENT_MULTI_STATEMENTS) 82 101 mysql::mysql(const data::base::__connection_options__ &a_info) : handle(new __mysql__), 102 info(*dynamic_cast<const mysql::__connection_options__ *>(&a_info)) 83 103 { 84 104 #ifndef DATABASE_WO_XEXEC … … 86 106 #endif 87 107 88 collectedData.dbInfo = info;89 90 108 handle->handle = mysql_init(NULL); 91 109 92 if (!mysql_real_connect(handle->handle, 93 collectedData.dbInfo.host.size() == 0 ? NULL : collectedData.dbInfo.host.data(), 94 collectedData.dbInfo.user.size() == 0 ? NULL : collectedData.dbInfo.user.data(), 95 collectedData.dbInfo.password.size() == 0 ? NULL : collectedData.dbInfo.password.data(), 96 collectedData.dbInfo.db.size() == 0 ? NULL : collectedData.dbInfo.db.data(), 97 collectedData.dbInfo.port, 98 collectedData.dbInfo.path.size() == 0 ? NULL : collectedData.dbInfo.path.data(), 99 type)) { 110 unsigned long type = 0; 111 112 if (info.type & __connection_options__::TYPE_MULTI_STATEMENTS) 113 type |= CLIENT_MULTI_STATEMENTS; 114 115 if (info.type & __connection_options__::TYPE_COMPRESS) 116 type |= CLIENT_COMPRESS; 117 118 if (mysql_ssl_set(handle->handle, 119 info.ssl.key.size() == 0 ? NULL : info.ssl.key.data(), 120 info.ssl.cert.size() == 0 ? NULL : info.ssl.cert.data(), 121 info.ssl.ca.size() == 0 ? NULL : info.ssl.ca.data(), 122 info.ssl.capath.size() == 0 ? NULL : info.ssl.capath.data(), 123 info.ssl.cipher.size() == 0 ? NULL : info.ssl.cipher.data()) == 0) 124 type |= CLIENT_SSL; 125 126 try { 127 if (!mysql_real_connect(handle->handle, 128 info.host.size() == 0 ? NULL : info.host.data(), 129 info.user.size() == 0 ? NULL : info.user.data(), 130 info.password.size() == 0 ? NULL : info.password.data(), 131 info.db.size() == 0 ? NULL : info.db.data(), 132 info.port, 133 info.path.size() == 0 ? NULL : info.path.data(), 134 type)) 135 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_MYSQL, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__); 136 } catch (...) { 137 mysql_close(handle->handle); 138 100 139 delete handle; 101 140 102 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_MYSQL, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__);141 throw; 103 142 } 104 143 … … 123 162 { 124 163 if (handle->handle != NULL) { 125 if ( !empty)164 if (handle->result) 126 165 mysql_free_result(handle->result); 127 166 … … 135 174 136 175 void 137 mysql::setConnectionSettings(unsigned long a_type, 138 const __ssl_options__ &options) 139 { 140 if (handle->handle == NULL) 141 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 142 143 type = a_type; 176 mysql::connect(const data::base::__connection_options__ &a_info) 177 { 178 #ifndef DATABASE_WO_XEXEC 179 performPreExec(OPERATION_CONNECT); 180 #endif 181 182 info = *dynamic_cast<const mysql::__connection_options__ *>(&a_info); 183 184 if (handle->handle != NULL) { 185 if (handle->result) { 186 mysql_free_result(handle->result); 187 handle->result = NULL; 188 } 189 190 mysql_close(handle->handle); 191 handle->handle = NULL; 192 } 193 194 handle->handle = mysql_init(NULL); 195 196 unsigned long type = 0; 197 198 if (info.type & __connection_options__::TYPE_MULTI_STATEMENTS) 199 type |= CLIENT_MULTI_STATEMENTS; 200 201 if (info.type & __connection_options__::TYPE_COMPRESS) 202 type |= CLIENT_COMPRESS; 144 203 145 204 if (mysql_ssl_set(handle->handle, 146 options.key.size() == 0 ? NULL : options.key.data(),147 options.cert.size() == 0 ? NULL : options.cert.data(),148 options.ca.size() == 0 ? NULL : options.ca.data(),149 options.capath.size() == 0 ? NULL : options.capath.data(),150 options.cipher.size() == 0 ? NULL : options.cipher.data()) == 0)205 info.ssl.key.size() == 0 ? NULL : info.ssl.key.data(), 206 info.ssl.cert.size() == 0 ? NULL : info.ssl.cert.data(), 207 info.ssl.ca.size() == 0 ? NULL : info.ssl.ca.data(), 208 info.ssl.capath.size() == 0 ? NULL : info.ssl.capath.data(), 209 info.ssl.cipher.size() == 0 ? NULL : info.ssl.cipher.data()) == 0) 151 210 type |= CLIENT_SSL; 152 }153 154 //-------------------------------------------------------------------155 156 void157 mysql::connect(const __connection__ &info)158 {159 collectedData.dbInfo = info;160 161 #ifndef DATABASE_WO_XEXEC162 performPreExec(OPERATION_CONNECT);163 #endif164 165 if (handle->handle != NULL) {166 if (!empty) {167 empty = true;168 mysql_free_result(handle->result);169 }170 171 mysql_close(handle->handle);172 173 handle->handle = NULL;174 }175 176 handle->handle = mysql_init(NULL);177 211 178 212 if (!mysql_real_connect(handle->handle, 179 collectedData.dbInfo.host.size() == 0 ? NULL : collectedData.dbInfo.host.data(),180 collectedData.dbInfo.user.size() == 0 ? NULL : collectedData.dbInfo.user.data(),181 collectedData.dbInfo.password.size() == 0 ? NULL : collectedData.dbInfo.password.data(),182 collectedData.dbInfo.db.size() == 0 ? NULL : collectedData.dbInfo.db.data(),183 collectedData.dbInfo.port,184 collectedData.dbInfo.path.size() == 0 ? NULL : collectedData.dbInfo.path.data(),213 info.host.size() == 0 ? NULL : info.host.data(), 214 info.user.size() == 0 ? NULL : info.user.data(), 215 info.password.size() == 0 ? NULL : info.password.data(), 216 info.db.size() == 0 ? NULL : info.db.data(), 217 info.port, 218 info.path.size() == 0 ? NULL : info.path.data(), 185 219 type)) 186 220 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_CONNECT, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__); … … 209 243 #endif 210 244 211 if (!empty) { 212 empty = true; 245 if (handle->result) { 213 246 mysql_free_result(handle->result); 247 handle->result = NULL; 214 248 } 215 249 216 250 mysql_close(handle->handle); 251 handle->handle = NULL; 217 252 218 253 #ifndef DATABASE_WO_XEXEC 219 254 performPostExec(OPERATION_DISCONNECT); 220 255 #endif 221 222 handle->handle = NULL; 223 } 224 } 225 226 //------------------------------------------------------------------- 227 228 dodoArray<dodo::dodoStringArray> 229 mysql::fetchRows() const 230 { 231 if (handle->handle == NULL) 232 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 233 234 #ifndef DATABASE_WO_XEXEC 235 performPreExec(OPERATION_FETCHROWS); 236 #endif 237 238 dodoArray<dodoStringArray> rows; 239 240 if (empty || !show) 241 return rows; 256 } 257 } 258 259 //------------------------------------------------------------------- 260 261 void 262 mysql::fetchedRows(data::base::rows &a_rows) const 263 { 264 sql::rows *rows = dynamic_cast<sql::rows *>(&a_rows); 265 266 #ifndef DATABASE_WO_XEXEC 267 performPreExec(OPERATION_FETCHEDROWS); 268 #endif 269 270 rows->fields.clear(); 271 rows->values.clear(); 272 273 if (!handle->result) // FIXME: throw exception? 274 return; 242 275 243 276 mysql_data_seek(handle->result, 0); 277 mysql_field_seek(handle->result, 0); 244 278 245 279 unsigned int numFields = mysql_num_fields(handle->result); 280 MYSQL_FIELD *mysqlFields = mysql_fetch_fields(handle->result); 246 281 247 282 #ifndef USE_DEQUE 248 rows.reserve(mysql_num_rows(handle->result)); 283 rows->fields.reserve(numFields); 284 285 rows->values.reserve(mysql_num_rows(handle->result)); 249 286 #endif 250 287 251 288 unsigned long *length, j; 252 289 253 dodoStringArray rowsPart;290 dodoStringArray values; 254 291 255 292 MYSQL_ROW mysqlRow; 256 293 257 294 #ifndef USE_DEQUE 258 rowsPart.reserve(numFields); 259 #endif 295 values.reserve(numFields); 296 #endif 297 298 for (unsigned int i(0); i < numFields; ++i) 299 rows->fields.push_back(mysqlFields[i].name); 260 300 261 301 while ((mysqlRow = mysql_fetch_row(handle->result)) != NULL) { 262 302 length = mysql_fetch_lengths(handle->result); 263 303 264 rowsPart.clear();265 266 304 for (j = 0; j < numFields; ++j) { 267 305 if (mysqlRow[j] != NULL) 268 rowsPart.push_back(dodoString(mysqlRow[j], length[j]));306 values.push_back(dodoString(mysqlRow[j], length[j])); 269 307 else 270 rowsPart.push_back(statements[sql::constructor::STATEMENT_NULL]); 271 } 272 273 rows.push_back(rowsPart); 274 } 275 276 #ifndef DATABASE_WO_XEXEC 277 performPostExec(OPERATION_FETCHROWS); 278 #endif 279 280 return rows; 281 } 282 283 //------------------------------------------------------------------- 284 285 dodo::dodoStringArray 286 mysql::fetchFields() const 287 { 288 if (handle->handle == NULL) 289 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 290 291 #ifndef DATABASE_WO_XEXEC 292 performPreExec(OPERATION_FETCHFIELDS); 293 #endif 294 295 dodoStringArray fields; 296 297 if (empty || !show) 298 return fields; 299 300 mysql_field_seek(handle->result, 0); 301 302 unsigned int numFields = mysql_num_fields(handle->result); 303 MYSQL_FIELD *mysqlFields = mysql_fetch_fields(handle->result); 304 305 #ifndef USE_DEQUE 306 fields.reserve(numFields); 307 #endif 308 309 for (unsigned int i(0); i < numFields; ++i) 310 fields.push_back(mysqlFields[i].name); 311 312 #ifndef DATABASE_WO_XEXEC 313 performPostExec(OPERATION_FETCHFIELDS); 314 #endif 315 316 return fields; 317 } 318 319 //------------------------------------------------------------------- 320 321 __tuples__ 322 mysql::fetch() const 323 { 324 return __tuples__(fetchRows(), fetchFields()); 308 values.push_back(statements[sql::constructor::STATEMENT_NULL]); 309 } 310 311 rows->values.push_back(values); 312 313 values.clear(); 314 } 315 316 #ifndef DATABASE_WO_XEXEC 317 performPostExec(OPERATION_FETCHEDROWS); 318 #endif 325 319 } 326 320 … … 328 322 329 323 unsigned int 330 mysql::requestedRows() const 331 { 332 if (handle->handle == NULL) 333 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 334 335 if (empty || !show) 336 return 0; 337 else 338 return mysql_num_rows(handle->result); 339 } 340 341 //------------------------------------------------------------------- 342 343 unsigned int 344 mysql::requestedFields() const 345 { 346 if (handle->handle == NULL) 347 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 348 349 if (empty || !show) 350 return 0; 351 else 352 return mysql_num_fields(handle->result); 324 mysql::fetchedRows() const 325 { 326 if (handle->result == NULL) 327 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_FETCHEDROWS, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 328 329 return mysql_num_rows(handle->result); 353 330 } 354 331 … … 359 336 { 360 337 if (handle->handle == NULL) 361 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 362 363 if (empty || show) 364 return 0; 365 else 366 return mysql_affected_rows(handle->handle); 338 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_AFFECTEDROWS, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 339 340 return mysql_affected_rows(handle->handle); 367 341 } 368 342 … … 373 347 { 374 348 if (handle->handle == NULL) 375 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 376 377 dodoString temp = collectedData.dbInfo.db + statements[sql::constructor::STATEMENT_COLON] + table; 378 379 dodoMap<dodoString, dodoMap<dodoString, short, dodoMapICaseStringCompare>, dodoMapICaseStringCompare>::iterator types = fieldTypes.find(temp); 349 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_REQUESTFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 350 351 dodoMap<dodoString, dodoMap<dodoString, short, dodoMapICaseStringCompare>, dodoMapICaseStringCompare>::iterator types = fieldTypes.find(table); 380 352 381 353 if (types == fieldTypes.end()) 382 types = fieldTypes.insert(make_pair(t emp, dodoMap<dodoString, short, dodoMapICaseStringCompare>())).first;383 384 request = "describe " + table;354 types = fieldTypes.insert(make_pair(table, dodoMap<dodoString, short, dodoMapICaseStringCompare>())).first; 355 356 dodoString request = "describe " + table; 385 357 386 358 if (mysql_real_query(handle->handle, request.data(), request.size()) != 0) { 387 359 int mysqlErrno = mysql_errno(handle->handle); 388 360 if (reconnect && (mysqlErrno == CR_SERVER_GONE_ERROR || mysqlErrno == CR_SERVER_LOST)) { 389 connect( collectedData.dbInfo);361 connect(info); 390 362 if (mysql_real_query(handle->handle, request.data(), request.size()) != 0) 391 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_ GETFIELDSTYPES, exception::ERRNO_MYSQL, mysqlErrno, mysql_error(handle->handle), __LINE__, __FILE__, request);363 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_REQUESTFIELDSTYPES, exception::ERRNO_MYSQL, mysqlErrno, mysql_error(handle->handle), __LINE__, __FILE__, request); 392 364 } else 393 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_ GETFIELDSTYPES, exception::ERRNO_MYSQL, mysqlErrno, mysql_error(handle->handle), __LINE__, __FILE__, request);365 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_REQUESTFIELDSTYPES, exception::ERRNO_MYSQL, mysqlErrno, mysql_error(handle->handle), __LINE__, __FILE__, request); 394 366 } 395 367 396 368 handle->result = mysql_store_result(handle->handle); 397 369 if (handle->result == NULL) 398 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__); 399 400 empty = false; 370 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_REQUESTFIELDSTYPES, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__); 401 371 402 372 MYSQL_ROW mysqlRow; … … 439 409 440 410 mysql_free_result(handle->result); 441 442 empty = true; 443 } 444 445 //------------------------------------------------------------------- 446 447 void 448 mysql::exec(const dodoString &query, 449 bool result) 411 handle->result = NULL; 412 } 413 414 //------------------------------------------------------------------- 415 416 void 417 mysql::exec() 418 { 419 exec(sql::query(construct())); 420 } 421 422 //------------------------------------------------------------------- 423 424 void 425 mysql::exec(const query &a_query) 426 try 427 { 428 collectedData.query = dynamic_cast<const sql::query *>(&a_query); 429 430 if (handle->handle == NULL) 431 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_EXEC, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 432 433 #ifndef DATABASE_WO_XEXEC 434 performPreExec(OPERATION_EXEC); 435 #endif 436 if (handle->result) { 437 mysql_free_result(handle->result); 438 handle->result = NULL; 439 } 440 441 if (mysql_real_query(handle->handle, collectedData.query->sql.data(), collectedData.query->sql.size()) != 0) { 442 int mysqlErrno = mysql_errno(handle->handle); 443 if (reconnect && (mysqlErrno == CR_SERVER_GONE_ERROR || mysqlErrno == CR_SERVER_LOST)) { 444 connect(info); 445 if (mysql_real_query(handle->handle, collectedData.query->sql.data(), collectedData.query->sql.size()) != 0) 446 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_EXEC, exception::ERRNO_MYSQL, mysqlErrno, mysql_error(handle->handle), __LINE__, __FILE__, collectedData.query->sql); 447 } else { 448 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_EXEC, exception::ERRNO_MYSQL, mysqlErrno, mysql_error(handle->handle), __LINE__, __FILE__, collectedData.query->sql); 449 } 450 } 451 452 if (mysql_field_count(handle->handle) != 0) { 453 handle->result = mysql_store_result(handle->handle); 454 if (handle->result == NULL) 455 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_EXEC, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__); 456 } 457 458 #ifndef DATABASE_WO_XEXEC 459 performPostExec(OPERATION_EXEC); 460 #endif 461 462 collectedData.clear(); 463 } catch (...) { 464 collectedData.clear(); 465 } 466 467 //------------------------------------------------------------------- 468 469 void 470 mysql::setCharset(const dodoString &charset) 450 471 { 451 472 if (handle->handle == NULL) 452 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_GETFIELDSTYPES, exception::ERRNO_LIBDODO, MYSQLEX_NOTOPENED, DATABASEMYSQLEX_NOTOPENED_STR, __LINE__, __FILE__); 453 454 #ifndef DATABASE_WO_XEXEC 455 performPreExec(OPERATION_EXEC); 456 #endif 457 458 if (query.size() == 0) 459 construct(); 460 else { 461 request = query; 462 show = result; 463 } 464 465 if (mysql_real_query(handle->handle, request.data(), request.size()) != 0) { 466 int mysqlErrno = mysql_errno(handle->handle); 467 if (reconnect && (mysqlErrno == CR_SERVER_GONE_ERROR || mysqlErrno == CR_SERVER_LOST)) { 468 connect(collectedData.dbInfo); 469 if (mysql_real_query(handle->handle, request.data(), request.size()) != 0) 470 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_EXEC, exception::ERRNO_MYSQL, mysqlErrno, mysql_error(handle->handle), __LINE__, __FILE__, request); 471 } else 472 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_EXEC, exception::ERRNO_MYSQL, mysqlErrno, mysql_error(handle->handle), __LINE__, __FILE__, request); 473 } 474 475 if (show) { 476 if (!empty) { 477 mysql_free_result(handle->result); 478 empty = true; 479 } 480 481 handle->result = mysql_store_result(handle->handle); 482 if (handle->result == NULL) 483 throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_EXEC, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__); 484 485 empty = false; 486 } 487 488 #ifndef DATABASE_WO_XEXEC 489 performPostExec(OPERATION_EXEC); 490 #endif 491 492 cleanCollected(); 493 request.clear(); 494 } 495 496 //------------------------------------------------------------------- 497 498 void 499 mysql::setCharset(const dodoString &charset)
