Fix postgres errors.
This commit is contained in:
@@ -86,8 +86,6 @@ class Database(object):
|
||||
Enter a transaction explicitly.
|
||||
|
||||
No data will be written until the transaction has been committed.
|
||||
**NOTICE:** Schema modification operations, such as the creation
|
||||
of tables or columns will not be part of the transactional context.
|
||||
"""
|
||||
if not hasattr(self.local, 'tx'):
|
||||
self.local.tx = []
|
||||
@@ -179,6 +177,9 @@ class Database(object):
|
||||
assert not isinstance(primary_type, six.string_types), \
|
||||
'Text-based primary_type support is dropped, use db.types.'
|
||||
table_name = self._valid_table_name(table_name)
|
||||
table = self._reflect_table(table_name)
|
||||
if table is not None:
|
||||
return Table(self, table)
|
||||
self._acquire()
|
||||
try:
|
||||
log.debug("Creating table: %s" % (table_name))
|
||||
@@ -192,7 +193,7 @@ class Database(object):
|
||||
primary_key=True,
|
||||
autoincrement=autoincrement)
|
||||
table.append_column(col)
|
||||
table.create(self.executable)
|
||||
table.create(self.executable, checkfirst=True)
|
||||
return Table(self, table)
|
||||
finally:
|
||||
self._release()
|
||||
@@ -222,7 +223,8 @@ class Database(object):
|
||||
return SQLATable(table_name,
|
||||
self.metadata,
|
||||
schema=self.schema,
|
||||
autoload=True)
|
||||
autoload=True,
|
||||
autoload_with=self.executable)
|
||||
except NoSuchTableError:
|
||||
return None
|
||||
|
||||
@@ -242,9 +244,6 @@ class Database(object):
|
||||
table = db['population']
|
||||
|
||||
"""
|
||||
table = self._reflect_table(table_name)
|
||||
if table is not None:
|
||||
return Table(self, table)
|
||||
return self.create_table(table_name, primary_id, primary_type)
|
||||
|
||||
def __getitem__(self, table_name):
|
||||
|
||||
@@ -30,10 +30,6 @@ class Table(object):
|
||||
"""Get a listing of all columns that exist in the table."""
|
||||
return list(self.table.columns.keys())
|
||||
|
||||
@property
|
||||
def _normalized_columns(self):
|
||||
return map(normalize_column_name, self.columns)
|
||||
|
||||
def drop(self):
|
||||
"""
|
||||
Drop the table from the database.
|
||||
@@ -46,13 +42,13 @@ class Table(object):
|
||||
self._check_dropped()
|
||||
self.database._acquire()
|
||||
try:
|
||||
self._is_dropped = True
|
||||
self.table.drop(self.database.executable)
|
||||
self.table.drop(self.database.executable, checkfirst=True)
|
||||
self.table = None
|
||||
finally:
|
||||
self.database._release()
|
||||
|
||||
def _check_dropped(self):
|
||||
if self._is_dropped:
|
||||
if self.table is None:
|
||||
raise DatasetException('the table has been dropped. this object should not be used again.')
|
||||
|
||||
def _prune_row(self, row):
|
||||
@@ -60,7 +56,7 @@ class Table(object):
|
||||
# normalize keys
|
||||
row = {normalize_column_name(k): v for k, v in row.items()}
|
||||
# filter out keys not in column set
|
||||
return {k: row[k] for k in row if k in self._normalized_columns}
|
||||
return {k: row[k] for k in row if k in self.columns}
|
||||
|
||||
def insert(self, row, ensure=None, types=None):
|
||||
"""
|
||||
@@ -261,7 +257,7 @@ class Table(object):
|
||||
return rows.rowcount > 0
|
||||
|
||||
def _has_column(self, column):
|
||||
return normalize_column_name(column) in self._normalized_columns
|
||||
return normalize_column_name(column) in self.columns
|
||||
|
||||
def _ensure_columns(self, row, types=None):
|
||||
# Keep order of inserted columns
|
||||
@@ -303,7 +299,8 @@ class Table(object):
|
||||
self._check_dropped()
|
||||
self.database._acquire()
|
||||
try:
|
||||
if normalize_column_name(name) in self._normalized_columns:
|
||||
name = normalize_column_name(name)
|
||||
if name in self.columns:
|
||||
log.debug("Column exists: %s" % name)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user