Example #1
0
File: conn.go Project: houcy/mysql
// Toggles autocommit mode on/off
func (conn *Connection) Autocommit(mode bool) error {
	m := C.my_bool(0)
	if mode {
		m = C.my_bool(1)
	}
	if C.my_autocommit(&conn.c, m) != 0 {
		return conn.lastError("")
	}
	return nil
}
Example #2
0
//设置SQL语句执行完后,是否自动提交事务,
//成功返回0, 否则返回errnum
func (mysql *MySQL) SetAutoCommit(mode bool) (errnum int) {
	f := C.my_bool(0)
	if mode {
		f = C.my_bool(1)
	}
	f = C.mysql_autocommit(mysql.my, f)
	mysql.errno = 5
	if f == C.my_bool(0) {
		mysql.errno = 0
	}

	return mysql.errno
}
Example #3
0
//提交一个事务,
//成功返回0, 否则返回errnum
func (mysql *MySQL) Commit() (errnum int) {
	f := C.mysql_commit(mysql.my)
	mysql.errno = 5
	if f == C.my_bool(0) {
		mysql.errno = 0
	}
	return mysql.errno
}
Example #4
0
File: stmt.go Project: houcy/mysql
package mysql

/*
#include "cgo.h"
*/
import "C"
import "unsafe"

var (
	c_TRUE  = C.my_bool(1)
	c_FALSE = C.my_bool(0)
)

// Prepared statement.
type Stmt struct {
	conn     *Connection
	s        C.MY_STMT
	sql      string
	binds    []C.MYSQL_BIND
	bind_pos int
}

// Prepare a statement.
func (conn *Connection) Prepare(sql string) (*Stmt, error) {
	stmt := &Stmt{}
	stmt.conn = conn
	stmt.sql = sql

	if C.my_prepare(&stmt.s, &conn.c, (*C.char)(stringPointer(sql)), C.ulong(len(sql))) != 0 {
		return nil, conn.lastError(sql)
	}