本文整理汇总了Golang中C.sqlite3_bind_parameter_name函数的典型用法代码示例。如果您正苦于以下问题:Golang sqlite3_bind_parameter_name函数的具体用法?Golang sqlite3_bind_parameter_name怎么用?Golang sqlite3_bind_parameter_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sqlite3_bind_parameter_name函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Prepare
// Prepare query string. Return a new statement.
func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) {
pquery := C.CString(query)
defer C.free(unsafe.Pointer(pquery))
var s *C.sqlite3_stmt
var tail *C.char
rv := C.sqlite3_prepare_v2(c.db, pquery, -1, &s, &tail)
if rv != C.SQLITE_OK {
return nil, c.lastError()
}
var t string
if tail != nil && *tail != '\000' {
t = strings.TrimSpace(C.GoString(tail))
}
nv := int(C.sqlite3_bind_parameter_count(s))
var nn []string
for i := 0; i < nv; i++ {
pn := C.GoString(C.sqlite3_bind_parameter_name(s, C.int(i+1)))
if len(pn) > 1 && pn[0] == '$' && 48 <= pn[1] && pn[1] <= 57 {
nn = append(nn, C.GoString(C.sqlite3_bind_parameter_name(s, C.int(i+1))))
}
}
ss := &SQLiteStmt{c: c, s: s, nv: nv, nn: nn, t: t}
runtime.SetFinalizer(ss, (*SQLiteStmt).Close)
return ss, nil
}
示例2: BindParameterName
// BindParameterName returns the name of a wildcard parameter (not cached).
// Returns "" if the index is out of range or if the wildcard is unnamed.
// The first host parameter has an index of 1, not 0.
// (See http://sqlite.org/c3ref/bind_parameter_name.html)
func (s *Stmt) BindParameterName(index int) (string, error) {
name := C.sqlite3_bind_parameter_name(s.stmt, C.int(index))
if name == nil {
return "", s.specificError("invalid parameter index: %d", index)
}
return C.GoString(name), nil
}
示例3: Params
// Params returns the names of bound parameters in the prepared statement. Nil
// is returned if the statement does not use named parameters.
// [http://www.sqlite.org/c3ref/bind_parameter_name.html]
func (s *Stmt) Params() []string {
if s.varNames == nil {
var names []string
for i := 0; i < s.nVars; i++ {
name := C.sqlite3_bind_parameter_name(s.stmt, C.int(i+1))
if name == nil {
names = unnamedVars
break
}
if names == nil {
names = make([]string, s.nVars)
}
names[i] = C.GoString(name)
}
s.varNames = names
}
if len(s.varNames) == 0 {
return nil // unnamedVars -> nil
}
return s.varNames
}