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
c4bfbe45
Commit
c4bfbe45
authored
Feb 22, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add shortcut methods to invoke some pragmas.
parent
b5cfeaf5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
28 deletions
+91
-28
meta.go
meta.go
+2
-2
pragma.go
pragma.go
+57
-0
pragma_test.go
pragma_test.go
+32
-0
sqlite.go
sqlite.go
+0
-20
sqlite_test.go
sqlite_test.go
+0
-6
No files found.
meta.go
View file @
c4bfbe45
...
...
@@ -142,7 +142,7 @@ type ForeignKey struct {
}
// Executes pragma 'foreign_key_list'
// TODO
How to specify a database-name?
// TODO
Make possible to specify the database-name (PRAGMA %Q.foreign_key_list(%Q))
func
(
c
*
Conn
)
ForeignKeys
(
table
string
)
(
map
[
int
]
*
ForeignKey
,
error
)
{
s
,
err
:=
c
.
Prepare
(
Mprintf
(
"PRAGMA foreign_key_list(%Q)"
,
table
))
if
err
!=
nil
{
...
...
@@ -179,7 +179,7 @@ type Index struct {
}
// Executes pragma 'index_list'
// TODO
How to specify a database-name?
// TODO
Make possible to specify the database-name (PRAGMA %Q.index_list(%Q))
func
(
c
*
Conn
)
Indexes
(
table
string
)
([]
Index
,
error
)
{
s
,
err
:=
c
.
Prepare
(
Mprintf
(
"PRAGMA index_list(%Q)"
,
table
))
if
err
!=
nil
{
...
...
pragma.go
0 → 100644
View file @
c4bfbe45
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
sqlite
import
(
"fmt"
)
// Check database integrity
// (See http://www.sqlite.org/pragma.html#pragma_integrity_check
// and http://www.sqlite.org/pragma.html#pragma_quick_check)
// TODO Make possible to specify the database-name (PRAGMA %Q.integrity_check(.))
func
(
c
*
Conn
)
IntegrityCheck
(
max
int
,
quick
bool
)
error
{
var
pragma
string
if
quick
{
pragma
=
"quick"
}
else
{
pragma
=
"integrity"
}
msg
,
err
:=
c
.
OneValue
(
fmt
.
Sprintf
(
"PRAGMA %s_check(%d)"
,
pragma
,
max
))
if
err
!=
nil
{
return
err
}
if
msg
!=
"ok"
{
return
c
.
specificError
(
"Integrity check failed (%s)"
,
msg
)
}
return
nil
}
// Returns the text encoding used by the main database
// (See http://sqlite.org/pragma.html#pragma_encoding)
// TODO Make possible to specify the database-name (PRAGMA %Q.encoding)
func
(
c
*
Conn
)
Encoding
()
(
string
,
error
)
{
value
,
err
:=
c
.
OneValue
(
"PRAGMA encoding"
)
if
err
!=
nil
{
return
""
,
err
}
if
encoding
,
ok
:=
value
.
(
string
);
ok
{
return
encoding
,
nil
}
return
""
,
c
.
specificError
(
"Unexpected encoding (%v)"
,
value
)
}
// (See http://sqlite.org/pragma.html#pragma_schema_version)
// TODO Make possible to specify the database-name (PRAGMA %Q.schema_version)
func
(
c
*
Conn
)
SchemaVersion
()
(
int64
,
error
)
{
value
,
err
:=
c
.
OneValue
(
"PRAGMA schema_version"
)
if
err
!=
nil
{
return
-
1
,
err
}
if
version
,
ok
:=
value
.
(
int64
);
ok
{
return
version
,
nil
}
return
-
1
,
c
.
specificError
(
"Unexpected version (%v)"
,
value
)
}
\ No newline at end of file
pragma_test.go
0 → 100644
View file @
c4bfbe45
package
sqlite_test
import
(
// . "github.com/gwenn/gosqlite"
"testing"
)
func
TestIntegrityCheck
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
checkNoError
(
t
,
db
.
IntegrityCheck
(
1
,
true
),
"Error checking integrity of database: %s"
)
}
func
TestEncoding
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
encoding
,
err
:=
db
.
Encoding
()
checkNoError
(
t
,
err
,
"Error reading encoding of database: %s"
)
if
encoding
!=
"UTF-8"
{
t
.
Errorf
(
"Expecting %s but got %s"
,
"UTF-8"
,
encoding
)
}
}
func
TestSchemaVersion
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
version
,
err
:=
db
.
SchemaVersion
()
checkNoError
(
t
,
err
,
"Error reading schema version of database: %s"
)
if
version
!=
0
{
t
.
Errorf
(
"Expecting %d but got %d"
,
0
,
version
)
}
}
sqlite.go
View file @
c4bfbe45
...
...
@@ -1286,26 +1286,6 @@ func EnableSharedCache(b bool) {
C
.
sqlite3_enable_shared_cache
(
btocint
(
b
))
}
// Check database integrity
// (See http://www.sqlite.org/pragma.html#pragma_integrity_check
// and http://www.sqlite.org/pragma.html#pragma_quick_check)
func
(
c
*
Conn
)
IntegrityCheck
(
max
int
,
quick
bool
)
error
{
var
pragma
string
if
quick
{
pragma
=
"quick"
}
else
{
pragma
=
"integrity"
}
msg
,
err
:=
c
.
OneValue
(
fmt
.
Sprintf
(
"PRAGMA %s_check(%d)"
,
pragma
,
max
))
if
err
!=
nil
{
return
err
}
if
msg
!=
"ok"
{
return
c
.
specificError
(
"Integrity check failed (%s)"
,
msg
)
}
return
nil
}
// Must is a helper that wraps a call to a function returning (bool, os.Error)
// and panics if the error is non-nil.
func
Must
(
b
bool
,
err
error
)
bool
{
...
...
sqlite_test.go
View file @
c4bfbe45
...
...
@@ -60,12 +60,6 @@ func TestEnableExtendedResultCodes(t *testing.T) {
checkNoError
(
t
,
db
.
EnableExtendedResultCodes
(
true
),
"cannot enabled extended result codes: %s"
)
}
func
TestIntegrityCheck
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
checkNoError
(
t
,
db
.
IntegrityCheck
(
1
,
true
),
"Error checking integrity of database: %s"
)
}
func
TestCreateTable
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
...
...
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