def exists(self, tbl_name=None): """Check to see if the table exists tbl_name[in] table name (db.table) (optional) If omitted, operation is performed on the class instance table name. return True = table exists, False = table does not exist """ db, table = (None, None) if tbl_name: db, table = Database.parse_object_name(tbl_name) else: db = self.db_name table = self.tbl_name res = self.server.exec_query("SELECT TABLE_NAME " + "FROM INFORMATION_SCHEMA.TABLES " + "WHERE TABLE_SCHEMA = '%s'" % db + " and TABLE_NAME = '%s'" % table) return (res is not None and len(res) >= 1)
def __init__(self, server1, name, options=None): """Constructor server[in] A Server object name[in] Name of table in the form (db.table) options[in] options for class: verbose, quiet, get_cols, quiet If True, do not print information messages verbose print extra data during operations (optional) (default is False) get_cols If True, get the column metadata on construction (default is False) """ if options is None: options = {} self.verbose = options.get('verbose', False) self.quiet = options.get('quiet', False) self.server = server1 # Keep table identifier considering backtick quotes if is_quoted_with_backticks(name): self.q_table = name self.q_db_name, self.q_tbl_name = Database.parse_object_name(name) self.db_name = remove_backtick_quoting(self.q_db_name) self.tbl_name = remove_backtick_quoting(self.q_tbl_name) self.table = ".".join([self.db_name, self.tbl_name]) else: self.table = name self.db_name, self.tbl_name = Database.parse_object_name(name) self.q_db_name = quote_with_backticks(self.db_name) self.q_tbl_name = quote_with_backticks(self.tbl_name) self.q_table = ".".join([self.q_db_name, self.q_tbl_name]) self.obj_type = "TABLE" self.pri_idx = None # We store each type of index in a separate list to make it easier # to manipulate self.btree_indexes = [] self.hash_indexes = [] self.rtree_indexes = [] self.fulltext_indexes = [] self.text_columns = [] self.blob_columns = [] self.column_format = None self.column_names = [] self.q_column_names = [] if options.get('get_cols', False): self.get_column_metadata() self.dest_vals = None self.storage_engine = None # Get max allowed packet res = self.server.exec_query("SELECT @@session.max_allowed_packet") if res: self.max_packet_size = res[0][0] else: self.max_packet_size = _MAXPACKET_SIZE # Watch for invalid values if self.max_packet_size > _MAXPACKET_SIZE: self.max_packet_size = _MAXPACKET_SIZE self._insert = "INSERT INTO %s.%s VALUES " self.query_options = { # Used for skipping fetch of rows 'fetch': False }