OSDN Git Service

add sqlite vendor (#48)
[bytom/vapor.git] / vendor / github.com / mattn / go-sqlite3 / sqlite3_type.go
1 package sqlite3
2
3 /*
4 #ifndef USE_LIBSQLITE3
5 #include <sqlite3-binding.h>
6 #else
7 #include <sqlite3.h>
8 #endif
9 */
10 import "C"
11 import (
12         "reflect"
13         "time"
14 )
15
16 // ColumnTypeDatabaseTypeName implement RowsColumnTypeDatabaseTypeName.
17 func (rc *SQLiteRows) ColumnTypeDatabaseTypeName(i int) string {
18         return C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i)))
19 }
20
21 /*
22 func (rc *SQLiteRows) ColumnTypeLength(index int) (length int64, ok bool) {
23         return 0, false
24 }
25
26 func (rc *SQLiteRows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) {
27         return 0, 0, false
28 }
29 */
30
31 // ColumnTypeNullable implement RowsColumnTypeNullable.
32 func (rc *SQLiteRows) ColumnTypeNullable(i int) (nullable, ok bool) {
33         return true, true
34 }
35
36 // ColumnTypeScanType implement RowsColumnTypeScanType.
37 func (rc *SQLiteRows) ColumnTypeScanType(i int) reflect.Type {
38         switch C.sqlite3_column_type(rc.s.s, C.int(i)) {
39         case C.SQLITE_INTEGER:
40                 switch C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i))) {
41                 case "timestamp", "datetime", "date":
42                         return reflect.TypeOf(time.Time{})
43                 case "boolean":
44                         return reflect.TypeOf(false)
45                 }
46                 return reflect.TypeOf(int64(0))
47         case C.SQLITE_FLOAT:
48                 return reflect.TypeOf(float64(0))
49         case C.SQLITE_BLOB:
50                 return reflect.SliceOf(reflect.TypeOf(byte(0)))
51         case C.SQLITE_NULL:
52                 return reflect.TypeOf(nil)
53         case C.SQLITE_TEXT:
54                 return reflect.TypeOf("")
55         }
56         return reflect.SliceOf(reflect.TypeOf(byte(0)))
57 }