Skip to content
Permalink
Browse files

[DB_Manager GPKG] Fix creating and changing default values of columns

  • Loading branch information
rouault committed Oct 24, 2016
1 parent f84826d commit 794c8f3c85ff2415f10b9fb6640ff5be908dd4e4
Showing with 21 additions and 1 deletion.
  1. +21 −1 python/plugins/db_manager/db_plugins/gpkg/connector.py
@@ -505,12 +505,30 @@ def createOGRFieldDefnFromSQL(self, sql_fielddef):
quoted_name = f_split[0]
name = self.unquoteId(quoted_name)
sql_type = f_split[1].upper()
if len(f_split) >= 3 and f_split[2].startswith('(') and f_split[2].endswith(')'):
sql_type += ' ' + f_split[2]
f_split = [f for f in f_split[3:]]
else:
f_split = [f for f in f_split[2:]]
ogr_type, ogr_subtype, width = self.getOGRFieldTypeFromSQL(sql_type)
fld_defn = ogr.FieldDefn(name, ogr_type)
fld_defn.SetSubType(ogr_subtype)
fld_defn.SetWidth(width)
if len(f_split) >= 4 and f_split[2] == 'NOT' and f_split[3] == 'NULL':
if len(f_split) >= 2 and f_split[0] == 'NOT' and f_split[1] == 'NULL':
fld_defn.SetNullable(False)
f_split = [f for f in f_split[2:]]
elif len(f_split) >= 1:
f_split = [f for f in f_split[1:]]
if len(f_split) >= 2 and f_split[0] == 'DEFAULT':
new_default = f_split[1]
if new_default == '':
fld_defn.SetDefault(None)
elif new_default == 'NULL' or ogr_type in (ogr.OFTInteger, ogr.OFTReal):
fld_defn.SetDefault(new_default)
elif new_default.startswith("'") and new_default.endswith("'"):
fld_defn.SetDefault(new_default)
else:
fld_defn.SetDefault(self.quoteString(new_default))
return fld_defn

def createTable(self, table, field_defs, pkey):
@@ -641,6 +659,8 @@ def updateTableColumn(self, table, column, new_name, new_data_type=None, new_not
new_fielddefn.SetDefault(None)
elif new_default == 'NULL' or ogr_type in (ogr.OFTInteger, ogr.OFTReal):
new_fielddefn.SetDefault(str(new_default))
elif new_default.startswith("'") and new_default.endswith("'"):
new_fielddefn.SetDefault(str(new_default))
else:
new_fielddefn.SetDefault(self.quoteString(new_default))
else:

0 comments on commit 794c8f3

Please sign in to comment.