Revision 3074
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
165 | 165 |
self.log_debug = log_debug |
166 | 166 |
self.debug = log_debug != log_debug_none |
167 | 167 |
self.debug_temp = debug_temp |
168 |
self.autoanalyze = False |
|
168 | 169 |
|
169 | 170 |
self.__db = None |
170 | 171 |
self.query_results = {} |
... | ... | |
727 | 728 |
|
728 | 729 |
return query |
729 | 730 |
|
730 |
def insert_select(db, *args, **kw_args): |
|
731 |
def insert_select(db, table, *args, **kw_args):
|
|
731 | 732 |
'''For params, see mk_insert_select() and run_query_into() |
732 | 733 |
@param into sql_gen.Table with suggested name of temp table to put RETURNING |
733 | 734 |
values in |
... | ... | |
739 | 740 |
cacheable = kw_args.pop('cacheable', True) |
740 | 741 |
log_level = kw_args.pop('log_level', 2) |
741 | 742 |
|
742 |
return run_query_into(db, mk_insert_select(db, *args, **kw_args), into, |
|
743 |
recover=recover, cacheable=cacheable, log_level=log_level) |
|
743 |
cur = run_query_into(db, mk_insert_select(db, table, *args, **kw_args), |
|
744 |
into, recover=recover, cacheable=cacheable, log_level=log_level) |
|
745 |
autoanalyze(db, table) |
|
746 |
return cur |
|
744 | 747 |
|
745 | 748 |
default = sql_gen.default # tells insert() to use the default value for a column |
746 | 749 |
|
... | ... | |
788 | 791 |
|
789 | 792 |
return query |
790 | 793 |
|
791 |
def update(db, *args, **kw_args): |
|
794 |
def update(db, table, *args, **kw_args):
|
|
792 | 795 |
'''For params, see mk_update() and run_query()''' |
793 | 796 |
recover = kw_args.pop('recover', None) |
794 | 797 |
cacheable = kw_args.pop('cacheable', False) |
795 | 798 |
log_level = kw_args.pop('log_level', 2) |
796 | 799 |
|
797 |
return run_query(db, mk_update(db, *args, **kw_args), recover, cacheable, |
|
798 |
log_level=log_level) |
|
800 |
cur = run_query(db, mk_update(db, table, *args, **kw_args), recover, |
|
801 |
cacheable, log_level=log_level) |
|
802 |
autoanalyze(db, table) |
|
803 |
return cur |
|
799 | 804 |
|
800 | 805 |
def last_insert_id(db): |
801 | 806 |
module = util.root_module(db.db) |
... | ... | |
1223 | 1228 |
table = sql_gen.as_Table(table) |
1224 | 1229 |
run_query(db, 'ANALYZE '+table.to_str(db), log_level=3) |
1225 | 1230 |
|
1231 |
def autoanalyze(db, table): |
|
1232 |
if db.autoanalyze: analyze(db, table) |
|
1233 |
|
|
1226 | 1234 |
def vacuum(db, table): |
1227 | 1235 |
table = sql_gen.as_Table(table) |
1228 | 1236 |
db.with_autocommit(lambda: run_query(db, 'VACUUM ANALYZE '+table.to_str(db), |
Also available in: Unified diff
sql.py: DbConn: Added autoanalyze mode. Added autoanalyze() which runs analyze() only if in autoanalyze mode. Use new autoanalyze() in functions that change a table's contents.