MCPcopy Index your code
hub / github.com/clips/pattern / create

Method create

pattern/db/__init__.py:600–618  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 8

setupMethod · 0.80
parse_xmlFunction · 0.80
test_escapeMethod · 0.80
test_create_tableMethod · 0.80
setUpMethod · 0.80
setUpMethod · 0.80
test_xmlMethod · 0.80
01-database.pyFile · 0.80

Calls 5

_field_SQLMethod · 0.95
executeMethod · 0.95
zipFunction · 0.85
parse_xmlFunction · 0.70
getMethod · 0.45

Tested by 5

test_escapeMethod · 0.64
test_create_tableMethod · 0.64
setUpMethod · 0.64
setUpMethod · 0.64
test_xmlMethod · 0.64