当前位置: 首页>>代码示例>>Golang>>正文


Golang sqlite.Conn类代码示例

本文整理汇总了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
}
开发者ID:ardekantur,项目名称:flow.go,代码行数:26,代码来源:db.go

示例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.');"))
}
开发者ID:ardekantur,项目名称:flow.go,代码行数:9,代码来源:db.go

示例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
}
开发者ID:ardekantur,项目名称:flow.go,代码行数:9,代码来源:db.go

示例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
}
开发者ID:ardekantur,项目名称:flow.go,代码行数:10,代码来源:db.go

示例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
}
开发者ID:robfig,项目名称:goto,代码行数:12,代码来源:gotoserver.go

示例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()
}
开发者ID:gnuvince,项目名称:profbot,代码行数:12,代码来源:db.go

示例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()
}
开发者ID:gnuvince,项目名称:profbot,代码行数:17,代码来源:db.go

示例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))
}
开发者ID:ardekantur,项目名称:flow.go,代码行数:22,代码来源:db.go


注:本文中的gosqlite/googlecode/com/hg/sqlite.Conn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。