A collection of tables stored in an SQLite or MySQL database. If the database does not exist, creates it. If the host, user or password is wrong, raises DatabaseConnectionError.
(self, name, host="localhost", port=3306, username="root", password="", type=SQLITE, unicode=True, **kwargs)
| 404 | return dict.__getitem__(self, k) |
| 405 | |
| 406 | def __init__(self, name, host="localhost", port=3306, username="root", password="", type=SQLITE, unicode=True, **kwargs): |
| 407 | """ A collection of tables stored in an SQLite or MySQL database. |
| 408 | If the database does not exist, creates it. |
| 409 | If the host, user or password is wrong, raises DatabaseConnectionError. |
| 410 | """ |
| 411 | _import_db(type) |
| 412 | self.type = type |
| 413 | self.name = name |
| 414 | self.host = host |
| 415 | self.port = port |
| 416 | self.username = kwargs.get("user", username) |
| 417 | self.password = password |
| 418 | self._connection = None |
| 419 | self.connect(unicode) |
| 420 | # Table names are available in the Database.tables dictionary, |
| 421 | # table objects as attributes (e.g. Database.table_name). |
| 422 | q = self.type==SQLITE and "select name from sqlite_master where type='table';" or "show tables;" |
| 423 | self.tables = Database.Tables(self) |
| 424 | for name, in self.execute(q): |
| 425 | if not name.startswith(("sqlite_",)): |
| 426 | self.tables[name] = None |
| 427 | # The SQL syntax of the last query is kept in cache. |
| 428 | self._query = None |
| 429 | # Persistent relations between tables, stored as (table1, table2, key1, key2, join) tuples. |
| 430 | self.relations = [] |
| 431 | |
| 432 | def connect(self, unicode=True): |
| 433 | # Connections for threaded applications work differently, |
nothing calls this directly
no test coverage detected