4 // #include <dbi/dbi.h>
13 type DBIConnection struct {
14 dbconn unsafe.Pointer;
18 func DBICreate()(connection *DBIConnection)
20 var dbCon *DBIConnection;
22 dbCon = new(DBIConnection);
28 //func (thisDBConn *DBIConnection)DBIConnect(dbtype string, host string, username string, password string, database string)
29 // for some reason, the above doesnt work how i'd expect..
30 func DBIConnect(thisDBConn *DBIConnection, dbtype string, host string, username string, password string, database string)
32 C.dbi_initialize(nil);
34 thisDBConn.dbconn = (unsafe.Pointer)(C.dbi_conn_new(C.CString(dbtype)));
36 C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("host"), C.CString(host));
37 C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("username"), C.CString(username));
38 C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("password"), C.CString(password));
39 C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("dbname"), C.CString(database));
40 C.dbi_conn_set_option(thisDBConn.dbconn, C.CString("encoding"), C.CString("UTF-8"));
41 C.dbi_conn_connect(thisDBConn.dbconn);
43 thisDBConn.dbinit = true;
46 func ExecSQL(thisDBConn *DBIConnection, SQL string)
48 //fmt.Printf("%s;\n", SQL);
49 res := C.dbi_conn_query(thisDBConn.dbconn, C.CString(SQL));
51 C.dbi_result_free((unsafe.Pointer)(res));
54 func DBIDisconnect(thisDBConn *DBIConnection)
56 C.dbi_conn_close(thisDBConn.dbconn);