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
  add(self, field, typeStr)
Unchecked field.
  addPrimaryKey(self, keyName='key')
Add a primary key based on the field name.
  addInt(self, field)
SQL integer field
  addReal(self, field)
SQL floating point field
  addVarChar(self, field, length)
SQL VARCHAR field...
  addBool(self, field)
SQL Boolean field
  addBitVarying(self, field, length)
SQL Boolean field
  addDecimal(self, field, precision=5, scale=0)
  addTimestamp(self, field)
SQL TIMESTAMP field
  addPostGIS(self, field, typeName, dimension, SRID='-1')
Add a spatial column to the table using the OpenGIS AddGeometryColumn function using current schema: AddGeometryColumn(<table_name>, <column_name>, <srid>, <type>, <dimension>) @param field: Name of the field in the db table @param typeName: OpenGIS geometry type (e.g.
str __str__(self)
Return the SQL string for the table creation

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.

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>)

@param field: Name of the field in the db table
@param typeName: OpenGIS geometry type (e.g. POINT)
@param dimension: x,y would be 2
@type dimension: int
@SRID: spatial referencing system identifier (FIX: give some more info!)

__str__(self)
(Informal representation operator)

source code 
Return the SQL string for the table creation
Returns: str