# See the License for the specific language governing permissions and
# limitations under the License.
-module sqlite3
+module sqlite3 is pkgconfig("sqlite3")
in "C header" `{
- #include "sqlite3.h"
+ #include <sqlite3.h>
`}
extern class Sqlite3Code `{int`}
new done `{ return SQLITE_DONE; `} # 101 /* sqlite3_step() has finished executing */
fun is_done: Bool `{ return recv == SQLITE_DONE; `}
+
+ redef fun to_s: String import NativeString.to_s `{
+#if SQLITE_VERSION_NUMBER >= 3007015
+ char *err = (char *)sqlite3_errstr(recv);
+#else
+ char *err = "sqlite3_errstr supported only by version >= 3.7.15";
+#endif
+ if (err == NULL) err = "";
+ return NativeString_to_s(err);
+ `}
end
extern class Statement `{sqlite3_stmt*`}
return sqlite3_step(recv);
`}
- fun column_name(i: Int) : String import String::from_cstring `{
+ fun column_name(i: Int) : String import NativeString.to_s `{
const char * name = (sqlite3_column_name(recv, i));
if(name == NULL){
name = "";
}
char * ret = (char *) name;
- return new_String_from_cstring(ret);
+ return NativeString_to_s(ret);
`}
fun column_bytes(i: Int) : Int `{
return sqlite3_column_int(recv, i);
`}
- fun column_text(i: Int) : String import String::from_cstring `{
+ fun column_text(i: Int) : String import NativeString.to_s `{
char * ret = (char *) sqlite3_column_text(recv, i);
if( ret == NULL ){
ret = "";
}
- return new_String_from_cstring(ret);
+ return NativeString_to_s(ret);
`}
fun column_type(i: Int) : Int `{
end
extern class Sqlite3 `{sqlite3 *`}
- new open(filename: String) import String::to_cstring `{
+ new open(filename: String) import String.to_cstring `{
sqlite3 *self;
sqlite3_open(String_to_cstring(filename), &self);
return self;
fun close `{ sqlite3_close(recv); `}
- fun exec(sql : String): Sqlite3Code import String::to_cstring `{
+ fun exec(sql : String): Sqlite3Code import String.to_cstring `{
return sqlite3_exec(recv, String_to_cstring(sql), 0, 0, 0);
`}
- fun prepare(sql: String): nullable Statement import String::to_cstring, Statement as nullable `{
+ fun prepare(sql: String): nullable Statement import String.to_cstring, Statement.as nullable `{
sqlite3_stmt *stmt;
int res = sqlite3_prepare_v2(recv, String_to_cstring(sql), -1, &stmt, 0);
if (res == SQLITE_OK)
return sqlite3_last_insert_rowid(recv);
`}
- fun get_error : Int import String::from_cstring `{
+ fun error: Sqlite3Code `{
return sqlite3_errcode(recv);
`}
-
- fun get_error_str : String import String::from_cstring `{
- char * err =(char *) sqlite3_errmsg(recv);
- if(err == NULL){
- err = "";
- }
- return new_String_from_cstring(err);
- `}
end