Beispiel #1
0
func (s *stmt) Query(args []driver.Value) (driver.Rows, error) {
	if s.closed {
		panic("database/sql/driver: misuse of sqlite driver: Query after Close")
	}
	if s.rows {
		panic("database/sql/driver: misuse of sqlite driver: Query with active Rows")
	}

	err := s.start(args)
	if err != nil {
		return nil, err
	}

	s.rows = true
	if s.colnames == nil {
		n := int64(C.sqlite3_column_count(s.stmt))
		s.colnames = make([]string, n)
		s.coltypes = make([]string, n)
		for i := range s.colnames {
			s.colnames[i] = C.GoString(C.sqlite3_column_name(s.stmt, C.int(i)))
			s.coltypes[i] = strings.ToLower(C.GoString(C.sqlite3_column_decltype(s.stmt, C.int(i))))
		}
	}
	return &rows{s}, nil
}
Beispiel #2
0
// ColumnName returns the name of the Nth column of the result set returned by the SQL statement. (not cached)
// The leftmost column is number 0.
// (See http://sqlite.org/c3ref/column_name.html)
func (s *Stmt) ColumnName(index int) string {
	if index < 0 || index >= s.ColumnCount() {
		panic(fmt.Sprintf("column index %d out of range [0,%d[.", index, s.ColumnCount()))
	}
	// If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next.
	return C.GoString(C.sqlite3_column_name(s.stmt, C.int(index)))
}
Beispiel #3
0
func (rows Rows) Columns() []string {
	count := int(C.sqlite3_column_count(rows.stmt))
	cols := make([]string, count)
	for i := 0; i < count; i++ {
		cols[i] = C.GoString(C.sqlite3_column_name(rows.stmt, C.int(i)))
	}
	return cols
}
Beispiel #4
0
// Return column names.
func (rc *SQLiteRows) Columns() []string {
	if rc.nc != len(rc.cols) {
		rc.cols = make([]string, rc.nc)
		for i := 0; i < rc.nc; i++ {
			rc.cols[i] = C.GoString(C.sqlite3_column_name(rc.s.s, C.int(i)))
		}
	}
	return rc.cols
}
Beispiel #5
0
// Columns returns the names of columns produced by the prepared statement.
// [http://www.sqlite.org/c3ref/column_name.html]
func (s *Stmt) Columns() []string {
	if len(s.colNames) != s.nCols {
		names := resize(s.colNames, s.nCols)
		for i, old := range names {
			new := goStr(C.sqlite3_column_name(s.stmt, C.int(i)))
			if old != new {
				names[i] = raw(new).Copy()
			}
		}
		s.colNames = names
	}
	return s.colNames
}
Beispiel #6
0
func ScanAsMap(stmnt *Stmt) (map[string]string, error) {
	temp_result := make([]string, Columns(stmnt))
	addrs := make([]interface{}, Columns(stmnt))
	for i := range temp_result {
		addrs[i] = &temp_result[i]
	}
	err := stmnt.Scan(addrs...)
	if err != nil {
		return nil, err
	}
	result := map[string]string{}
	for i, v := range temp_result {
		result[C.GoString(C.sqlite3_column_name(stmnt.stmt, C.int(i)))] = v
	}
	return result, nil
}
Beispiel #7
0
func (c ResultColumn) Name(s *Statement) string {
	return C.GoString(C.sqlite3_column_name(s.cptr, C.int(c)))
}
Beispiel #8
0
func (s *Statement) ColumnName(column int) (name string) {
	cname := C.sqlite3_column_name(s.cptr, C.int(column))
	name = C.GoString(cname)
	return
}
Beispiel #9
0
// ColumnName returns the name of the Nth column of the result set returned by the SQL statement. (not cached)
// The leftmost column is number 0.
// (See http://sqlite.org/c3ref/column_name.html)
func (s *Stmt) ColumnName(index int) string {
	// If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next.
	return C.GoString(C.sqlite3_column_name(s.stmt, C.int(index)))
}
Beispiel #10
0
func (s *Stmt) ColumnName(n int) string {
	return C.GoString(C.sqlite3_column_name(s.stmt, C.int(n)))
}