| 830 | self._update() |
| 831 | |
| 832 | def _update(self): |
| 833 | # Retrieve table column names. |
| 834 | # Table column names are available in the Table.fields list. |
| 835 | # Table column names should not contain unicode because they can also be function parameters. |
| 836 | # Table column names should avoid " ", ".", "(" and ")". |
| 837 | # The primary key column is stored in Table.primary_key. |
| 838 | self.fields = Table.Fields(self) |
| 839 | if self.name not in self.database.tables: |
| 840 | raise TableError, "table '%s' does not exist" % (self.database.name + "." + self.name) |
| 841 | if self.db.type == MYSQL: |
| 842 | q = "show columns from `%s`;" % self.name |
| 843 | if self.db.type == SQLITE: |
| 844 | q = "pragma table_info(`%s`);" % self.name |
| 845 | i = self.db.execute("pragma index_list(`%s`)" % self.name) # look up indices |
| 846 | i = dict(((v[1].replace(self.name+"_", "", 1), v[2]) for v in i)) |
| 847 | for f in self.db.execute(q): |
| 848 | # [name, type, default, index, optional, extra] |
| 849 | if self.db.type == MYSQL: |
| 850 | f = [f[0], f[1], f[4], f[3], f[2], f[5]] |
| 851 | if self.db.type == SQLITE: |
| 852 | f = [f[1], f[2], f[4], f[5], f[3], ""] |
| 853 | f[3] = f[3] == 1 and "pri" or (f[0] in i and ("1","uni")[int(i[f[0]])] or "") |
| 854 | list.append(self.fields, f[0]) |
| 855 | self.schema[f[0]] = Schema(*f) |
| 856 | if self.schema[f[0]].index == PRIMARY: |
| 857 | self.primary_key = f[0] |
| 858 | |
| 859 | def _get_name(self): |
| 860 | return self._name |