File: test/

Recommend this page to a friend!
  Classes of Nikos M.  >  Dialect PHP SQL Query Builder  >  test/  >  Download  
File: test/
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Dialect PHP SQL Query Builder
Build SQL queries from templates
Author: By
Last change: Update of test/
Date: 5 months ago
Size: 1,996 bytes


Class file image Download
#!/usr/bin/env python

import os, sys
import pprint

def import_module(name, path):
    import imp
        mod_fp, mod_path, mod_desc  = imp.find_module(name, [path])
        mod = getattr( imp.load_module(name, mod_fp, mod_path, mod_desc), name )
    except ImportError as exc:
        mod = None
        sys.stderr.write("Error: failed to import module ({})".format(exc))
        if mod_fp: mod_fp.close()
    return mod

# import the engine (as a) module, probably you will want to place this in another dir/package
Dialect = import_module('Dialect', os.path.join(os.path.dirname(__file__), '../src/python/'))
if not Dialect:
    print ('Could not load the Dialect Module')

def echo( s='' ):
    print (s)

echo('Dialect.VERSION = ' + Dialect.VERSION)
echo( )

dialect = Dialect( 'postgres' )

echo(dialect.Create('new_table', {
    'ifnotexists': True,
    'columns': [
        {'column':'id', 'type':'bigint(20)', 'isnotnull':1, 'auto_increment':1},
        {'column':'name', 'type':'tinytext', 'isnotnull':1, 'default_value':"''"},
        {'column':'categoryid', 'type':'bigint(20)', 'isnotnull':1, 'default_value':0},
        {'column':'companyid', 'type':'bigint(20)', 'isnotnull':1, 'default_value':0},
        {'column':'fields', 'type':'text', 'isnotnull':1, 'default_value':"''"},
        {'column':'start', 'type':'datetime', 'isnotnull':1, 'default_value':"'0000-00-00 00:00:00'"},
        {'column':'end', 'type':'datetime', 'isnotnull':1, 'default_value':"'0000-00-00 00:00:00'"},
        {'column':'status', 'type':'tinyint(8) unsigned', 'isnotnull':1, 'default_value':0},
        {'column':'extra', 'type':'text', 'isnotnull':1, 'default_value':"''"}
    'table': [


echo(dialect.Create('new_view', {
    'view': True,
    'ifnotexists': True,
    'columns': ['id', 'name'],
    'query': 'SELECT id, name FROM another_table'

For more information send a message to info at phpclasses dot org.