當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.SQLHSTMT函數代碼示例

本文整理匯總了Golang中C.SQLHSTMT函數的典型用法代碼示例。如果您正苦於以下問題:Golang SQLHSTMT函數的具體用法?Golang SQLHSTMT怎麽用?Golang SQLHSTMT使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了SQLHSTMT函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Execute

func (stmt *Statement) Execute(params ...interface{}) *ODBCError {
	if params != nil {
		var cParams C.SQLSMALLINT
		ret := C.SQLNumParams(C.SQLHSTMT(stmt.handle), &cParams)
		if !Success(ret) {
			err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
			return err
		}
		for i := 0; i < int(cParams); i++ {
			stmt.BindParam(i+1, params[i])
		}
	}
	ret := C.SQLExecute(C.SQLHSTMT(stmt.handle))
	if ret == C.SQL_NEED_DATA {
		// TODO
		//		send_data(stmt)
	} else if ret == C.SQL_NO_DATA {
		// Execute NO DATA
	} else if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		return err
	}
	stmt.executed = true
	return nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:25,代碼來源:odbc.go

示例2: FieldMetadata

func (stmt *Statement) FieldMetadata(col int) (*Field, *ODBCError) {
	var BufferLength C.SQLSMALLINT = INFO_BUFFER_LEN
	var NameLength C.SQLSMALLINT
	var DataType C.SQLSMALLINT
	var ColumnSize C.SQLULEN
	var DecimalDigits C.SQLSMALLINT
	var Nullable C.SQLSMALLINT
	ColumnName := make([]byte, INFO_BUFFER_LEN)
	ret := C.SQLDescribeCol(C.SQLHSTMT(stmt.handle),
		C.SQLUSMALLINT(col),
		(*C.SQLCHAR)(unsafe.Pointer(&ColumnName[0])),
		BufferLength,
		&NameLength,
		&DataType,
		&ColumnSize,
		&DecimalDigits,
		&Nullable)
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle, int(ret))
		debugPrint("SQLDescribeCol Error", err)
		return nil, err
	}
	field := &Field{string(ColumnName[0:NameLength]), int(DataType), int(ColumnSize), int(DecimalDigits), int(Nullable)}
	return field, nil
}
開發者ID:bwheatley,項目名稱:go-odbc,代碼行數:25,代碼來源:odbc.go

示例3: NextResult

func (stmt *Statement) NextResult() bool {
	ret := C.SQLMoreResults(C.SQLHSTMT(stmt.handle))
	if ret == C.SQL_NO_DATA {
		return false
	}
	return true
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:7,代碼來源:odbc.go

示例4: NumParams

func (stmt *Statement) NumParams() int {
	var cParams C.SQLSMALLINT
	ret := C.SQLNumParams(C.SQLHSTMT(stmt.handle), &cParams)
	if !Success(ret) {
		return -1
	}
	return int(cParams)
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:8,代碼來源:odbc.go

示例5: Cancel

func (stmt *Statement) Cancel() *ODBCError {
	ret := C.SQLCancel(C.SQLHSTMT(stmt.handle))
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		return err
	}
	return nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:8,代碼來源:odbc.go

示例6: NumFields

func (stmt *Statement) NumFields() (int, *ODBCError) {
	var NOC C.SQLSMALLINT
	ret := C.SQLNumResultCols(C.SQLHSTMT(stmt.handle), &NOC)
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		return -1, err
	}
	return int(NOC), nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:9,代碼來源:odbc.go

示例7: NumRows

func (stmt *Statement) NumRows() (int, *ODBCError) {
	var NOR C.SQLLEN
	ret := C.SQLRowCount(C.SQLHSTMT(stmt.handle), &NOR)
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		return -1, err
	}
	return int(NOR), nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:9,代碼來源:odbc.go

示例8: RowsAffected

func (stmt *Statement) RowsAffected() (int, *ODBCError) {
	var nor C.SQLLEN
	ret := C.SQLRowCount(C.SQLHSTMT(stmt.handle), &nor)
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		return -1, err
	}
	return int(nor), nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:9,代碼來源:odbc.go

示例9: GetParamType

func (stmt *Statement) GetParamType(index int) (int, int, int, int, *ODBCError) {
	var data_type, dec_ptr, null_ptr C.SQLSMALLINT
	var size_ptr C.SQLULEN
	ret := C.SQLDescribeParam(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(index), &data_type, &size_ptr, &dec_ptr, &null_ptr)
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		return -1, -1, -1, -1, err
	}
	return int(data_type), int(size_ptr), int(dec_ptr), int(null_ptr), nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:10,代碼來源:odbc.go

示例10: Fetch

func (stmt *Statement) Fetch() (bool, *ODBCError) {
	ret := C.SQLFetch(C.SQLHSTMT(stmt.handle))
	if ret == C.SQL_NO_DATA {
		return false, nil
	}
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		return false, err
	}
	return true, nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:11,代碼來源:odbc.go

示例11: ExecDirect

func (conn *Connection) ExecDirect(sql string) (stmt *Statement, err *ODBCError) {
	if stmt, err = conn.newStmt(); err != nil {
		return nil, err
	}
	wsql := StringToUTF16Ptr(sql)
	ret := C.SQLExecDirectW(C.SQLHSTMT(stmt.handle), (*C.SQLWCHAR)(unsafe.Pointer(wsql)), C.SQL_NTS)
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		stmt.Close()
		return nil, err
	}
	stmt.executed = true
	return stmt, nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:14,代碼來源:odbc.go

示例12: Prepare

func (conn *Connection) Prepare(sql string, params ...interface{}) (*Statement, *ODBCError) {
	wsql := StringToUTF16Ptr(sql)
	stmt, err := conn.newStmt()
	if err != nil {
		return nil, err
	}
	ret := C.SQLPrepareW(C.SQLHSTMT(stmt.handle), (*C.SQLWCHAR)(unsafe.Pointer(wsql)), C.SQLINTEGER(len(sql)))
	if !Success(ret) {
		err := FormatError(C.SQL_HANDLE_STMT, stmt.handle)
		stmt.Close()
		return nil, err
	}
	stmt.prepared = true
	return stmt, nil
}
開發者ID:andybalholm,項目名稱:go-odbc,代碼行數:15,代碼來源:odbc.go

示例13: GetField

func (stmt *Statement) GetField(field_index int) (v interface{}, ftype int, flen int, err *ODBCError) {
	var field_type C.SQLINTEGER
	var field_len C.SQLINTEGER
	var ll C.SQLSMALLINT
	ret := C.SQLColAttribute(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_DESC_CONCISE_TYPE, C.SQLPOINTER(unsafe.Pointer(uintptr(0))), C.SQLSMALLINT(0), &ll, &field_type)
	if !Success(ret) {
		debugPrint("GetFiled type Error")
	}
	ret = C.SQLColAttribute(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_DESC_LENGTH, C.SQLPOINTER(unsafe.Pointer(uintptr(0))), C.SQLSMALLINT(0), &ll, &field_len)
	if !Success(ret) {
		debugPrint("GetFiled len Error")
	}
	var fl C.SQLLEN = C.SQLLEN(field_len)
	switch int(field_type) {
	case C.SQL_BIT, C.SQL_INTEGER, C.SQL_SMALLINT, C.SQL_TINYINT:
		var value C.HANDLE
		ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_LONG, C.SQLPOINTER(unsafe.Pointer(&value)), 0, &fl)
		if fl == -1 {
			v = nil
		} else {
			v = value
		}
	case C.SQL_FLOAT, C.SQL_REAL:
		var value C.double
		ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_DOUBLE, C.SQLPOINTER(unsafe.Pointer(&value)), 0, &fl)
		if fl == -1 {
			v = nil
		} else {
			v = value
		}
	case C.SQL_WCHAR, C.SQL_WVARCHAR, C.SQL_WLONGVARCHAR:
		value := make([]uint16, int(field_len)+8)
		ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_WCHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLINTEGER(int(field_len)+4), &fl)
		s := UTF16ToString(value)
		v = s
	default:
		value := make([]byte, int(fl)+2)
		ret = C.SQLGetData(C.SQLHSTMT(stmt.handle), C.SQLUSMALLINT(field_index+1), C.SQL_C_CHAR, C.SQLPOINTER(unsafe.Pointer(&value[0])), C.SQLINTEGER(int(field_len)+4), &fl)
		s := string(value[0:])
		v = s
		debugPrint("default type", value, fl, s)
	}
	if !Success(ret) {
		err = FormatError(C.SQL_HANDLE_STMT, stmt.handle, int(ret))
		debugPrint("GetFiled Data Error", err)
	}
	return v, int(field_type), int(fl), err
}
開發者ID:bwheatley,項目名稱:go-odbc,代碼行數:48,代碼來源:odbc.go

示例14: SQLPrepare

func SQLPrepare(statementHandle SQLHSTMT, statementText *SQLWCHAR, textLength SQLINTEGER) (ret SQLRETURN) {
	r := C.SQLPrepareW(C.SQLHSTMT(statementHandle), (*C.SQLWCHAR)(unsafe.Pointer(statementText)), C.SQLINTEGER(textLength))
	return SQLRETURN(r)
}
開發者ID:dimbi,項目名稱:dashdb-test,代碼行數:4,代碼來源:zapi_unix.go

示例15: SQLNumParams

func SQLNumParams(statementHandle SQLHSTMT, parameterCountPtr *SQLSMALLINT) (ret SQLRETURN) {
	r := C.SQLNumParams(C.SQLHSTMT(statementHandle), (*C.SQLSMALLINT)(parameterCountPtr))
	return SQLRETURN(r)
}
開發者ID:dimbi,項目名稱:dashdb-test,代碼行數:4,代碼來源:zapi_unix.go


注:本文中的C.SQLHSTMT函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。