def create_database(system, host, root_password, name, username, distances): """Create and initialize the database.""" cnx_uri = uri(system, host, None, "root", root_password) root_cnx = connection_for_URI(cnx_uri) root_cnx.query("CREATE DATABASE %s%s" % (DB_PREFIX, name)) root_cnx.query("GRANT ALL ON %s%s.* TO %s@%s IDENTIFIED BY ''" % (DB_PREFIX, name, USERNAME, host)) root_cnx.query("USE %s%s" % (DB_PREFIX, name)) root_cnx.close() connection = connection_for_URI(uri(system, host, name)) sqlhub.processConnection = connection for table in tables: table.createTable() Distances(mens_distance=distances[0], womens_distance=distances[1])
found = cls.selectBy(name=name) if city is not None: found = [venue for venue in found if venue.city == city] if state is not None: found = [venue for venue in found if venue.state == state] if found.count() == 1: return found[0] if found.count() == 0: raise SQLObjectNotFound("No venue named %s could be found." % name) raise TooManyObjectsError("More than one venue %s found." % name) @searchable_by_name(get_venue_by_name) class Venues(SQLObject): name = StringCol() city = StringCol() state = StringCol() elevation = IntCol() tables = [Affiliations, Conferences, Distances, Meets, Races, Results, Runners, Schools, Venues] #Exceptions class DidNotCompeteError(Exception): pass class NotAffiliatedError(Exception): pass class TooManyObjectsError(Exception): pass if __name__ == "__main__": uri = "mysql://xcanalyze@localhost/xca_database" sqlhub.processConnection = connection_for_URI(uri)