Changeset 1413:90ddaec5a31a


Ignore:
Timestamp:
01/04/10 23:08:12 (2 years ago)
Author:
niam
Branch:
default
Message:

db: interface redesign

Location:
sources
Files:
3 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • sources/examples/db/test.cc

    r1406 r1413  
    1616 
    1717#ifndef DATABASE_WO_XEXEC 
    18  
    1918void 
    2019hook(xexec::__collected_data__ *odata, 
     
    2322     void                      *udata) 
    2423{ 
    25     accumulator::__collected_data__ *sql = (accumulator::__collected_data__ *)odata; 
     24    sql::constructor::__collected_data__ *sql = (sql::constructor::__collected_data__ *)odata; 
    2625 
    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; 
    3028} 
    31  
    3229#endif 
    3330 
     
    3734{ 
    3835    if (argc == 1) { 
    39         cout << "usage: " << argv[0] << " [postgresql|mysql|sqlite]" << endl; 
     36        cout << "usage: " << argv[0] << " [postgresql [host]|mysql [host]|sqlite]" << endl; 
    4037 
    4138        return 1; 
    4239    } 
    4340 
     41    __connection_options__ *ci; 
     42    connector *db; 
     43 
    4444    try { 
    45         __connection__ info; 
    46         info.db = "test"; 
    4745        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); 
    5848 
    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); 
    6550#else 
    6651            return 1; 
    6752#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); 
    6856 
    69         else if (strcasecmp(argv[1], "mysql") == 0) 
    70 #ifdef MYSQL_EXT 
    71             db = new mysql(info); 
     57            db = new mysql(*ci); 
    7258#else 
    7359            return 1; 
    7460#endif 
     61        } else if (strcasecmp(argv[1], "sqlite") == 0)   { 
     62#ifdef SQLITE3_EXT 
     63            ci = new sqlite::__connection_options__("test.lite"); 
    7564 
    76         else if (strcasecmp(argv[1], "sqlite") == 0) 
    77 #ifdef SQLITE3_EXT 
    78             db = new sqlite(info); 
     65            db = new sqlite(*ci); 
    7966#else 
    8067            return 1; 
    8168#endif 
    82  
    83         else 
    84             return 1; 
     69        } 
    8570 
    8671#ifndef DATABASE_WO_XEXEC 
     
    8873#endif 
    8974 
    90             ///define session charset 
     75        ///define session charset 
    9176        if (strcasecmp(argv[1], "postgresql") == 0) { 
    9277#ifdef POSTGRESQL_EXT 
    93  
    94                           ((postgresql *)db)->setCharset("UTF-8"); 
     78            ((postgresql *)db)->setCharset("UTF-8"); 
    9579 
    9680            cout << "Encoding: " << ((postgresql *)db)->charset() << endl; 
    97  
    9881#endif 
    9982        } else if (strcasecmp(argv[1], "mysql") == 0)   { 
    10083#ifdef MYSQL_EXT 
    101  
    102                           ((mysql *)db)->setCharset("UTF-8"); 
     84            ((mysql *)db)->setCharset("UTF-8"); 
    10385 
    10486            cout << "Encoding: " << ((mysql *)db)->charset() << endl; 
    105  
    10687#endif 
    10788        } 
    10889 
    10990        try { 
    110             db->exec("DROP TABLE test"); 
     91            db->exec(sql::query("DROP TABLE test")); 
    11192        } catch (dodo::exception::basic &ex)   { 
    11293            cout << (dodoString)ex << endl << ex.file << endl << ex.message << endl << ex.line << endl << endl; 
     
    11495 
    11596        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)")); 
    11798        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)")); 
    119100 
    120101        try { 
     
    135116        array["i"] = "1"; 
    136117 
    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"); 
    141122 
    142         __tuples__ store; 
     123        sql::rows rows; 
    143124 
    144125        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'")); 
    146127            db->exec(); 
    147128 
    148             store = db->fetch(); 
     129            db->fetchedRows(rows); 
    149130 
    150             db->insert("test", array); 
     131            db->insert(sql::rows(array), sql::condition("test")); 
    151132            db->exec(); 
    152133 
    153134            array["i"] = "i+1"; 
    154135            array["t1"] = "def"; 
    155             db->update("test", array); 
     136            db->update(sql::rows(array), sql::condition("test")); 
    156137            db->exec(); 
    157138 
     
    160141        } 
    161142 
    162         db->select("test", select, "t1='def'"); 
     143        db->select(sql::condition("test", fields, "t1='def'")); 
    163144        db->exec(); 
    164145 
    165         store = db->fetch(); 
     146        db->fetchedRows(rows); 
    166147 
    167         cout << store.rows.size() << endl; 
     148        cout << rows.values.size() << endl; 
    168149 
    169         dodoArray<dodoStringArray>::iterator i(store.rows.begin()), j(store.rows.end()); 
     150        dodoArray<dodoStringArray>::iterator i(rows.values.begin()), j(rows.values.end()); 
    170151        dodoStringArray::iterator m, n; 
    171152        for (; i != j; i++) { 
     
    181162#endif 
    182163 
     164        ///put binary data into data base 
    183165        tools::filesystem::unlink("test.db"); 
    184166        dodoString b = tools::filesystem::fileContents("test"); 
     
    190172        array["t1"] = ""; 
    191173 
    192         db->insert("test", array); 
     174        db->insert(sql::rows(array), sql::condition("test")); 
    193175        db->exec(); 
    194176 
    195177        db->disconnect(); 
    196         db->connect(info); 
     178        db->connect(*ci); 
    197179 
    198         db->select("test", select, "t0='blob'"); 
     180        db->select(sql::condition("test", fields, "t0='blob'")); 
    199181        db->exec(); 
    200182 
    201         store = db->fetch(); 
     183        db->fetchedRows(rows); 
    202184 
    203             ///put fetched binary data to file 
    204         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]); 
    206188 
    207189        delete db; 
     190        delete ci; 
    208191    } catch (dodo::exception::basic &ex)   { 
    209192        cout << (dodoString)ex << endl << ex.file << endl << ex.message << endl << ex.line << endl << endl; 
  • sources/examples/db_mysql/test.cc

    r1406 r1413  
    2323     void                      *udata) 
    2424{ 
    25     accumulator::__collected_data__ *sql = (accumulator::__collected_data__ *)odata; 
     25    sql::constructor::__collected_data__ *sql = (sql::constructor::__collected_data__ *)odata; 
    2626 
    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; 
    3029} 
    3130#endif 
     
    3837    long now = tools::time::now(); 
    3938 
     39    mysql::__connection_options__ ci("test", argc>1?argv[1]:"localhost", "root", "password", "", 3306); 
     40 
    4041#ifdef MYSQL_EXT 
    4142    try { 
    42         mysql db(__connection__("test", "localhost", "root", "password", "", 3306)); 
     43        mysql db(ci); 
    4344 
    4445#ifndef DATABASE_WO_XEXEC 
     
    4748 
    4849        try { 
    49             db.exec("DROP TABLE test0"); 
     50            db.exec(sql::query("DROP TABLE test0")); 
    5051        } catch (...)   { 
    5152        } 
    5253        try { 
    53             db.exec("DROP TABLE test1"); 
     54            db.exec(sql::query("DROP TABLE test1")); 
    5455        } catch (...)   { 
    5556        } 
    5657 
    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))")); 
    5960 
    6061        db.requestFieldsTypes("test0"); 
    6162        db.requestFieldsTypes("test1"); 
    6263 
     64        sql::rows rows; 
    6365        dodoStringArray fields; 
    64         __tuples__ storage; 
    6566 
    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")); 
    6968        db.exec(); 
    7069 
    71         storage = db.fetch(); 
     70        db.fetchedRows(rows); 
    7271 
    73         dodoStringArray::iterator i = storage.fields.begin(), j = storage.fields.end(); 
     72        dodoStringArray::iterator i = rows.fields.begin(), j = rows.fields.end(); 
    7473        for (; i != j; ++i) 
    7574            cout << "[" << *i << "]\t"; 
     
    8988        mapArray.push_back(array); 
    9089 
    91         db.insert("test0", mapArray); 
     90        db.insert(sql::rows(mapArray), sql::condition("test0")); 
    9291        db.exec(); 
    9392 
     
    9594 
    9695        db.disconnect(); 
    97         db.connect(__connection__("test", "localhost", "root", "password", "", 3306)); 
     96        db.connect(ci); 
    9897 
    9998        array["i"] = "100000"; 
    100         db.update("test0", array); 
     99        db.update(sql::rows(array), sql::condition("test0")); 
    101100        db.exec(); 
    102101 
     
    105104        fields.push_back("t1"); 
    106105 
    107         db.insert("test0", values, fields); 
     106        db.insert(sql::rows(values, fields), sql::condition("test0")); 
    108107        db.exec(); 
    109108 
     
    113112 
    114113        for (int o = 0; o < 100000; o++) { 
    115             db.insert("test0", values, fields); 
     114            db.insert(sql::rows(values, fields), sql::condition("test0")); 
    116115            db.exec(); 
    117116        } 
     
    121120#endif 
    122121 
    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)); 
    124129 
    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)); 
    144131        db.exec(); 
    145132 
    146         db.select("test0"); 
    147         db.limit(10); 
    148         db.exec(); 
     133        db.fetchedRows(rows); 
    149134 
    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()); 
    153136        dodoStringArray::iterator m, n; 
    154137        for (; o != p; o++) { 
     
    160143        } 
    161144    } 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(); 
    163146    } 
    164147#else 
  • sources/examples/db_postgresql/test.cc

    r1406 r1413  
    2323     void                      *udata) 
    2424{ 
    25     accumulator::__collected_data__ *sql = (accumulator::__collected_data__ *)odata; 
     25    sql::constructor::__collected_data__ *sql = (sql::constructor::__collected_data__ *)odata; 
    2626 
    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; 
    3029} 
    3130#endif 
     
    3837#ifdef POSTGRESQL_EXT 
    3938    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); 
    4540 
    46         postgresql db(info); 
     41        postgresql db(ci); 
    4742 
    4843#ifndef DATABASE_WO_XEXEC 
     
    5146 
    5247        try { 
    53             db.exec("DROP TABLE test"); 
     48            db.exec(sql::query("DROP TABLE test")); 
    5449        } catch (...)   { 
    5550        } 
    5651 
    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)")); 
    5853 
    59         __tuples__ store; 
     54        sql::rows rows; 
    6055 
    6156        dodoStringMap array; 
     
    6358        array["t1"] = "abc"; 
    6459 
    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"); 
    6863 
    6964        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'")); 
    7166            db.exec(); 
    7267 
    73             store = db.fetch(); 
     68            db.fetchedRows(rows); 
    7469 
    75             db.insert("test", array); 
     70            db.insert(sql::rows(array), sql::condition("test")); 
    7671            db.exec(); 
    7772 
    7873            array["t1"] = "def"; 
    79             db.update("test", array); 
     74            db.update(sql::rows(array), sql::condition("test")); 
    8075            db.exec(); 
    8176 
     
    8479 
    8580        db.disconnect(); 
    86         db.connect(info); 
     81        db.connect(ci); 
    8782 
    88         db.select("test", select, "t1='def'"); 
     83        db.select(sql::condition("test", fields, "t1='def'")); 
    8984        db.exec(); 
    9085 
    91         cout << db.fetch().rows.size() << endl; 
     86        db.fetchedRows(rows); 
    9287 
    93         store = db.fetch(); 
     88        cout << rows.values.size() << endl; 
    9489 
    95         dodoArray<dodoStringArray>::iterator i(store.rows.begin()), j(store.rows.end()); 
     90        dodoArray<dodoStringArray>::iterator i(rows.values.begin()), j(rows.values.end()); 
    9691        dodoStringArray::iterator m, n; 
    9792        for (; i != j; i++) { 
  • sources/examples/db_sqlite/test.cc

    r1406 r1413  
    2323     void                      *udata) 
    2424{ 
    25     accumulator::__collected_data__ *sql = (accumulator::__collected_data__ *)odata; 
     25    sql::constructor::__collected_data__ *sql = (sql::constructor::__collected_data__ *)odata; 
    2626 
    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; 
    3029} 
    3130#endif 
     
    4039        tools::filesystem::unlink("test.lite", true); 
    4140 
    42         __connection__ info; 
    43         info.path = "test.lite"; 
     41        sqlite::__connection_options__ ci("test.lite"); 
    4442 
    45         sqlite db(info); 
     43        sqlite db(ci); 
    4644 
    4745#ifndef DATABASE_WO_XEXEC 
     
    5048 
    5149        try { 
    52             db.exec("DROP TABLE test"); 
     50            db.exec(sql::query("DROP TABLE test")); 
    5351        } catch (...)   { 
    5452        } 
    5553 
    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; 
    5757 
    5858        dodoStringMap array; 
     
    6060        array["t1"] = "abc"; 
    6161 
    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"); 
    6565 
    6666        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'")); 
    6868            db.exec(); 
    6969 
    7070            cout << "Selected: \n"; 
    71             cout << "Rows: " << db.requestedRows() << endl; 
    72             cout << "Fields: " << db.requestedFields() << endl; 
     71            cout << "Rows: " << db.fetchedRows() << endl; 
    7372 
    74             db.insert("test", array); 
     73            db.insert(sql::rows(array), sql::condition("test")); 
    7574            db.exec(); 
    7675 
    7776            array["t1"] = "def"; 
    78             db.update("test", array); 
     77            db.update(sql::rows(array), sql::condition("test")); 
    7978            db.exec(); 
    8079 
     
    8584 
    8685        db.disconnect(); 
    87         db.connect(info); 
     86        db.connect(ci); 
    8887 
    89         db.select("test", select, "`id`<20 or `t1`='def'"); 
     88        db.select(sql::condition("test", fields, "`id`<20 or `t1`='def'")); 
    9089        db.exec(); 
    9190 
    92         cout << db.fetch().rows.size() << endl; 
     91        db.fetchedRows(rows); 
    9392 
    94         __tuples__ store = db.fetch(); 
     93        cout << rows.values.size() << endl; 
    9594 
    96         dodoArray<dodoStringArray>::iterator i(store.rows.begin()), j(store.rows.end()); 
     95        dodoArray<dodoStringArray>::iterator i(rows.values.begin()), j(rows.values.end()); 
    9796 
    9897        dodoStringArray::iterator m, n; 
  • sources/include/libdodo/data.h

    r1406 r1413  
    3131#define _DATA_H_ 1 
    3232 
    33 #include <libdodo/dataBaseAccumulator.h> 
    3433#include <libdodo/dataBaseConnector.h> 
    3534#include <libdodo/dataBaseMysql.h> 
     
    3837#include <libdodo/dataBasePostgresqlEx.h> 
    3938#include <libdodo/dataBaseSqlConstructor.h> 
    40 #include <libdodo/dataBaseSqlConstructorEx.h> 
    4139#include <libdodo/dataBaseSqlite.h> 
    4240#include <libdodo/dataBaseSqliteEx.h> 
  • sources/include/libdodo/dataBaseConnector.h

    r1406 r1413  
    4040        namespace base { 
    4141            /** 
    42              * @enum joinEnum defines join types 
     42             * @struct __connection_options__ 
     43             * @brief defines connection options for the server 
    4344             */ 
    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__ { 
    5146 
    52                 JOIN_ENUMSIZE 
     47                /** 
     48                 * destructor 
     49                 */ 
     50                virtual ~__connection_options__() = 0; 
    5351            }; 
    5452 
    5553            /** 
    56              * @enum subrequestEnum defines type of sub request 
     54             * @class condition 
     55             * @brief defines condition for data base operations 
    5756             */ 
    58             enum subrequestEnum { 
    59                 SUBREQUEST_UNION = 1, 
    60                 SUBREQUEST_UNION_ALL, 
    61                 SUBREQUEST_MINUS, 
    62                 SUBREQUEST_INTERSECT, 
     57            class condition { 
     58              public: 
    6359 
    64                 SUBREQUEST_ENUMSIZE 
     60                /** 
     61                 * destructor 
     62                 */ 
     63                virtual ~condition() = 0; 
    6564            }; 
    6665 
    6766            /** 
    68              * @struct __tuples__ 
    69              * @brief defines fetched data from db 
     67             * @class row 
     68             * @brief defines rows of data base 
    7069             */ 
    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: 
    7972 
    8073                /** 
    81                  * constructor 
     74                 * destructor 
    8275                 */ 
    83                 __tuples__(); 
    84  
    85                 dodoArray<dodoStringArray> rows;    ///< rows of data 
    86                 dodoStringArray            fields;  ///< names of fields 
     76                virtual ~rows() = 0; 
    8777            }; 
    8878 
    8979            /** 
    90              * @struct __connection__ 
    91              * @brief defines connection options for the server 
     80             * @class query 
     81             * @brief defines data base query 
    9282             */ 
    93             struct __connection__ { 
    94                 /** 
    95                  * constructor 
    96                  */ 
    97                 __connection__(); 
     83            class query { 
     84              public: 
    9885 
    9986                /** 
    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 
    10788                 */ 
    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; 
    12190            }; 
    12291 
    12392            /** 
    12493             * @class connector 
    125              * @brief implements an interface to db through sql and database independent interfaces 
     94             * @brief implements data base interface 
    12695             */ 
    12796            class connector 
     
    137106                enum operationEnum { 
    138107                    OPERATION_CONNECT, 
     108                    OPERATION_DISCONNECT, 
     109                    OPERATION_SELECT, 
     110                    OPERATION_INSERT, 
     111                    OPERATION_UPDATE, 
     112                    OPERATION_REMOVE, 
    139113                    OPERATION_EXEC, 
    140                     OPERATION_DISCONNECT, 
    141                     OPERATION_FETCHROWS, 
    142                     OPERATION_FETCHFIELDS, 
     114                    OPERATION_FETCHEDROWS, 
    143115                }; 
    144116 
     
    155127                /** 
    156128                 * connect to the database 
    157                  * @param dbInfo defines connection information 
     129                 * @param info defines information for connection to db 
    158130                 */ 
    159                 virtual void connect(const __connection__ &dbInfo) = 0; 
     131                virtual void connect(const __connection_options__ &info) = 0; 
    160132 
    161133                /** 
     
    165137 
    166138                /** 
    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 
    171140                 */ 
    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; 
    175142 
    176143                /** 
    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 
    180146                 */ 
    181                 virtual void procedure(const dodoString      &name, 
    182                                        const dodoStringArray &arguments) = 0; 
     147                virtual void insert(const rows      &rows, 
     148                                    const condition &condition) = 0; 
    183149 
    184150                /** 
    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 
    190153                 */ 
    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; 
    194156 
    195157                /** 
    196                  * @param table defines table name 
    197                  * @param fields defines hash of field=>value 
     158                 * @param condition defines row remove condition 
    198159                 */ 
    199                 virtual void insert(const dodoString    &table, 
    200                                     const dodoStringMap &fields) = 0; 
     160                virtual void remove(const condition &condition) = 0; 
    201161 
    202162                /** 
    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 
    205164                 */ 
    206                 virtual void insert(const dodoString               &table, 
    207                                     const dodoArray<dodoStringMap> &fields) = 0; 
     165                virtual void fetchedRows(rows &rows) const = 0; 
    208166 
    209167                /** 
    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 
    213170                 */ 
    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; 
    217172 
    218173                /** 
    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 
    222175                 */ 
    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; 
    345177 
    346178                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  
    5050 
    5151                /** 
    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 
    61108                }; 
    62109 
     
    78125                /** 
    79126                 * constructor 
    80                  * @param dbInfo defines information for connection to db 
    81                  */ 
    82                 mysql(const __connection__ &dbInfo); 
     127                 * @param info defines information for connection to db 
     128                 */ 
     129                mysql(const data::base::__connection_options__ &info); 
    83130 
    84131                /** 
     
    87134                virtual ~mysql(); 
    88135 
    89                 /* 
    90                  * set connection settings 
    91                  * @param type defines type of connection, @see mySQL documentation 
    92                  * @param options defines options of ssl connection 
    93                  * @note type can be: 
    94                  *  CLIENT_COMPRESS         Use compression protocol 
    95                  *      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  
    100136                /** 
    101137                 * connect to the database 
    102                  * @param dbInfo defines information for connection to db 
    103                  */ 
    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); 
    105141 
    106142                /** 
     
    116152 
    117153                /** 
     154                 * @param rows defines rows got from the request 
     155                 */ 
     156                virtual void fetchedRows(data::base::rows &rows) const; 
     157 
     158                /** 
    118159                 * @return amount of affected rows from the evaluated request 
    119160                 */ 
     
    123164                 * @return amount of received rows from the evaluated request 
    124165                 */ 
    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(); 
    159178 
    160179                /** 
     
    177196              private: 
    178197 
    179                 bool empty;             ///< true id mysqlRes is empty 
    180  
    181198                __mysql__ *handle;      ///< DB handle 
    182199 
    183                 unsigned long type;     ///< connection type 
     200                __connection_options__ info; ///< DB connection information 
    184201            }; 
    185202        }; 
  • sources/include/libdodo/dataBaseMysqlEx.h

    r1406 r1413  
    5757                MYSQLEX_EXEC, 
    5858                MYSQLEX_MYSQL, 
    59                 MYSQLEX_GETFIELDSTYPES, 
     59                MYSQLEX_REQUESTFIELDSTYPES, 
     60                MYSQLEX_FETCHEDROWS, 
     61                MYSQLEX_AFFECTEDROWS, 
     62                MYSQLEX_SETCONNECTIONTIMEOUT, 
     63                MYSQLEX_CHARSET, 
     64                MYSQLEX_SETCHARSET, 
    6065            }; 
    6166        }; 
  • sources/include/libdodo/dataBasePostgresql.h

    r1406 r1413  
    4747             */ 
    4848            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 
    4983              private: 
    5084 
     
    6498                /** 
    6599                 * constructor 
    66                  * @param dbInfo defines information for connection to db 
    67                  */ 
    68                 postgresql(const __connection__ &dbInfo); 
     100                 * @param info defines information for connection to db 
     101                 */ 
     102                postgresql(const data::base::__connection_options__ &info); 
    69103 
    70104                /** 
     
    75109                /** 
    76110                 * connect to the database 
    77                  * @param dbInfo defines information for connection to db 
    78                  */ 
    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); 
    80114 
    81115                /** 
     
    98132                 * @return amount of received rows from the evaluated request 
    99133                 */ 
    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(); 
    134151 
    135152                /** 
     
    144161                dodoString charset() const; 
    145162 
     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 
    146177              protected: 
    147178 
    148179                /** 
    149                  * construct `insert` statement 
    150                  */ 
    151                 virtual void insertCollect(); 
    152  
    153                 /** 
    154                  * construct `update` statement 
    155                  */ 
    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(); 
    157188 
    158189#ifdef POSTGRESQL_NO_ENCODINGTOCHAR 
     
    223254              private: 
    224255 
    225                 bool empty;                                                                             ///< true id pgResult is empty 
    226  
    227256                __postgresql__ *handle;                                                                 ///< DB handle 
     257 
     258                __connection_options__ info; ///< DB connection information 
    228259            }; 
    229260        }; 
  • sources/include/libdodo/dataBasePostgresqlEx.h

    r1406 r1413  
    5858                POSTGRESQLEX_POSTGRESQL, 
    5959                POSTGRESQLEX_SETCHARSET, 
    60                 POSTGRESQLEX_GETFIELDSTYPES, 
     60                POSTGRESQLEX_CHARSET, 
     61                POSTGRESQLEX_REQUESTFIELDSTYPES, 
     62                POSTGRESQLEX_FETCHEDROWS, 
     63                POSTGRESQLEX_AFFECTEDROWS, 
    6164            }; 
    6265        }; 
  • sources/include/libdodo/dataBaseSqlConstructor.h

    r1406 r1413  
    3434 
    3535#include <libdodo/types.h> 
    36 #include <libdodo/dataBaseAccumulator.h> 
     36#include <libdodo/dataBaseConnector.h> 
    3737 
    3838namespace dodo { 
     
    4040        namespace base { 
    4141            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 
    42219                /** 
    43220                 * @enum fieldEnum defines field type 
     
    55232                 * If you want to prevent data framing define preventFraming sqlConstructor class propertie as true but remember 
    56233                 */ 
    57                 class constructor : public accumulator { 
     234                class constructor : public connector { 
    58235                  public: 
    59236 
     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 
    60286                    /* 
    61287                     * constructor 
     
    67293                     */ 
    68294                    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); 
    69321 
    70322                    /** 
     
    100352                    dodoMap<dodoString, dodoMap<dodoString, short, dodoMapICaseStringCompare>, dodoMapICaseStringCompare> fieldTypes;   ///< hash of 'db:table' => 'field => 'type'' 
    101353 
    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(); 
    151373 
    152374                    /** 
     
    174396                        STATEMENT_RIGHTBRACKET, 
    175397                        STATEMENT_SELECT, 
    176                         STATEMENT_CALL, 
    177398                        STATEMENT_FROM, 
     399                        STATEMENT_STAR, 
    178400                        STATEMENT_COLON, 
    179401                        STATEMENT_APOSTROPHECOMA, 
     
    186408                        STATEMENT_SET, 
    187409                        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, 
    188419                        STATEMENT_NULL, 
    189420 
     
    191422                    }; 
    192423 
    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 
    200429                }; 
    201430            }; 
  • sources/include/libdodo/dataBaseSqlite.h

    r1406 r1413  
    4747             */ 
    4848            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 
    4970              private: 
    5071 
     
    6485                /** 
    6586                 * constructor 
    66                  * @param dbInfo defines information for connection to db 
     87                 * @param info defines information for connection to db 
    6788                 */ 
    68                 sqlite(const __connection__ &dbInfo); 
     89                sqlite(const data::base::__connection_options__ &info); 
    6990 
    7091                /** 
     
    7596                /** 
    7697                 * connect to the database 
    77                  * @param dbInfo defines information for connection to db 
     98                 * @param info defines information for connection to db 
    7899                 */ 
    79                 virtual void connect(const __connection__ &dbInfo); 
     100                virtual void connect(const data::base::__connection_options__ &info); 
    80101 
    81102                /** 
     
    98119                 * @return amount of received rows from the evaluated request 
    99120                 */ 
    100                 virtual unsigned int requestedRows() const; 
     121                virtual unsigned int fetchedRows() const; 
    101122 
    102123                /** 
    103                  * @return amount of received fields from the evaluated request 
     124                 * @param rows defines rows got from the request 
    104125                 */ 
    105                 virtual unsigned int requestedFields() const; 
     126                virtual void fetchedRows(data::base::rows &rows) const; 
    106127 
    107128                /** 
    108                  * @return received rows from the evaluated request 
     129                 * execute request for data base 
     130                 * @param query contains query for data base 
    109131                 */ 
    110                 virtual dodoArray<dodoStringArray> fetchRows() const; 
     132                virtual void exec(const data::base::query &query); 
    111133 
    112134                /** 
    113                  * @return received fields from the evaluated request 
     135                 * execute collected request for data base 
    114136                 */ 
    115                 virtual dodoStringArray fetchFields() const; 
     137                virtual void exec(); 
    116138 
    117139                /** 
    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 
    119142                 */ 
    120                 virtual __tuples__ fetch() const; 
     143                virtual void insert(const data::base::rows      &rows, 
     144                                    const data::base::condition &condition); 
    121145 
    122146                /** 
    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 
    124149                 */ 
    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); 
    134152 
    135153              protected: 
    136154 
    137155                /** 
    138                  * construct `insert` statement 
     156                 * @return insert SQL statement 
    139157                 */ 
    140                 virtual void insertCollect(); 
     158                virtual dodoString insert(); 
    141159 
    142160                /** 
    143                  * construct `update` statement 
     161                 * @return update SQL statement 
    144162                 */ 
    145                 virtual void updateCollect(); 
     163                virtual dodoString update(); 
    146164 
    147165                /** 
     
    160178                __sqlite__ *handle;                 ///< DB handle 
    161179 
    162                 bool empty;                         ///< true if liteStmt is empty 
     180                __connection_options__ info; ///< DB connection information 
    163181            }; 
    164182        }; 
  • sources/include/libdodo/dataBaseSqliteEx.h

    r1406 r1413  
    5858                SQLITEEX_EXEC, 
    5959                SQLITEEX_SQLITE, 
    60                 SQLITEEX_FETCHROWS, 
    61                 SQLITEEX_FETCHFIELDSTOROWS, 
    62                 SQLITEEX_GETFIELDSTYPES, 
     60                SQLITEEX_FETCHEDROWS, 
     61                SQLITEEX_AFFECTEDROWS, 
     62                SQLITEEX_REQUESTFIELDSTYPES, 
    6363            }; 
    6464        }; 
  • sources/include/libdodo/exceptionBasic.h

    r1410 r1413  
    6565            MODULE_DATABASEMYSQL = 0, 
    6666            MODULE_DATABASEPOSTGRESQL, 
    67             MODULE_DATABASESQLCONSTRUCTOR, 
    6867            MODULE_DATABASESQLITE, 
    6968            MODULE_DATAFORMATXMLPROCESSOR, 
  • sources/src/dataBaseConnector.cc

    r1406 r1413  
    3535using namespace dodo::data::base; 
    3636 
    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__() 
    4838{ 
    4939} 
     
    5141//------------------------------------------------------------------- 
    5242 
    53 __connection__::__connection__() 
     43condition::~condition() 
    5444{ 
    5545} 
     
    5747//------------------------------------------------------------------- 
    5848 
    59 __tuples__::__tuples__(dodoArray<dodoStringArray> a_rows, dodoStringArray a_fields) : rows(a_rows), 
    60                                                                                       fields(a_fields) 
     49rows::~rows() 
    6150{ 
    6251} 
     
    6453//------------------------------------------------------------------- 
    6554 
    66 __tuples__::__tuples__() 
     55query::~query() 
    6756{ 
    6857} 
     
    8170 
    8271//------------------------------------------------------------------- 
    83  
  • sources/src/dataBaseMysql.cc

    r1406 r1413  
    6363using namespace dodo::data::base; 
    6464 
    65 mysql::mysql() : empty(true), 
    66                  handle(new __mysql__), 
    67                  type(CLIENT_MULTI_STATEMENTS) 
     65mysql::__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 
     83mysql::__connection_options__::__connection_options__() : type(TYPE_MULTI_STATEMENTS) 
     84{ 
     85} 
     86 
     87//------------------------------------------------------------------- 
     88 
     89mysql::mysql() : handle(new __mysql__) 
    6890 
    6991{ 
     
    7799//------------------------------------------------------------------- 
    78100 
    79 mysql::mysql(const __connection__ &info) : empty(true), 
    80                                            handle(new __mysql__), 
    81                                            type(CLIENT_MULTI_STATEMENTS) 
    82  
     101mysql::mysql(const data::base::__connection_options__ &a_info) : handle(new __mysql__), 
     102                                                                 info(*dynamic_cast<const mysql::__connection_options__ *>(&a_info)) 
    83103{ 
    84104#ifndef DATABASE_WO_XEXEC 
     
    86106#endif 
    87107 
    88     collectedData.dbInfo = info; 
    89  
    90108    handle->handle = mysql_init(NULL); 
    91109 
    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 
    100139        delete handle; 
    101140 
    102         throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_MYSQL, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__); 
     141        throw; 
    103142    } 
    104143 
     
    123162{ 
    124163    if (handle->handle != NULL) { 
    125         if (!empty) 
     164        if (handle->result) 
    126165            mysql_free_result(handle->result); 
    127166 
     
    135174 
    136175void 
    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; 
     176mysql::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; 
    144203 
    145204    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) 
    151210        type |= CLIENT_SSL; 
    152 } 
    153  
    154 //------------------------------------------------------------------- 
    155  
    156 void 
    157 mysql::connect(const __connection__ &info) 
    158 { 
    159     collectedData.dbInfo = info; 
    160  
    161 #ifndef DATABASE_WO_XEXEC 
    162     performPreExec(OPERATION_CONNECT); 
    163 #endif 
    164  
    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); 
    177211 
    178212    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(), 
    185219                            type)) 
    186220        throw exception::basic(exception::MODULE_DATABASEMYSQL, MYSQLEX_CONNECT, exception::ERRNO_MYSQL, mysql_errno(handle->handle), mysql_error(handle->handle), __LINE__, __FILE__); 
     
    209243#endif 
    210244 
    211         if (!empty) { 
    212             empty = true; 
     245        if (handle->result) { 
    213246            mysql_free_result(handle->result); 
     247            handle->result = NULL; 
    214248        } 
    215249 
    216250        mysql_close(handle->handle); 
     251        handle->handle = NULL; 
    217252 
    218253#ifndef DATABASE_WO_XEXEC 
    219254        performPostExec(OPERATION_DISCONNECT); 
    220255#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 
     261void 
     262mysql::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; 
    242275 
    243276    mysql_data_seek(handle->result, 0); 
     277    mysql_field_seek(handle->result, 0); 
    244278 
    245279    unsigned int numFields = mysql_num_fields(handle->result); 
     280    MYSQL_FIELD *mysqlFields = mysql_fetch_fields(handle->result); 
    246281 
    247282#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)); 
    249286#endif 
    250287 
    251288    unsigned long *length, j; 
    252289 
    253     dodoStringArray rowsPart; 
     290    dodoStringArray values; 
    254291 
    255292    MYSQL_ROW mysqlRow; 
    256293 
    257294#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); 
    260300 
    261301    while ((mysqlRow = mysql_fetch_row(handle->result)) != NULL) { 
    262302        length = mysql_fetch_lengths(handle->result); 
    263303 
    264         rowsPart.clear(); 
    265  
    266304        for (j = 0; j < numFields; ++j) { 
    267305            if (mysqlRow[j] != NULL) 
    268                 rowsPart.push_back(dodoString(mysqlRow[j], length[j])); 
     306                values.push_back(dodoString(mysqlRow[j], length[j])); 
    269307            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 
    325319} 
    326320 
     
    328322 
    329323unsigned 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); 
     324mysql::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); 
    353330} 
    354331 
     
    359336{ 
    360337    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); 
    367341} 
    368342 
     
    373347{ 
    374348    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); 
    380352 
    381353    if (types == fieldTypes.end()) 
    382         types = fieldTypes.insert(make_pair(temp, 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; 
    385357 
    386358    if (mysql_real_query(handle->handle, request.data(), request.size()) != 0) { 
    387359        int mysqlErrno = mysql_errno(handle->handle); 
    388360        if (reconnect && (mysqlErrno == CR_SERVER_GONE_ERROR || mysqlErrno == CR_SERVER_LOST)) { 
    389             connect(collectedData.dbInfo); 
     361            connect(info); 
    390362            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); 
    392364        } 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); 
    394366    } 
    395367 
    396368    handle->result = mysql_store_result(handle->handle); 
    397369    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__); 
    401371 
    402372    MYSQL_ROW mysqlRow; 
     
    439409 
    440410    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 
     416void 
     417mysql::exec() 
     418{ 
     419    exec(sql::query(construct())); 
     420} 
     421 
     422//------------------------------------------------------------------- 
     423 
     424void 
     425mysql::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 
     469void 
     470mysql::setCharset(const dodoString &charset) 
    450471{ 
    451472    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)