|
1 | | -#$Id: back_mysql.py,v 1.61 2006-01-13 00:05:46 richard Exp $ |
| 1 | +#$Id: back_mysql.py,v 1.62 2006-01-13 01:18:06 richard Exp $ |
2 | 2 | # |
3 | 3 | # Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <[email protected]> |
4 | 4 | # |
@@ -379,6 +379,38 @@ def create_class_table(self, spec, create_sequence=1): |
379 | 379 | self.create_class_table_indexes(spec) |
380 | 380 | return cols, mls |
381 | 381 |
|
| 382 | + def create_class_table_indexes(self, spec): |
| 383 | + ''' create the class table for the given spec |
| 384 | + ''' |
| 385 | + # create __retired__ index |
| 386 | + index_sql2 = 'create index _%s_retired_idx on _%s(__retired__)'%( |
| 387 | + spec.classname, spec.classname) |
| 388 | + self.sql(index_sql2) |
| 389 | + |
| 390 | + # create index for key property |
| 391 | + if spec.key: |
| 392 | + if isinstance(spec.properties[spec.key], String): |
| 393 | + idx = spec.key + '(255)' |
| 394 | + else: |
| 395 | + idx = spec.key |
| 396 | + index_sql3 = 'create index _%s_%s_idx on _%s(_%s)'%( |
| 397 | + spec.classname, spec.key, |
| 398 | + spec.classname, idx) |
| 399 | + self.sql(index_sql3) |
| 400 | + |
| 401 | + # TODO: create indexes on (selected?) Link property columns, as |
| 402 | + # they're more likely to be used for lookup |
| 403 | + |
| 404 | + def create_class_table_key_index(self, cn, key): |
| 405 | + ''' create the class table for the given spec |
| 406 | + ''' |
| 407 | + prop = self.classes[cn].getprops()[key] |
| 408 | + if isinstance(prop, String): |
| 409 | + sql = 'create index _%s_%s_idx on _%s(_%s(255))'%(cn, key, cn, key) |
| 410 | + else: |
| 411 | + sql = 'create index _%s_%s_idx on _%s(_%s)'%(cn, key, cn, key) |
| 412 | + self.sql(sql) |
| 413 | + |
382 | 414 | def drop_class_table_indexes(self, cn, key): |
383 | 415 | # drop the old table indexes first |
384 | 416 | l = ['_%s_id_idx'%cn, '_%s_retired_idx'%cn] |
@@ -492,6 +524,14 @@ def sql_commit(self): |
492 | 524 | self.sql("SET AUTOCOMMIT=0") |
493 | 525 | self.sql("START TRANSACTION") |
494 | 526 |
|
| 527 | + def sql_close(self): |
| 528 | + logging.getLogger('hyperdb').info('close') |
| 529 | + try: |
| 530 | + self.conn.close() |
| 531 | + except MySQLdb.ProgrammingError, message: |
| 532 | + if str(message) != 'closing a closed connection': |
| 533 | + raise |
| 534 | + |
495 | 535 | class MysqlClass: |
496 | 536 | # we're overriding this method for ONE missing bit of functionality. |
497 | 537 | # look for "I can't believe it's not a toy RDBMS" below |
|
0 commit comments