From 1216f0355cac3b265d65b3a5bc2b1f47e0782058 Mon Sep 17 00:00:00 2001 From: Myun2 Date: Wed, 2 Jun 2010 03:17:03 +0900 Subject: [PATCH] =?utf8?q?db/base.hpp:=20SQL=E4=BD=9C=E3=82=8B=E5=87=A6?= =?utf8?q?=E7=90=86=E3=81=A8=E3=81=97=E3=81=A6sql.hpp=E3=81=AB=E7=A7=BB?= =?utf8?q?=E5=8B=95=E3=81=A0=E3=81=B9=20db/sql.hpp:=20create=5Ftable():=20?= =?utf8?q?=E3=81=A8=E3=82=8A=E3=81=82=E3=81=88=E3=81=9A=E3=82=AB=E3=83=A9?= =?utf8?q?=E3=83=A0=E7=84=A1=E3=81=97=E3=81=AE=E3=83=86=E3=83=BC=E3=83=96?= =?utf8?q?=E3=83=AB=E4=BD=9C=E3=82=8B=E3=81=A0=E3=81=91=E3=83=BC=E3=80=82?= =?utf8?q?=E3=81=AB=E3=81=97=E3=81=A6=E3=81=BF=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/roast/db/base.hpp | 28 +++++------------------- include/roast/db/sql.hpp | 53 ++++++++++++++++++++++++++++++++++++++++++++- include/roast/db/sqlite.hpp | 2 +- 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/include/roast/db/base.hpp b/include/roast/db/base.hpp index 08f932f6..95e03074 100644 --- a/include/roast/db/base.hpp +++ b/include/roast/db/base.hpp @@ -7,11 +7,14 @@ #define __SFJP_ROAST__db__base_HPP__ #include +#include "roast/db/sql.hpp" namespace roast { namespace db { + using namespace ::roast::sql; + ///////////////////////////////////////// class string @@ -38,28 +41,7 @@ namespace roast class table { public: - typedef struct - { - ::std::string name; - ::std::string data_type; - int length; - bool is_unsigned; - bool is_zerofill; - bool is_null_permit; - bool is_primary; - bool is_unique; - ::std::string default; - ::std::string mix; - ::std::string max; - ::std::string foreign_table; - ::std::string foreign_column; - bool auto_increment; - ::std::string comment; - ::std::string extensions; - } - create_column; - public: - void create(const char* name, const ::std::vector& columns); + void create(const char* name, const ::std::vector& columns); }; ///////////////////////////////////////// @@ -68,7 +50,7 @@ namespace roast { public: //bool open(const char* path); - bool connect(const char* name, const char* user=0, const char* pass=0) =0; + virtual bool connect(const char* name, const char* user=0, const char* pass=0) =0; }; diff --git a/include/roast/db/sql.hpp b/include/roast/db/sql.hpp index 3a361104..cf2b4705 100644 --- a/include/roast/db/sql.hpp +++ b/include/roast/db/sql.hpp @@ -6,10 +6,61 @@ #ifndef __SFJP_ROAST__db__sql_HPP__ #define __SFJP_ROAST__db__sql_HPP__ +#include + +#define _ROAST_SQL_DEFULT_QUERY_BUFFER_LENGTH (256) + namespace roast { - namespace db + namespace sql { + typedef ::std::string + _query_t, query_t, sql_query, _sql_query; + + /////////////////////////////////////////////////////////////////////////// + + typedef struct + { + ::std::string name; + ::std::string data_type; + int length; + bool is_unsigned; + bool is_zerofill; + bool is_null_permit; + bool is_primary; + bool is_unique; + ::std::string default; + ::std::string mix; + ::std::string max; + ::std::string foreign_table; + ::std::string foreign_column; + bool auto_increment; + ::std::string comment; + ::std::string extensions; + } + create_column_info; + + /////////////////////////////////////////// + + // CREATE TABLE + _query_t create_table(const char* name, const ::std::vector& columns) + { + _query_t q; + q.resize(_ROAST_SQL_DEFULT_QUERY_BUFFER_LENGTH); + q = "CREATE TABLE "; + + q += name; + q += ' '; + + for(size_t i=0; i