You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sqlite3_type.go 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
  2. //
  3. // Use of this source code is governed by an MIT-style
  4. // license that can be found in the LICENSE file.
  5. package sqlite3
  6. /*
  7. #ifndef USE_LIBSQLITE3
  8. #include <sqlite3-binding.h>
  9. #else
  10. #include <sqlite3.h>
  11. #endif
  12. */
  13. import "C"
  14. import (
  15. "reflect"
  16. "time"
  17. )
  18. // ColumnTypeDatabaseTypeName implement RowsColumnTypeDatabaseTypeName.
  19. func (rc *SQLiteRows) ColumnTypeDatabaseTypeName(i int) string {
  20. return C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i)))
  21. }
  22. /*
  23. func (rc *SQLiteRows) ColumnTypeLength(index int) (length int64, ok bool) {
  24. return 0, false
  25. }
  26. func (rc *SQLiteRows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) {
  27. return 0, 0, false
  28. }
  29. */
  30. // ColumnTypeNullable implement RowsColumnTypeNullable.
  31. func (rc *SQLiteRows) ColumnTypeNullable(i int) (nullable, ok bool) {
  32. return true, true
  33. }
  34. // ColumnTypeScanType implement RowsColumnTypeScanType.
  35. func (rc *SQLiteRows) ColumnTypeScanType(i int) reflect.Type {
  36. switch C.sqlite3_column_type(rc.s.s, C.int(i)) {
  37. case C.SQLITE_INTEGER:
  38. switch C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i))) {
  39. case "timestamp", "datetime", "date":
  40. return reflect.TypeOf(time.Time{})
  41. case "boolean":
  42. return reflect.TypeOf(false)
  43. }
  44. return reflect.TypeOf(int64(0))
  45. case C.SQLITE_FLOAT:
  46. return reflect.TypeOf(float64(0))
  47. case C.SQLITE_BLOB:
  48. return reflect.SliceOf(reflect.TypeOf(byte(0)))
  49. case C.SQLITE_NULL:
  50. return reflect.TypeOf(nil)
  51. case C.SQLITE_TEXT:
  52. return reflect.TypeOf("")
  53. }
  54. return reflect.SliceOf(reflect.TypeOf(byte(0)))
  55. }