aboutsummaryrefslogtreecommitdiff
path: root/sqlite3_type.go
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2016-11-04 23:24:02 +0900
committerGitHub <noreply@github.com>2016-11-04 23:24:02 +0900
commitf4e49e6484de6dd3ffaf25eb103de03118732782 (patch)
tree8b893ca791939e310bd0eb741efbc55654ac9c50 /sqlite3_type.go
parentremove -Wno-c99-extension (diff)
parentseparate test (diff)
downloadgolite-f4e49e6484de6dd3ffaf25eb103de03118732782.tar.gz
golite-f4e49e6484de6dd3ffaf25eb103de03118732782.tar.xz
Merge pull request #348 from mattn/ping
new go1.8 feature
Diffstat (limited to 'sqlite3_type.go')
-rw-r--r--sqlite3_type.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/sqlite3_type.go b/sqlite3_type.go
new file mode 100644
index 0000000..748bc42
--- /dev/null
+++ b/sqlite3_type.go
@@ -0,0 +1,54 @@
+package sqlite3
+
+/*
+#ifndef USE_LIBSQLITE3
+#include <sqlite3-binding.h>
+#else
+#include <sqlite3.h>
+#endif
+*/
+import "C"
+import (
+ "reflect"
+ "time"
+)
+
+func (rc *SQLiteRows) ColumnTypeDatabaseTypeName(i int) string {
+ return C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i)))
+}
+
+/*
+func (rc *SQLiteRows) ColumnTypeLength(index int) (length int64, ok bool) {
+ return 0, false
+}
+
+func (rc *SQLiteRows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) {
+ return 0, 0, false
+}
+*/
+
+func (rc *SQLiteRows) ColumnTypeNullable(i int) (nullable, ok bool) {
+ return true, true
+}
+
+func (rc *SQLiteRows) ColumnTypeScanType(i int) reflect.Type {
+ switch C.sqlite3_column_type(rc.s.s, C.int(i)) {
+ case C.SQLITE_INTEGER:
+ switch C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i))) {
+ case "timestamp", "datetime", "date":
+ return reflect.TypeOf(time.Time{})
+ case "boolean":
+ return reflect.TypeOf(false)
+ }
+ return reflect.TypeOf(int64(0))
+ case C.SQLITE_FLOAT:
+ return reflect.TypeOf(float64(0))
+ case C.SQLITE_BLOB:
+ return reflect.SliceOf(reflect.TypeOf(byte(0)))
+ case C.SQLITE_NULL:
+ return reflect.TypeOf(nil)
+ case C.SQLITE_TEXT:
+ return reflect.TypeOf("")
+ }
+ return reflect.SliceOf(reflect.TypeOf(byte(0)))
+}