tried to use the
[goDBhammer.git] / src / dbibridge.go
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