Webware / MiddleKit / Design / SQLiteSQLGenerator.py

import os

from SQLGenerator import SQLGenerator


class SQLiteSQLGenerator(SQLGenerator):

    def sqlSupportsDefaultValues(self):
        return True


class Model(object):

    def writeConnectToDatabase(self, generator, output, databasename):
        pass


class Klasses(object):

    def dropDatabaseSQL(self, dbName):
        return self.dropTablesSQL()

    def dropTablesSQL(self):
        sql = []
        for tableName in reversed(self.auxiliaryTableNames()):
            sql.append('drop table if exists %s;\n' % tableName)
        for klass in reversed(self._model._allKlassesInOrder):
            sql.append('drop table if exists %s;\n' % klass.name())
        sql.append('\n')
        return ''.join(sql)

    def createDatabaseSQL(self, dbName):
        return ''

    def useDatabaseSQL(self, dbName):
        return ''

    def listTablesSQL(self):
        return ''


class Klass(object):

    def primaryKeySQLDef(self, generator):
        return '    %s integer primary key autoincrement,\n' % (
            self.sqlSerialColumnName().ljust(self.maxNameWidth()),)

    def writeIndexSQLDefs(self, wr):
        # in SQLite, indices must be created with 'create index' commands
        pass


class EnumAttr(object):

    def writeAuxiliaryCreateTable(self, generator, out):
        if self.usesExternalSQLEnums():
            out.write('drop table if exists %s;\n' % self.externalEnumsSQLNames()[0])
        EnumAttr.mixInSuperWriteAuxiliaryCreateTable(self, generator, out)


class StringAttr(object):

    def sqlType(self):
        return 'text'

    def sqlForNonNoneSampleInput(self, value):
        return "'%s'" % value.replace("'", "''")


class ObjRefAttr(object):

    def sqlType(self):
        return 'integer /* %s */' % self['Type']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.