// Cideq calls the stored procedure 'pg_catalog.cideq(cid, cid) boolean' on db.
184913
func Cideq(db XODB, v0 pgtypes.Cid, v1 pgtypes.Cid) (bool, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.cideq($1, $2)`

	// run query
	var ret bool
	XOLog(sqlstr, v0, v1)
	err = db.QueryRow(sqlstr, v0, v1).Scan(&ret)
	if err != nil {
		return false, err
	}

	return ret, nil
}
1154334
func ToCQL(e *dosa.EntityDefinition) string {
	var buf bytes.Buffer
	// errors are ignored here, they can only happen from an invalid template, which will get caught in tests
	err := cqlCreateTableTemplate.Execute(&buf, e)
	if err != nil {
		panic(err)
	}
	return buf.String()
}
894681
func isValidSeq(names []string) bool {
	var lastSeq uint64
	for _, name := range names {
		curSeq, _, err := parseWalName(name)
		if err != nil {
			plog.Panicf("parse correct name should never fail: %v", err)
		}
		if lastSeq != 0 && lastSeq != curSeq-1 {
			return false
		}
		lastSeq = curSeq
	}
	return true
}
1252265
func (db *DB) Queryx(query string, args ...interface{}) (*Rows, error) {
	r, err := db.DB.Query(query, args...)
	if err != nil {
		return nil, err
	}
	return &Rows{Rows: r, unsafe: db.unsafe, Mapper: db.Mapper}, err
}
1030150
func (db *DB) addSeq(delta uint64) {
	atomic.AddUint64(&db.seq, delta)
}
314375
func (ss *SQLSubStore) addSeq(subid, seqno uint64) bool {
	ap := ss.getOrCreateAcksPending(subid, seqno)
	ap.msgs[seqno] = struct{}{}
	return len(ap.msgs) >= sqlMaxPendingAcks
}
389183
func (mr *MockCloudStemcellMockRecorder) CID() *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CID", reflect.TypeOf((*MockCloudStemcell)(nil).CID))
}
202022
func (b *backend) DB(ctx context.Context, s logical.Storage) (*sql.DB, error) {
	b.logger.Debug("postgres/db: enter")
	defer b.logger.Debug("postgres/db: exit")

	b.lock.Lock()
	defer b.lock.Unlock()

	// If we already have a DB, we got it!
	if b.db != nil {
		if err := b.db.Ping(); err == nil {
			return b.db, nil
		}
		// If the ping was unsuccessful, close it and ignore errors as we'll be
		// reestablishing anyways
		b.db.Close()
	}

	// Otherwise, attempt to make connection
	entry, err := s.Get(ctx, "config/connection")
	if err != nil {
		return nil, err
	}
	if entry == nil {
		return nil,
			fmt.Errorf("configure the DB connection with config/connection first")
	}

	var connConfig connectionConfig
	if err := entry.DecodeJSON(&connConfig); err != nil {
		return nil, err
	}

	conn := connConfig.ConnectionURL
	if len(conn) == 0 {
		conn = connConfig.ConnectionString
	}

	// Ensure timezone is set to UTC for all the connections
	if strings.HasPrefix(conn, "postgres://") || strings.HasPrefix(conn, "postgresql://") {
		if strings.Contains(conn, "?") {
			conn += "&timezone=utc"
		} else {
			conn += "?timezone=utc"
		}
	} else {
		conn += " timezone=utc"
	}

	b.db, err = sql.Open("postgres", conn)
	if err != nil {
		return nil, err
	}

	// Set some connection pool settings. We don't need much of this,
	// since the request rate shouldn't be high.
	b.db.SetMaxOpenConns(connConfig.MaxOpenConnections)
	b.db.SetMaxIdleConns(connConfig.MaxIdleConnections)

	return b.db, nil
}
1302097
func Oidvectoreq(db XODB, v0 pgtypes.Oidvector, v1 pgtypes.Oidvector) (bool, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.oidvectoreq($1, $2)`

	// run query
	var ret bool
	XOLog(sqlstr, v0, v1)
	err = db.QueryRow(sqlstr, v0, v1).Scan(&ret)
	if err != nil {
		return false, err
	}

	return ret, nil
}
222398
func (d DotSql) Exec(db Execer, name string, args ...interface{}) (sql.Result, error) {
	query, err := d.lookupQuery(name)
	if err != nil {
		return nil, err
	}

	return db.Exec(query, args...)
}
471037
func shapeEq(a, b []int) bool {
	if isScalar(a) && isScalar(b) {
		return true
	}

	if len(a) != len(b) {
		return false
	}

	for i, v := range a {
		if b[i] != v {
			return false
		}
	}
	return true
}
797444
func (c *Client) ExecQuery(query string) ([]byte, error) {
	req := Query(query)
	return c.Exec(req)
}
490282
func GtOrEqFunc(column string, fn *Func) Cmp {
	return Cmp{
		op:     geq,
		column: column,
		value:  fn,
	}
}
905356
func (r *RangeOp) GtOrEq(fieldName string, value interface{}) *RangeOp {
	r.appendOp(GtOrEq, fieldName, value)
	return r
}
1117274
func (s *propagateConstantSolver) propagateInEQ() {
	s.unionSet = &multiEqualSet{}
	s.unionSet.init(len(s.columns))
	for i := range s.conditions {
		if fun, ok := s.conditions[i].(*ScalarFunction); ok && fun.FuncName.L == ast.EQ {
			lCol, lOk := fun.GetArgs()[0].(*Column)
			rCol, rOk := fun.GetArgs()[1].(*Column)
			if lOk && rOk {
				lID := s.getColID(lCol)
				rID := s.getColID(rCol)
				s.unionSet.addRelation(lID, rID)
			}
		}
	}
	condsLen := len(s.conditions)
	for i := 0; i < condsLen; i++ {
		cond := s.conditions[i]
		col, con := s.validPropagateCond(cond, inEqFuncNameMap)
		if col == nil {
			continue
		}
		id := s.getColID(col)
		for j := range s.columns {
			if id != j && s.unionSet.findRoot(id) == s.unionSet.findRoot(j) {
				funName := cond.(*ScalarFunction).FuncName.L
				var newExpr Expression
				if _, ok := cond.(*ScalarFunction).GetArgs()[0].(*Column); ok {
					newExpr, _ = NewFunction(s.ctx, funName, cond.GetType(), s.columns[j], con)
				} else {
					newExpr, _ = NewFunction(s.ctx, funName, cond.GetType(), con, s.columns[j])
				}
				s.conditions = append(s.conditions, newExpr)
			}
		}
	}
}
1341756
func (b ValExprBuilder) Neq(val interface{}) BoolExprBuilder {
	return b.makeComparisonExpr(astNE, makeValExpr(val))
}
255425
func PgProcParams(db XODB, schema string, proc string) ([]*ProcParam, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`UNNEST(STRING_TO_ARRAY(oidvectortypes(p.proargtypes), ', ')) ` + // ::varchar AS param_type
		`FROM pg_proc p ` +
		`JOIN ONLY pg_namespace n ON p.pronamespace = n.oid ` +
		`WHERE n.nspname = $1 AND p.proname = $2`

	// run query
	XOLog(sqlstr, schema, proc)
	q, err := db.Query(sqlstr, schema, proc)
	if err != nil {
		return nil, err
	}
	defer q.Close()

	// load results
	res := []*ProcParam{}
	for q.Next() {
		pp := ProcParam{}

		// scan
		err = q.Scan(&pp.ParamType)
		if err != nil {
			return nil, err
		}

		res = append(res, &pp)
	}

	return res, nil
}