sqlite: load column headers
This commit is contained in:
parent
6234f02ea6
commit
91f9c5fc30
11
bolt.go
11
bolt.go
@ -9,6 +9,7 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/ying32/govcl/vcl"
|
"github.com/ying32/govcl/vcl"
|
||||||
|
"github.com/ying32/govcl/vcl/types"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,6 +47,16 @@ func (ld *boltLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) {
|
|||||||
f.contentBox.SetEnabled(false)
|
f.contentBox.SetEnabled(false)
|
||||||
f.contentBox.Clear()
|
f.contentBox.Clear()
|
||||||
|
|
||||||
|
// Bolt always uses Key + Value as the columns
|
||||||
|
|
||||||
|
f.contentBox.Columns().Clear()
|
||||||
|
colKey := f.contentBox.Columns().Add()
|
||||||
|
colKey.SetCaption("Key")
|
||||||
|
colKey.SetWidth(MY_WIDTH)
|
||||||
|
colKey.SetAlignment(types.TaLeftJustify)
|
||||||
|
colVal := f.contentBox.Columns().Add()
|
||||||
|
colVal.SetCaption("Value")
|
||||||
|
|
||||||
err := ld.db.View(func(tx *bbolt.Tx) error {
|
err := ld.db.View(func(tx *bbolt.Tx) error {
|
||||||
b := boltTargetBucket(tx, ndata.bucketPath)
|
b := boltTargetBucket(tx, ndata.bucketPath)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
|
16
main.go
16
main.go
@ -12,6 +12,11 @@ import (
|
|||||||
"github.com/ying32/govcl/vcl/types"
|
"github.com/ying32/govcl/vcl/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MY_SPACING = 6
|
||||||
|
MY_WIDTH = 180
|
||||||
|
)
|
||||||
|
|
||||||
type TMainForm struct {
|
type TMainForm struct {
|
||||||
*vcl.TForm
|
*vcl.TForm
|
||||||
|
|
||||||
@ -34,9 +39,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
|
func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
|
||||||
const MY_SPACING = 6
|
|
||||||
const MY_WIDTH = 180
|
|
||||||
|
|
||||||
f.ImageList = loadImages(f)
|
f.ImageList = loadImages(f)
|
||||||
|
|
||||||
f.SetCaption("yvbolt")
|
f.SetCaption("yvbolt")
|
||||||
@ -118,13 +120,7 @@ func (f *TMainForm) OnFormCreate(sender vcl.IObject) {
|
|||||||
f.contentBox.SetViewStyle(types.VsReport) // "Report style" i.e. has columns
|
f.contentBox.SetViewStyle(types.VsReport) // "Report style" i.e. has columns
|
||||||
f.contentBox.SetAutoWidthLastColumn(true)
|
f.contentBox.SetAutoWidthLastColumn(true)
|
||||||
f.contentBox.SetReadOnly(true)
|
f.contentBox.SetReadOnly(true)
|
||||||
colKey := f.contentBox.Columns().Add()
|
f.contentBox.Columns().Clear()
|
||||||
colKey.SetCaption("Key")
|
|
||||||
colKey.SetWidth(MY_WIDTH)
|
|
||||||
colKey.SetAlignment(types.TaLeftJustify)
|
|
||||||
colVal := f.contentBox.Columns().Add()
|
|
||||||
colVal.SetCaption("Value")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TMainForm) OnMnuFileOpenClick(sender vcl.IObject) {
|
func (f *TMainForm) OnMnuFileOpenClick(sender vcl.IObject) {
|
||||||
|
41
sqlite.go
41
sqlite.go
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/ying32/govcl/vcl"
|
"github.com/ying32/govcl/vcl"
|
||||||
|
"github.com/ying32/govcl/vcl/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -64,13 +65,45 @@ func (ld *sqliteLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) {
|
|||||||
// Display table properties
|
// Display table properties
|
||||||
f.propertiesBox.SetText(fmt.Sprintf("Selected table %q\n\nSchema:\n\n%s", tableName, schemaStmt))
|
f.propertiesBox.SetText(fmt.Sprintf("Selected table %q\n\nSchema:\n\n%s", tableName, schemaStmt))
|
||||||
|
|
||||||
// Load column details
|
|
||||||
ld.db.Query(`pragma table_info(?)`, tableName)
|
|
||||||
|
|
||||||
// Select * with small limit
|
|
||||||
f.contentBox.SetEnabled(false)
|
f.contentBox.SetEnabled(false)
|
||||||
f.contentBox.Clear()
|
f.contentBox.Clear()
|
||||||
|
|
||||||
|
// Load column details
|
||||||
|
// Use SELECT form instead of common PRAGMA table_info so we can just get names
|
||||||
|
colr, err := ld.db.Query(`SELECT name FROM pragma_table_info(?)`, tableName)
|
||||||
|
if err != nil {
|
||||||
|
vcl.ShowMessageFmt("Failed to load columns for table %q: %s", tableName, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer colr.Close()
|
||||||
|
|
||||||
|
f.contentBox.Columns().Clear()
|
||||||
|
for colr.Next() {
|
||||||
|
|
||||||
|
var columnName string
|
||||||
|
err = colr.Scan(&columnName)
|
||||||
|
if err != nil {
|
||||||
|
vcl.ShowMessageFmt("Failed to read column names for table %q: %s", tableName, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
col := f.contentBox.Columns().Add()
|
||||||
|
col.SetCaption(columnName)
|
||||||
|
col.SetWidth(MY_WIDTH)
|
||||||
|
col.SetAlignment(types.TaLeftJustify)
|
||||||
|
}
|
||||||
|
if colr.Err() != nil {
|
||||||
|
vcl.ShowMessageFmt("Failed to load columns for table %q: %s", tableName, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
colr.Close() // will be double-closed
|
||||||
|
|
||||||
|
// Select * with small limit
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// We successfully populated the data grid
|
||||||
|
f.contentBox.SetEnabled(true)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// ??? unknown
|
// ??? unknown
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user