Package ais :: Module sqlhelp :: Class create
[hide private]
[frames] | no frames]

Class create

source code

Helper for building create SQL commands.

FIX: add type checking - what did I mean by this???


To Do: FIX - add a remove command to nuke a field

Instance Methods [hide private]
 
__init__(self, table, dbType='postgres')
Kick it off with no fields
source code
 
add(self, field, typeStr)
Unchecked field.
source code
 
addPrimaryKey(self, keyName='key')
Add a primary key based on the field name.
source code
 
addInt(self, field)
SQL integer field
source code
 
addReal(self, field)
SQL floating point field
source code
 
addVarChar(self, field, length)
SQL VARCHAR field...
source code
 
addBool(self, field)
SQL Boolean field
source code
 
addBitVarying(self, field, length)
SQL Boolean field
source code
 
addDecimal(self, field, precision=5, scale=0) source code
 
addTimestamp(self, field)
SQL TIMESTAMP field
source code
 
addPostGIS(self, field, typeName, dimension, SRID='-1')
Add a spatial column to the table using the OpenGIS AddGeometryColumn function using current schema:
source code
str
__str__(self)
Return the SQL string for the table creation
source code
Method Details [hide private]

__init__(self, table, dbType='postgres')
(Constructor)

source code 

Kick it off with no fields

table - which table are we going to insert into

add(self, field, typeStr)

source code 

Unchecked field. Provide the field and type all in one. Use this if nothing matches what you need.

e.g.: create.add('corenumber','INTEGER') create.add('username','VARCHAR(40)') create.add('id','INTEGER PRIMARY KEY')
Parameters:
  • field - name of the field
  • typeStr - the type of field

To Do: Allow setting of primary key in a simple way

addPrimaryKey(self, keyName='key')

source code 
Add a primary key based on the field name.

To Do: FIX: complain if trying to add a second primary key

addInt(self, field)

source code 
SQL integer field
Parameters:
  • field - name of the field

addReal(self, field)

source code 
SQL floating point field
Parameters:
  • field - name of the field

addVarChar(self, field, length)

source code 
SQL VARCHAR field... variable length up to a max size
Parameters:
  • field - name of the field
  • length - max length of the field

addBool(self, field)

source code 
SQL Boolean field
Parameters:
  • field - name of the field

addBitVarying(self, field, length)

source code 
SQL Boolean field
Parameters:
  • field - name of the field
  • length - largest possible size

addDecimal(self, field, precision=5, scale=0)

source code 
Parameters:
  • precision - overall digits including to right of decimal
  • scale - number of digits to the right of decimal

addTimestamp(self, field)

source code 
SQL TIMESTAMP field
Parameters:
  • field - name of the field

addPostGIS(self, field, typeName, dimension, SRID='-1')

source code 

Add a spatial column to the table using the OpenGIS AddGeometryColumn function using current schema:

AddGeometryColumn(<table_name>,<column_name>, <srid>, <type>, <dimension>)
Parameters:
  • field (str) - Name of the field in the db table
  • typeName (str) - OpenGIS geometry type (e.g. POINT)
  • dimension (int) - x,y would be 2
  • SRID (int) - spatial referencing system identifier (FIX: give some more info!)