本文整理汇总了Golang中gosqlite/googlecode/com/hg/sqlite.Conn类的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conn类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Get
func Get(conn *sqlite.Conn, kind interface{}, id string) interface{} {
result := reflect.NewValue(kind)
tableType := reflect.Typeof(kind).(*reflect.StructType)
numColumns := tableType.NumField()
schemaArray := make([]string, numColumns)
things := make([]interface{}, numColumns)
_ = unsafe.Unreflect
for i := 0; i < numColumns; i++ {
name := tableType.Field(i).Name
schemaArray[i] = strings.ToLower(name)
field := result.(*reflect.StructValue).Field(i)
k := field.Interface()
things[i] = k
fmt.Printf("%v.", k)
}
str := "SELECT " + strings.Join(schemaArray, ", ") + " FROM " + tableType.Name() + " WHERE id = ?"
stmt, _ := conn.Prepare(str)
HandleError(stmt.Exec(id))
if stmt.Next() {
HandleError(stmt.Scan(things...))
}
return result
}
示例2: SetupForum
func SetupForum(conn *sqlite.Conn) {
for i := 0; i < len(ForumsTables); i++ {
createTable(conn, "", ForumsTables[i])
}
for i := 0; i < len(UsersTables); i++ {
createTable(conn, "users", UsersTables[i])
}
HandleError(conn.Exec("INSERT INTO main.forum (name, desc) VALUES ('Main Forum', 'This is the main forum.');"))
}
示例3: GetForum
func GetForum(conn *sqlite.Conn, id string) Forum {
stmt, _ := conn.Prepare("SELECT id, name, desc FROM main.forum WHERE id = ?;")
var f Forum
HandleError(stmt.Exec(id))
if stmt.Next() {
HandleError(stmt.Scan(&f.Id, &f.Name, &f.Desc))
}
return f
}
示例4: TablesExist
func TablesExist(conn *sqlite.Conn) bool {
stmt, _ := conn.Prepare("SELECT COUNT(*) FROM sqlite_master WHERE type='table';")
r := 0
for stmt.Next() {
stmt.Scan(&r)
}
return r != 0
}
示例5: doLookup
/** This function performs the db lookup. */
func doLookup(c *sqlite.Conn, key string) (url string) {
stmt, err := c.Prepare("select url from redirects where key = ?")
if err != nil {
panic(err.String())
}
defer stmt.Finalize()
stmt.Exec(key)
stmt.Next()
stmt.Scan(&url)
return
}
示例6: TableExists
func TableExists(conn *sqlite.Conn, tableName string) bool {
stmt, err := conn.Prepare(
"select 1 from sqlite_master where type = ? and tbl_name = ?")
defer stmt.Finalize()
if err != nil {
log.Println("sql error: " + err.String())
return false
}
stmt.Exec("table", tableName)
return stmt.Next()
}
示例7: CreateTable
func CreateTable(conn *sqlite.Conn, tableName string, columns ...string) {
if len(columns) == 0 {
return
}
parameter_list := strings.Join(columns, ", ")
query := fmt.Sprintf("create table %s (%s)", tableName, parameter_list)
stmt, err := conn.Prepare(query)
defer stmt.Finalize()
if err != nil {
log.Fatalf("Cannot create table %s; %s (%s)\n", tableName, err, query)
}
stmt.Exec()
stmt.Next()
}
示例8: createTable
func createTable(conn *sqlite.Conn, dbName string, schemaDefinition interface{}) {
schemaString := ""
forumType := reflect.Typeof(schemaDefinition).(*reflect.StructType)
numColumns := forumType.NumField()
schemaArray := make([]string, numColumns)
for i := 0; i < numColumns; i++ {
schemaArray[i] = strings.ToLower(forumType.Field(i).Name) +
" " + strings.ToUpper(forumType.Field(i).Tag)
}
schemaString = strings.Join(schemaArray, ", ")
if dbName == "" {
dbName = "main"
}
dbName = dbName + "." + forumType.Name()
schemaString = "CREATE TABLE " + strings.ToLower(dbName) +
" (" + schemaString + ");"
HandleError(conn.Exec(schemaString))
}