00001
00002
00003
00004 #ifndef MYSQLWRAPPER_H
00005 #define MYSQLWRAPPER_H
00006
00007 #include <dmlite/cpp/exceptions.h>
00008 #include <mysql/mysql.h>
00009 #include <stdint.h>
00010 #include <map>
00011 #include <vector>
00012
00013 #include "utils/logger.h"
00014
00015 namespace dmlite {
00016
00017
00018 extern Logger::bitmask mysqllogmask;
00019 extern Logger::component mysqllogname;
00020
00021
00022 class Statement {
00023 public:
00024 Statement(MYSQL* conn, const std::string& db, const char* query) ;
00025 ~Statement() throw ();
00026
00027 void bindParam(unsigned index, int64_t) ;
00028 void bindParam(unsigned index, const std::string& value) ;
00029 void bindParam(unsigned index, const char* value, size_t size) ;
00030
00031 unsigned long execute(void) ;
00032
00033 void bindResult(unsigned index, short* destination) ;
00034 void bindResult(unsigned index, unsigned short* destination) ;
00035 void bindResult(unsigned index, signed int* destination) ;
00036 void bindResult(unsigned index, unsigned int* destination) ;
00037 void bindResult(unsigned index, signed long* destination) ;
00038 void bindResult(unsigned index, unsigned long* destination) ;
00039 void bindResult(unsigned index, signed long long* destination) ;
00040 void bindResult(unsigned index, unsigned long long* destination) ;
00041 void bindResult(unsigned index, char* destination, size_t size) ;
00042 void bindResult(unsigned index, char* destination, size_t size, int) ;
00043
00044 unsigned long count(void) throw ();
00045
00046 bool fetch(void) ;
00047
00048 protected:
00049 private:
00050 enum Step {STMT_CREATED, STMT_EXECUTED,
00051 STMT_RESULTS_UNBOUND, STMT_RESULTS_BOUND,
00052 STMT_DONE, STMT_FAILED};
00053
00054 MYSQL_STMT* stmt_;
00055 unsigned long nParams_;
00056 unsigned long nFields_;
00057 MYSQL_BIND* params_;
00058 MYSQL_BIND* result_;
00059 my_bool* result_null_;
00060 Step status_;
00061
00062
00063 void throwException() ;
00064 void zeroNullResults();
00065 };
00066
00067 };
00068
00069 #endif // MYSQLWRAPPER_H