Bug free, feature complete, uses Marco Bambinis nativ C SDK.
package main
import "cubesql"
import "fmt"
func main() {
cube := cubesql.New()
if cube.Connect( "dbhost", 4430, "loginname", "password", 10, 0 ) == cubesql.NOERR {
defer cube.Disconnect( 0 )
fmt.Printf( "PING... " )
if cube.Ping() == cubesql.ERR {
fmt.Printf( "ERROR %d (%s).\r\n", cube.ErrorCode(), cube.ErrorMessage() )
} else {
println( "SUCCESS." )
cube.Use( "demo" )
cube.AutoCommit( true )
cube.Execute( `CREATE TABLE IF NOT EXISTS "Friends" ("Name" TEXT PRIMARY KEY NOT NULL UNIQUE, "Birthday" DATE);` )
// Inserting values...
cube.Execute( `INSERT OR IGNORE INTO Friends VALUES ( "Buddy1", "1974-05-14" )` )
cube.Execute( fmt.Sprintf( `INSERT OR IGNORE INTO Friends VALUES ( "%s", "%s" )`, "Buddy2", "2009-01-14" ) )
var values []interface{}
cube.Bind( `INSERT OR IGNORE INTO Friends VALUES ( ?1, ?2 )`, append( values, "Buddy3", "2007-07-18" ) )
statement := cube.Prepare( `INSERT OR IGNORE INTO Friends VALUES ( ?1, ?2 )` )
statement.BindText( 1, "Buddy4" )
statement.BindText( 2, "1974-07-26" )
statement.Execute()
statement.Close()
result := cube.Select( "SELECT * FROM Friends;" )
defer result.Free()
fmt.Printf( "%d Rows with %d Coulmns found in Table 'Friends':\r\n", result.NumRows(), result.NumColumns() )
for col:= 1; col <= result.NumColumns(); col++ {
fmt.Printf( "Column %d: Name = %-10s, Type = %2d\r\n", col, result.GetField( cubesql.COLNAME, col ), result.ColumnType( col ) )
}
for {
fmt.Printf( "Row %02d: ", result.CurrentRow() )
for col:= 1; col <= result.NumColumns(); col++ {
fmt.Printf( "%s | ", result.String( cubesql.CURROW, col ) )
}
println( "" )
result.Seek( cubesql.SEEKNEXT )
if result.IsEOF() == cubesql.TRUE {
break
}
}
// More compact... (but wrong! - Do you know why? HINT: Free your mind to figuer it out ;-)
for result := cube.Select( "SELECT * FROM Friends ORDER BY Birthday;" ); result.IsEOF() == cubesql.FALSE; result.Seek( cubesql.SEEKNEXT ) {
println( result.String( cubesql.CURROW, 1 ) )
}
}
}
}- Set up your go development environment:
go env -w GO111MODULE=off
mkdir ~/MyProject
cd ~/MyProject
- Download CubeSQL.go
git clone https://github.com/andreaspfeil/CubeSQL.go.git- Enter CubeSQL.go directory and compile the native database driver
cd CubeSQL.go/src/cubesql/
make- Test the example programm:
cd ../..
export GOPATH=`pwd`
echo $GOPATH
cd src
go run .- Why does the example programm not work?
Make sure that your database is running and can be reached from your workstation. Also change your credentials in:
cube.Connect( "dbhost", 4430, "loginname", "password", 10, 0 ) and use the correct database:
cube.Use( "demo" )If you are interersted in how to install the CubeSQL.go driver on Windows, drop me a line.
- Windows Installer
- More handy methods
- Better Error handling
- Make a go module for even easier integration into your project
If you are interersted in any of this, drop me a line or please consider buying me a beer...
- Marco Bambini (Author of cubeSQL and the original nativ client SDK)
The BEER license is basically the same as the MIT license (see link), except that you should buy the author a beer (see Donate) if you use this software.
none yet - YOU can still be number one in this list!!!