Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
d6af0c6f
Commit
d6af0c6f
authored
Jan 18, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move global variables related to time storage into connection statuses.
parent
1b72095a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
11 deletions
+10
-11
driver.go
driver.go
+1
-0
sqlite.go
sqlite.go
+6
-1
stmt.go
stmt.go
+3
-10
No files found.
driver.go
View file @
d6af0c6f
...
...
@@ -52,6 +52,7 @@ func (d *impl) Open(name string) (driver.Conn, error) {
return
nil
,
err
}
c
.
BusyTimeout
(
10
*
time
.
Second
)
c
.
ScanNumericalAsTime
=
true
return
&
conn
{
c
},
nil
}
...
...
sqlite.go
View file @
d6af0c6f
...
...
@@ -156,6 +156,11 @@ type Conn struct {
modules
map
[
string
]
*
sqliteModule
timeUsed
time
.
Time
nTransaction
uint8
// DefaultTimeLayout specifies the layout used to persist time ("2006-01-02 15:04:05.999Z07:00" by default).
// Using type alias implementing the Scanner/Valuer interfaces is suggested...
DefaultTimeLayout
string
// ScanNumericalAsTime tells the driver to try to parse column with NUMERIC affinity as time.Time (using the DefaultTimeLayout)
ScanNumericalAsTime
bool
}
// Version returns the run-time library version number
...
...
@@ -220,7 +225,7 @@ func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error)
if
db
==
nil
{
return
nil
,
errors
.
New
(
"sqlite succeeded without returning a database"
)
}
c
:=
&
Conn
{
db
:
db
,
stmtCache
:
newCache
()}
c
:=
&
Conn
{
db
:
db
,
stmtCache
:
newCache
()
,
DefaultTimeLayout
:
"2006-01-02 15:04:05.999Z07:00"
}
if
os
.
Getenv
(
"SQLITE_DEBUG"
)
!=
""
{
c
.
SetAuthorizer
(
authorizer
,
c
.
db
)
c
.
SetCacheSize
(
0
)
...
...
stmt.go
View file @
d6af0c6f
...
...
@@ -339,10 +339,6 @@ var NullIfEmptyString = true
// NullIfZeroTime transforms zero time (time.Time.IsZero) to null when true (true by default)
var
NullIfZeroTime
=
true
// DefaultTimeLayout specifies the layout used to persist time ("2006-01-02 15:04:05.999Z07:00" by default).
// Using type alias implementing the Scanner/Valuer interfaces is suggested...
var
DefaultTimeLayout
=
"2006-01-02 15:04:05.999Z07:00"
// BindByIndex binds value to the specified host parameter of the prepared statement.
// Value's type/kind is used to find the storage class.
// The leftmost SQL parameter has an index of 1.
...
...
@@ -388,7 +384,7 @@ func (s *Stmt) BindByIndex(index int, value interface{}) error {
rv
=
C
.
sqlite3_bind_null
(
s
.
stmt
,
i
)
}
else
{
//rv = C.sqlite3_bind_int64(s.stmt, i, C.sqlite3_int64(value.Unix()))
cs
,
l
:=
cstring
(
value
.
Format
(
DefaultTimeLayout
))
cs
,
l
:=
cstring
(
value
.
Format
(
s
.
c
.
DefaultTimeLayout
))
rv
=
C
.
my_bind_text
(
s
.
stmt
,
i
,
cs
,
l
)
}
case
ZeroBlobLength
:
...
...
@@ -823,9 +819,6 @@ func (s *Stmt) ScanReflect(index int, v interface{}) (bool, error) {
return
isNull
,
err
}
// ScanNumericalAsTime tells the driver to try to parse column with NUMERIC affinity as time.Time (using the DefaultTimeLayout)
var
ScanNumericalAsTime
=
false
// ScanValue scans result value from a query.
// The leftmost column/index is number 0.
//
...
...
@@ -844,10 +837,10 @@ func (s *Stmt) ScanValue(index int, blob bool) (interface{}, bool) {
case
Null
:
return
nil
,
true
case
Text
:
// does not work as expected if column type affinity is TEXT but inserted value was a numeric
if
ScanNumericalAsTime
&&
s
.
ColumnTypeAffinity
(
index
)
==
Numerical
{
if
s
.
c
.
ScanNumericalAsTime
&&
s
.
ColumnTypeAffinity
(
index
)
==
Numerical
{
p
:=
C
.
sqlite3_column_text
(
s
.
stmt
,
C
.
int
(
index
))
txt
:=
C
.
GoString
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
)))
value
,
err
:=
time
.
Parse
(
DefaultTimeLayout
,
txt
)
value
,
err
:=
time
.
Parse
(
s
.
c
.
DefaultTimeLayout
,
txt
)
if
err
==
nil
{
return
value
,
false
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment