tried to use the
authorPaul J R <me@pjr.cc>
Fri, 13 Nov 2009 16:40:54 +0000 (03:40 +1100)
committerPaul J R <me@pjr.cc>
Fri, 13 Nov 2009 16:40:54 +0000 (03:40 +1100)
package.var.function() syntax with very little joy... quite odd.

src/dbibridge.8 [deleted file]
src/dbibridge.go
src/dbibridge.go.or [deleted file]
src/makeit [changed mode: 0755->0644]
src/webconnector.go

diff --git a/src/dbibridge.8 b/src/dbibridge.8
deleted file mode 100644 (file)
index b7d3036..0000000
Binary files a/src/dbibridge.8 and /dev/null differ
index 7f0bcf8..0b9b97a 100644 (file)
@@ -1,8 +1,51 @@
 package dbibridge
 
-import "fmt"
+// #include <stdio.h>
+// #include <dbi/dbi.h>
+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 (file)
index 0d5bad4..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-package dbibridge
-
-// #include <stdio.h>
-// #include <dbi/dbi.h>
-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));
-       
-       
-        
-}
old mode 100755 (executable)
new mode 100644 (file)
index cd40c77..fbcd8fc
@@ -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
index 546341d..5fe61aa 100644 (file)
@@ -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())
+       //}
 
 }