6 #define ATLASSERT assert
21 typedef std::basic_string
<TCHAR
> Text
;
25 static void get_column_Int(sqlite3_stmt
* stmt
, int index
, T
& val
)
27 val
= sqlite3_column_int(stmt
, index
);
31 static void get_column_Text(sqlite3_stmt
* stmt
, int index
, T
& val
)
33 #if defined(_UNICODE) || defined(UNICODE)
34 val
= (const TCHAR
*)sqlite3_column_text16(stmt
, index
);
36 val
= (const TCHAR
*)sqlite3_column_text(stmt
, index
);
40 static void set_param_null(sqlite3_stmt
* stmt
, int index
)
42 int nResult
= sqlite3_bind_null(stmt
, index
+ 1);
43 ATLASSERT(SQLITE_OK
== nResult
);
46 static void set_param_Text(sqlite3_stmt
* stmt
, const Text
& val
, int index
)
48 #if defined(_UNICODE) || defined(UNICODE)
49 int nResult
= sqlite3_bind_text16(stmt
, index
+ 1, val
.c_str(), -1, SQLITE_TRANSIENT
);
51 int nResult
= sqlite3_bind_text(stmt
, index
+ 1, val
.c_str(), -1, SQLITE_TRANSIENT
);
53 ATLASSERT(SQLITE_OK
== nResult
);
56 static void set_param_Any(sqlite3_stmt
* stmt
, const Any
& val
, int index
)
58 set_param_Text(stmt
,val
,index
);
61 static void set_param_Int(sqlite3_stmt
* stmt
, const Int
& val
, int index
)
63 int nResult
= sqlite3_bind_int(stmt
, index
+ 1, val
);
64 ATLASSERT(SQLITE_OK
== nResult
);
67 template<class Container
, class Binder
, class Params
>
68 static bool do_select(sqlite3
* db
, Container
& result
, const TCHAR
* sql
, Binder binder
, Params params
)
73 #if defined(_UNICODE) || defined(UNICODE)
74 nResult
= sqlite3_prepare16(db
, sql
, -1, &stmt
, (void const**)&pszTail
);
76 nResult
= sqlite3_prepare(db
, sql
, -1, &stmt
, &pszTail
);
78 ATLASSERT(SQLITE_OK
== nResult
);
79 //printf("%u\n%S\n%s\n",nResult,sql,sqlite3_errmsg(db));
80 if (SQLITE_OK
!= nResult
)
82 //log_sqlite(sql,instDB);
86 params
.set_params(stmt
);
90 while(SQLITE_ROW
== sqlite3_step(stmt
)) //Iterate all objects
92 result
.push_back(typename
Container::value_type());
93 binder
.of_stmt(stmt
,result
.back());
97 nResult
= sqlite3_finalize(stmt
);
98 if (SQLITE_OK
!= nResult
)
108 void set_params(sqlite3_stmt
*) {}
111 template<class Params
>
112 static int do_execute(sqlite3
* db
, const char* sql
, Params params
)
117 #if defined(_UNICODE) || defined(UNICODE)
118 nResult
= sqlite3_prepare16(db
, sql
, -1, &stmt
, (void const**)&pszTail
);
120 nResult
= sqlite3_prepare(db
, sql
, -1, &stmt
, &pszTail
);
122 //ATLASSERT(SQLITE_OK == nResult);
123 if (SQLITE_OK
!= nResult
)
128 params
.set_params(stmt
);
130 //Execute the command
131 nResult
= sqlite3_step(stmt
);
132 ATLASSERT(SQLITE_DONE
== nResult
);
134 //Destroy the command
135 nResult
= sqlite3_finalize(stmt
);