當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。