Exemplo n.º 1
0
    def create(self):
        from germ.lib.db_iface import db_iface

        create_defs = []
        for attr_id in self._attr_ids:
            attr = self._attr_map[attr_id]

            # TODO: add REFERENCES?
            sql_type = attr.sql_type()

            col_def = attr_id + " " + sql_type + " NOT NULL"
            # if default is not None:
            # 	col_def += ' DEFAULT %s' % default

            create_defs.append(col_def)

        pk_def = ", ".join(self._pk_set)
        create_defs.append("PRIMARY KEY (%s)" % pk_def)

        create_def = ", ".join(create_defs)

        # sql_query = "CREATE TABLE IF NOT EXISTS %s (%s)" % \
        sql_query = "CREATE TABLE %s (%s)" % (self._name, create_def)

        db_iface.query(sql_query)
Exemplo n.º 2
0
	def __doit(self):
		query_str = self._get_sql_query()

		if query_str is None:
			return

		from germ.lib.db_iface import db_iface
		from _mysql_exceptions import ProgrammingError

		try:
			rset = db_iface.query(query_str)
		except ProgrammingError, e:
			self._tbl.create()

			rset = db_iface.query(query_str)
Exemplo n.º 3
0
def sql_query(sql_str, session, glob):
	"""handle failures due to non-existent tables correctly"""

	from germ.lib.db_iface import db_iface
	from _mysql_exceptions import ProgrammingError

	done = False
	while not done:
		try:
			res = db_iface.query(sql_str)
		except ProgrammingError, e:
			table = db_iface.get_missing_table(e)

			if table is None:
				import sys
				exctype, exc, tb = sys.exc_info()
				raise exctype, exc, tb

			from helper import get_entity
			entity = get_entity(table, session, glob)
			entity.create()
			del entity
		else:
			done = True