package.var.function() syntax with very little joy... quite odd.
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
+++ /dev/null
-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));
-
-
-
-}
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
}
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())
+ //}
}