changed web interface to static files + json interface
[goDBhammer.git] / src / dbibridge.go
1 package dbibridge
2
3 // #include <stdio.h>
4 // #include <dbi/dbi.h>
5 import "C"
6
7 import (
8         "unsafe";
9         //"fmt";
10         //"strings";
11 )
12
13 type DBIConnection struct {
14         dbconn unsafe.Pointer;
15         dbinit bool;
16 }
17
18 func DBICreate()(connection *DBIConnection)
19 {
20         var dbCon *DBIConnection;
21         
22         dbCon = new(DBIConnection);
23         dbCon.dbinit = false;
24         
25         return dbCon;
26 }
27
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)
31 {
32         C.dbi_initialize(nil);
33         
34         thisDBConn.dbconn = (unsafe.Pointer)(C.dbi_conn_new(C.CString(dbtype)));
35         
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);
42         
43         thisDBConn.dbinit = true;
44 }
45
46 func ExecSQL(thisDBConn *DBIConnection, SQL string)
47 {
48         //fmt.Printf("%s;\n", SQL);
49         res := C.dbi_conn_query(thisDBConn.dbconn, C.CString(SQL));
50         
51         C.dbi_result_free((unsafe.Pointer)(res));
52 }
53
54 func DBIDisconnect(thisDBConn *DBIConnection)
55 {
56         C.dbi_conn_close(thisDBConn.dbconn);
57 }