From: Paul J R Date: Fri, 13 Nov 2009 16:40:54 +0000 (+1100) Subject: tried to use the X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=52618e1a8ebd86ebb31b7109a65cfd5f6f82bf53;p=goDBhammer.git tried to use the package.var.function() syntax with very little joy... quite odd. --- diff --git a/src/dbibridge.8 b/src/dbibridge.8 deleted file mode 100644 index b7d3036..0000000 Binary files a/src/dbibridge.8 and /dev/null differ diff --git a/src/dbibridge.go b/src/dbibridge.go index 7f0bcf8..0b9b97a 100644 --- a/src/dbibridge.go +++ b/src/dbibridge.go @@ -1,8 +1,51 @@ package dbibridge -import "fmt" +// #include +// #include +import "C" -func dbiconnect() +import ( + "unsafe"; +) + +type DBConnection struct { + dbconn C.dbi_conn; + dbinit bool; +} + +func DBICreate()(connection *DBConnection) +{ + var dbCon *DBConnection; + + dbCon = new(DBConnection); + dbCon.dbinit = false; + + return dbCon; +} + +//func (thisDBConn *DBConnection)DBIConnect(dbtype string, host string, username string, password string, database string) +// for some reason, the above doesnt work how i'd expect.. +func DBIConnect(thisDBConn *DBConnection, dbtype string, host string, username string, password string, database string) { - fmt.Printf("Hello, world\n"); + C.dbi_initialize(nil); + + thisDBConn.dbconn = C.dbi_conn_new(C.CString(dbtype)); + + C.dbi_conn_set_option((unsafe.Pointer)(thisDBConn.dbconn), C.CString("host"), C.CString(host)); + C.dbi_conn_set_option((unsafe.Pointer)(thisDBConn.dbconn), C.CString("username"), C.CString(username)); + C.dbi_conn_set_option((unsafe.Pointer)(thisDBConn.dbconn), C.CString("password"), C.CString(password)); + C.dbi_conn_set_option((unsafe.Pointer)(thisDBConn.dbconn), C.CString("dbname"), C.CString(database)); + C.dbi_conn_connect((unsafe.Pointer)(thisDBConn.dbconn)); + + thisDBConn.dbinit = true; } + +func ExecSQL(thisDBConn *DBConnection, SQL string) +{ + C.dbi_conn_query((unsafe.Pointer)(thisDBConn.dbconn), C.CString(SQL)); +} + +func DBIDisconnect(thisDBConn *DBConnection) +{ + C.dbi_conn_close((unsafe.Pointer)(thisDBConn.dbconn)); +} \ No newline at end of file diff --git a/src/dbibridge.go.or b/src/dbibridge.go.or deleted file mode 100644 index 0d5bad4..0000000 --- a/src/dbibridge.go.or +++ /dev/null @@ -1,28 +0,0 @@ -package dbibridge - -// #include -// #include -import "C" - -import ( - "unsafe"; -) - -func dbiconnect() -{ - - C.dbi_initialize(nil); - - myVar := C.dbi_conn_new(C.CString("mysql")); - - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("host"), C.CString("localhost")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("username"), C.CString("your_name")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("username"), C.CString("your_name")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("password"), C.CString("your_password")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("dbname"), C.CString("your_dbname")); - C.dbi_conn_set_option((unsafe.Pointer)(myVar), C.CString("encoding"), C.CString("UTF-8")); - C.dbi_conn_connect((unsafe.Pointer)(myVar)); - - - -} diff --git a/src/makeit b/src/makeit old mode 100755 new mode 100644 index cd40c77..fbcd8fc --- a/src/makeit +++ b/src/makeit @@ -6,10 +6,10 @@ cgo dbibridge.go gopack grc dbibridge.a _dbibridge_.8 dbibridge.cgo3.8 #cp dbibridge.a /export/src/external/golang//pkg/linux_386/dbibridge.a gcc -m32 -fPIC -O2 -o dbibridge.cgo4.o -c dbibridge.cgo4.c -gcc -m32 -shared -lpthread -lm -o dbibridge.so dbibridge.cgo4.o -#cp dbibridge.so /export/src/external/golang//pkg/linux_386/./dbibridge.so +gcc -m32 -shared -lpthread -lm -ldbi -o dbibridge.so dbibridge.cgo4.o +cp dbibridge.so /export/src/external/golang//pkg/linux_386/./dbibridge_dbibridge.so 8g -I. webconnector.go -8l webconnector.8 +8l -L. webconnector.8 diff --git a/src/webconnector.go b/src/webconnector.go index 546341d..5fe61aa 100644 --- a/src/webconnector.go +++ b/src/webconnector.go @@ -15,11 +15,18 @@ func HelloServer(c *http.Conn, req *http.Request) { } func main() { - dbibridge.dbiconnect(); - http.Handle("/hello", http.HandlerFunc(HelloServer)); - err := http.ListenAndServe(":12345", nil); - if err != nil { - panic("ListenAndServe: ", err.String()) - } + + var Dbconn *dbibridge.DBConnection; + + Dbconn = dbibridge.DBICreate(); + + dbibridge.DBIConnect(Dbconn, "mysql", "localhost", "root", "password", "zm"); + dbibridge.ExecSQL(Dbconn, "create table asdf (asdf int)"); + dbibridge.DBIDisconnect(Dbconn); + //http.Handle("/hello", http.HandlerFunc(HelloServer)); + //err := http.ListenAndServe(":12345", nil); + //if err != nil { + ////panic("ListenAndServe: ", err.String()) + //} }