stuck with a bitch of a problem
[goDBhammer.git] / src / dbibridge.go
index 0b9b97a..fe26e60 100644 (file)
@@ -6,46 +6,50 @@ import "C"
 
 import (
        "unsafe";
+       "fmt";
 )
 
-type DBConnection struct {
-       dbconn C.dbi_conn;
+type DBIConnection struct {
+       dbconn unsafe.Pointer;
        dbinit bool;
 }
 
-func DBICreate()(connection *DBConnection)
+func DBICreate()(connection *DBIConnection)
 {
-       var dbCon *DBConnection;
+       var dbCon *DBIConnection;
        
-       dbCon = new(DBConnection);
+       dbCon = new(DBIConnection);
        dbCon.dbinit = false;
        
        return dbCon;
 }
 
-//func (thisDBConn *DBConnection)DBIConnect(dbtype string, host string, username string, password string, database string)
+//func (thisDBConn *DBIConnection)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)
+func DBIConnect(thisDBConn *DBIConnection, dbtype string, host string, username string, password string, database string)
 {
        C.dbi_initialize(nil);
        
-       thisDBConn.dbconn = C.dbi_conn_new(C.CString(dbtype));
+       thisDBConn.dbconn = (unsafe.Pointer)(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));
+       C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("host"), C.CString(host));
+       C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("username"), C.CString(username));
+       C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("password"), C.CString(password));
+       C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("dbname"), C.CString(database));
+       C.dbi_conn_connect(thisDBConn.dbconn);
        
        thisDBConn.dbinit = true;
 }
 
-func ExecSQL(thisDBConn *DBConnection, SQL string)
+func ExecSQL(thisDBConn *DBIConnection, SQL string)
 {
-       C.dbi_conn_query((unsafe.Pointer)(thisDBConn.dbconn), C.CString(SQL));
+       fmt.Printf("%s;\n", SQL);
+       res := C.dbi_conn_query(thisDBConn.dbconn, C.CString(SQL));
+       
+       C.dbi_result_free((unsafe.Pointer)(res));
 }
 
-func DBIDisconnect(thisDBConn *DBConnection)
+func DBIDisconnect(thisDBConn *DBIConnection)
 {
-       C.dbi_conn_close((unsafe.Pointer)(thisDBConn.dbconn));
+       C.dbi_conn_close(thisDBConn.dbconn);
 }
\ No newline at end of file