MCPcopy Index your code
hub / github.com/webpy/webpy / query

Method query

web/db.py:793–826  ·  view source on GitHub ↗

Execute SQL query `sql_query` using dictionary `vars` to interpolate it. If `processed=True`, `vars` is a `reparam`-style list to use instead of interpolating. >>> db = DB(None, {}) >>> db.query("SELECT * FROM foo", _test=True) <sql: 'SEL

(self, sql_query, vars=None, processed=False, _test=False)

Source from the content-addressed store, hash-verified

791 return None
792
793 def query(self, sql_query, vars=None, processed=False, _test=False):
794 """
795 Execute SQL query `sql_query` using dictionary `vars` to interpolate it.
796 If `processed=True`, `vars` is a `reparam`-style list to use
797 instead of interpolating.
798
799 >>> db = DB(None, {})
800 >>> db.query("SELECT * FROM foo", _test=True)
801 <sql: 'SELECT * FROM foo'>
802 >>> db.query("SELECT * FROM foo WHERE x = $x", vars=dict(x='f'), _test=True)
803 <sql: "SELECT * FROM foo WHERE x = 'f'">
804 >>> db.query("SELECT * FROM foo WHERE x = " + sqlquote('f'), _test=True)
805 <sql: "SELECT * FROM foo WHERE x = 'f'">
806 """
807 if vars is None:
808 vars = {}
809
810 if not processed and not isinstance(sql_query, SQLQuery):
811 sql_query = reparam(sql_query, vars)
812
813 if _test:
814 return sql_query
815
816 db_cursor = self._db_cursor()
817 self._db_execute(db_cursor, sql_query)
818
819 if db_cursor.description:
820 out = self.create_result_set(db_cursor)
821 else:
822 out = db_cursor.rowcount
823
824 if not self.ctx.transactions:
825 self.ctx.commit()
826 return out
827
828 def create_result_set(self, cursor):
829 return ResultSet(cursor)

Callers 13

selectMethod · 0.95
make_sessionMethod · 0.45
setUpMethod · 0.45
tearDownMethod · 0.45
test_multiple_insertMethod · 0.45
setUpMethod · 0.45
tearDownMethod · 0.45
test_insert_returningMethod · 0.45
setUpMethod · 0.45
setUpMethod · 0.45
_process_queryMethod · 0.45
_get_all_sequencesMethod · 0.45

Calls 5

_db_cursorMethod · 0.95
_db_executeMethod · 0.95
create_result_setMethod · 0.95
reparamFunction · 0.85
commitMethod · 0.45

Tested by 9

make_sessionMethod · 0.36
setUpMethod · 0.36
tearDownMethod · 0.36
test_multiple_insertMethod · 0.36
setUpMethod · 0.36
tearDownMethod · 0.36
test_insert_returningMethod · 0.36
setUpMethod · 0.36
setUpMethod · 0.36