示例#1
0
func NewDb(file string) (*Db, error) {
	d, err := sqlx.Connect("sqlite3", file)
	if err != nil {
		fmt.Println("Error: ", err)
		return nil, err
	}
	r := &Db{
		File:   file,
		DB:     d,
		Tables: make([]*Table, 0),
	}

	//r.InitTable(DbMeta{})
	DbFileList = append(DbFileList, file)

	if Main == nil {
		Main = r
	}

	return r, nil
}
示例#2
0
func DoAdminRpc(params url.Values) (interface{}, error) {

	fn := params.Get("fn")
	if fn == "GetDBList" {
		return DoAdminGetDBList(params)
	}

	dbFile := params.Get("db")
	dbfIdx := -1
	for i := 0; i < len(DbFileList); i++ {
		if DbFileList[i] == dbFile {
			dbfIdx = i
			break
		}
	}
	if dbfIdx == -1 {
		return nil, errors.New("invalid db:" + dbFile)
	}
	db, err := sqlx.Connect("sqlite3", dbFile)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	if fn == "GetTblList" {
		return DoAdminGetTblList(db, params)
	}
	if fn == "GetTblInfo" {
		return DoAdminGetTblInfo(db, params)
	}
	if fn == "ExecStmnt" {
		return DoAdminExecStmnt(db, params)
	}
	if fn == "QueryStmnt" {
		return DoAdminQueryStmnt(db, params)
	}
	return nil, errors.New("invalid db.DoAdminRpc function")
}