package dbibridge // #include // #include import "C" import ( "unsafe"; //"fmt"; //"strings"; ) type DBIConnection struct { dbconn unsafe.Pointer; dbinit bool; } func DBICreate()(connection *DBIConnection) { var dbCon *DBIConnection; dbCon = new(DBIConnection); dbCon.dbinit = false; return dbCon; } //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 *DBIConnection, dbtype string, host string, username string, password string, database string) { C.dbi_initialize(nil); thisDBConn.dbconn = (unsafe.Pointer)(C.dbi_conn_new(C.CString(dbtype))); 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_set_option(thisDBConn.dbconn, C.CString("encoding"), C.CString("UTF-8")); C.dbi_conn_connect(thisDBConn.dbconn); thisDBConn.dbinit = true; } func ExecSQL(thisDBConn *DBIConnection, SQL string) { //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 *DBIConnection) { C.dbi_conn_close(thisDBConn.dbconn); }