Creates a new table with the given fields. The given list of fields must contain values returned from the field() function.
(self, table, fields=[], encoding="utf-8", **kwargs)
| 598 | return a, b |
| 599 | |
| 600 | def create(self, table, fields=[], encoding="utf-8", **kwargs): |
| 601 | """ Creates a new table with the given fields. |
| 602 | The given list of fields must contain values returned from the field() function. |
| 603 | """ |
| 604 | if table in self.tables: |
| 605 | raise TableError, "table '%s' already exists" % (self.name + "." + table) |
| 606 | if table.startswith(XML_HEADER): |
| 607 | # From an XML-string generated with Table.xml. |
| 608 | return parse_xml(self, table, |
| 609 | table = kwargs.get("name"), |
| 610 | field = kwargs.get("field", lambda s: s.replace(".", "_"))) |
| 611 | encoding = self.type == MYSQL and " default charset=" + encoding.replace("utf-8", "utf8") or "" |
| 612 | fields, indices = zip(*[self._field_SQL(table, f) for f in fields]) |
| 613 | self.execute("create table `%s` (%s)%s;" % (table, ", ".join(fields), encoding)) |
| 614 | for index in indices: |
| 615 | if index is not None: |
| 616 | self.execute(index, commit=True) |
| 617 | self.tables[table] = None # lazy loading |
| 618 | return self.tables[table] |
| 619 | |
| 620 | def drop(self, table): |
| 621 | """ Removes the table with the given name. |