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

Method _field_SQL

pattern/db/__init__.py:578–598  ·  view source on GitHub ↗
(self, table, field)

Source from the content-addressed store, hash-verified

576 blob = binary
577
578 def _field_SQL(self, table, field):
579 # Returns a (field, index)-tuple with SQL strings for the given field().
580 # The field string can be used in a CREATE TABLE or ALTER TABLE statement.
581 # The index string is an optional CREATE INDEX statement (or None).
582 auto = " auto%sincrement" % (self.type == MYSQL and "_" or "")
583 field = list(field) + [STRING, None, False, True][len(field)-1:]
584 field = list(_field(field[0], field[1], default=field[2], index=field[3], optional=field[4]))
585 if field[1] == "timestamp" and field[2] == "now":
586 field[2] = "current_timestamp"
587 a = b = None
588 a = "`%s` %s%s%s%s" % (
589 # '`id` integer not null primary key auto_increment'
590 field[0],
591 field[1] == STRING and field[1]() or field[1],
592 field[4] is False and " not null" or " null",
593 field[2] is not None and " default %s" % self.escape(field[2]) or "",
594 field[3] == PRIMARY and " primary key%s" % ("", auto)[field[1]==INTEGER] or "")
595 if field[3] in (UNIQUE, True):
596 b = "create %sindex `%s_%s` on `%s` (`%s`);" % (
597 field[3] == UNIQUE and "unique " or "", table, field[0], table, field[0])
598 return a, b
599
600 def create(self, table, fields=[], encoding="utf-8", **kwargs):
601 """ Creates a new table with the given fields.

Callers 3

createMethod · 0.95
appendMethod · 0.80
test_create_tableMethod · 0.80

Calls 2

escapeMethod · 0.95
lenFunction · 0.85

Tested by 1

test_create_tableMethod · 0.64