示例#1
0
func DoAdminQueryStmnt(db *sqlx.DB, params url.Values) (interface{}, error) {
	stmt := params.Get("stmt")
	res := make(map[string]interface{})

	log.Println("DoAdminExecStmnt:", stmt)
	rows, err := db.Queryx(stmt)
	if err != nil {
		return nil, err
	}
	info, err := RowsDump(rows)
	//log.Println(info)

	res["result"] = info
	return res, err
}
示例#2
0
func DoAdminExecStmnt(db *sqlx.DB, params url.Values) (interface{}, error) {
	stmt := params.Get("stmt")
	res := make(map[string]interface{})

	log.Println("DoAdminExecStmnt:", stmt)
	sqres, err := db.Exec(stmt)
	if err != nil {
		return nil, err
	}
	i, _ := sqres.LastInsertId()
	a, _ := sqres.RowsAffected()

	res["LastInsertId"] = i
	res["RowsAffected"] = a
	log.Println(res)
	return res, nil
}
示例#3
0
func DoAdminGetTblList(db *sqlx.DB, params url.Values) (interface{}, error) {
	res := make(map[string]interface{})
	tbls := make([]string, 1)
	tbls[0] = "sqlite_master"

	cmd := "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name"
	rows, err := db.Queryx(cmd)
	if err != nil {
		return nil, err
	}
	for rows.Next() {
		var name string
		err = rows.Scan(&name)
		//log.Println(">>>>>>>>>>>>>>", name)
		tbls = append(tbls, name)
	}

	res["tbls"] = tbls
	return res, nil
}
示例#4
0
func DoAdminGetTblInfo(db *sqlx.DB, params url.Values) (interface{}, error) {
	res := make(map[string]interface{})
	tableName := params.Get("table")

	cmd := "PRAGMA table_info(" + tableName + ")"
	rows, err := db.Queryx(cmd)
	if err != nil {
		return nil, err
	}
	info, err := RowsDump(rows)
	//log.Println(info)

	cmd = "SELECT count(*) FROM " + tableName
	rows, err = db.Queryx(cmd)
	count, err := RowsDump(rows)
	//log.Println(count)

	res["info"] = info
	res["count"] = count
	return res, err
}