Skip to content

Commit

Permalink
Merge branch 'fixes/issue10' into main - fix mysql connectionstring
Browse files Browse the repository at this point in the history
  • Loading branch information
timabell committed Jan 28, 2024
2 parents e59b769 + f54f0c1 commit e5b366d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
20 changes: 19 additions & 1 deletion mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,11 @@ func buildQuery(table *schema.Table, params *params.TableParams, peekFinder *dri
func (model mysqlModel) getColumns(dbc *sql.DB, table *schema.Table) (cols []*schema.Column, err error) {
// todo: parameterise
// todo: read all tables' columns in one query hit
sql := fmt.Sprintf("select column_name, data_type, is_nullable, character_maximum_length from information_schema.columns where table_schema = '%s' and table_name='%s' order by ordinal_position;", opts.Database, table.Name)
dbname := opts.Database
if dbname == "" {
dbname, _ = model.getSelectedDatabase(dbc)
}
sql := fmt.Sprintf("select column_name, data_type, is_nullable, character_maximum_length from information_schema.columns where table_schema = '%s' and table_name='%s' order by ordinal_position;", dbname, table.Name)

rows, err := dbc.Query(sql)
if err != nil {
Expand Down Expand Up @@ -584,3 +588,17 @@ func (model mysqlModel) SetTableDescription(database string, table string, descr
func (model mysqlModel) SetColumnDescription(database string, table string, column string, description string) (err error) {
return
}

func (model mysqlModel) getSelectedDatabase(dbc *sql.DB) (name string, err error) {
sql := "SELECT DATABASE();"
rows, err := dbc.Query(sql)
if err != nil {
log.Print(sql)
return
}
defer rows.Close()
for rows.Next() {
rows.Scan(&name)
}
return
}
15 changes: 15 additions & 0 deletions mysql/test-mysql-connectionstring.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -e

echo "======================"
echo "mysql connectionstring"
echo "======================"

./setup.sh

cd ..
export schemaexplorer_driver=mysql
export schemaexplorer_live=false
export schemaexplorer_mysql_connection_string="ssetestusr:ssetestusrpass@tcp(localhost:3306)/ssetest"
go clean -testcache
go test sse_test.go #-test.v
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ popd > /dev/null
pushd . > /dev/null
cd mysql
./test-mysql.sh
./test-mysql-connectionstring.sh
popd > /dev/null

pushd . > /dev/null
Expand Down

0 comments on commit e5b366d

Please sign in to comment.