Extract table names from an SQL query.
548415
def extract_table_names(query):
    
    # a good old fashioned regex. turns out this worked better than actually parsing the code
    tables_blocks = re.findall(r'(?:FROM|JOIN)\s+(\w+(?:\s*,\s*\w+)*)', query, re.IGNORECASE)
    tables = [tbl
              for block in tables_blocks
              for tbl in re.findall(r'\w+', block)]
    return set(tables)
424307
def get_drop_table_sql(self, table):
        
        if isinstance(table, Table):
            table = table.get_quoted_name(self)

        return "DROP TABLE %s" % table
973859
def get_tables(self, table_name="", **kwargs):
        
        with self.connection(**kwargs) as connection:
            kwargs['connection'] = connection
            return self._get_tables(str(table_name), **kwargs)
1310436
public function getTableNames($sql) {
        $sql = trim(strtoupper($sql));

        if (strpos($sql, 'SELECT') === 0) {
            return $this->express($sql, static::$selectExpression);
        } else if (strpos($sql, 'UPDATE') === 0) {
            return $this->express($sql, static::$updateExpression);
        } else if (strpos($sql, 'INSERT') === 0) {
            return $this->express($sql, static::$insertExpression);
        } else if (strpos($sql, 'DELETE') === 0) {
            return $this->express($sql, static::$deleteExpression);
        }
        return [];
    }
497255
def fetch_fieldnames(self, sql: str, *args) -> List[str]:
        """"""
        self.ensure_db_open()
        cursor = self.db.cursor()
        self.db_exec_with_cursor(cursor, sql, *args)
        try:
            return [i[0] for i in cursor.description]
        except:  # nopep8
            log.exception("fetch_fieldnames: SQL was: " + sql)
            raise
1232043
def get_database_columns(self, tables=None, database=None):
        """"""
        # Get table data and columns from source database
        source = database if database else self.database
        tables = tables if tables else self.tables
        return {tbl: self.get_columns(tbl) for tbl in tqdm(tables, total=len(tables),
                                                           desc='Getting {0} columns'.format(source))}
224548
def tables(self):
        """"""
        self.own_connection.row_factory = sqlite3.Row
        self.own_cursor.execute('SELECT name from sqlite_master where type="table";')
        result = [x[0].encode('ascii') for x in self.own_cursor.fetchall()]
        self.own_connection.row_factory = self.factory
        return result
34279
def get_tables_for_bind(self, bind=None):
        """"""
        result = []
        tables = Model.metadata.tables
        for key in tables:
            if tables[key].info.get("bind_key") == bind:
                result.append(tables[key])
        return result
378397
def _split_queries(cls, sql):
        ""

        sql_s = dbt.compat.to_string(sql)
        sql_buf = StringIO(sql_s)
        split_query = snowflake.connector.util_text.split_statements(sql_buf)
        return [part[0] for part in split_query]
442454
def all_table_names_in_database(self, cache=False,
                                    cache_timeout=None, force=False):
        """"""
        if not self.allow_multi_schema_metadata_fetch:
            return []
        return self.db_engine_spec.fetch_result_sets(self, 'table')
763338
def db_tables(name, **connection_args):
    '''
    
    '''
    if not db_exists(name, **connection_args):
        log.info('Database \'%s\' does not exist', name)
        return False

    dbc = _connect(**connection_args)
    if dbc is None:
        return []
    cur = dbc.cursor()
    s_name = quote_identifier(name)
    # identifiers cannot be used as values
    qry = 'SHOW TABLES IN {0}'.format(s_name)
    try:
        _execute(cur, qry)
    except MySQLdb.OperationalError as exc:
        err = 'MySQL Error {0}: {1}'.format(*exc.args)
        __context__['mysql.error'] = err
        log.error(err)
        return []

    ret = []
    results = cur.fetchall()
    for table in results:
        ret.append(table[0])
    log.debug(ret)
    return ret
1369710
def getScriptNames(self):
		""""""

		if self._db == '':
			raise FMError, 'No database was selected'

		request = []
		request.append(uu({'-db': self._db }))
		request.append(uu({'-scriptnames': '' }))

		result = self._doRequest(request)
		result = FMResultset.FMResultset(result)

		scriptNames = []
		for scriptName in result.resultset:
			scriptNames.append(string.lower(scriptName['SCRIPT_NAME']))

		return scriptNames
1043101
private function getQueryTableName($query)
    {
        if (empty($query->from)) {
            /* @var $modelClass ActiveRecord */
            $modelClass = $query->modelClass;
            $tableName = $modelClass::tableName();
        } else {
            $tableName = '';
            foreach ($query->from as $alias => $tableName) {
                if (is_string($alias)) {
                    return [$tableName, $alias];
                } else {
                    break;
                }
            }
        }

        if (preg_match('/^(.*?)\s+({{\w+}}|\w+)$/', $tableName, $matches)) {
            $alias = $matches[2];
        } else {
            $alias = $tableName;
        }

        return [$tableName, $alias];
    }
1241718
def get_table_names(engine: Engine) -> List[str]:
    
    insp = Inspector.from_engine(engine)
    return insp.get_table_names()
508510
def rows(self):
        """"""
        bf = self.copy()
        result = bf.query.executeQuery(format="soa")
        return result["_rowName"]
74898
def _extract_columns(self, table_name):
        
        '''  '''
        
        import re
        from sqlalchemy import MetaData, VARCHAR, INTEGER, BLOB, BOOLEAN, FLOAT
        from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION, BIT, BYTEA
    
    # retrieve list of tables
        metadata_object = MetaData()
        table_list = self.engine.table_names()
    
    # determine columns
        prior_columns = {}
        if table_name in table_list:
            metadata_object.reflect(self.engine)
            existing_table = metadata_object.tables[table_name]
            for column in existing_table.columns:
                column_type = None
                column_length = None
                if column.type.__class__ == FLOAT().__class__:
                    column_type = 'float'
                elif column.type.__class__ == DOUBLE_PRECISION().__class__: # Postgres
                    column_type = 'float'
                elif column.type.__class__ == INTEGER().__class__:
                    column_type = 'integer'
                elif column.type.__class__ == VARCHAR().__class__:
                    column_length = getattr(column.type, 'length', None)
                    if column_length == 1:
                        if column.primary_key:
                            column_length = None
                    column_type = 'string'
                elif column.type.__class__ == BLOB().__class__:
                    column_type = 'list'
                elif column.type.__class__ in (BIT().__class__, BYTEA().__class__):
                    column_type = 'list'
                elif column.type.__class__ == BOOLEAN().__class__:
                    column_type = 'boolean'
                prior_columns[column.key] = (column.key, column_type, '', column_length)
        
        return prior_columns
13505
def get_table_column_names(self, exclude=None):
        """"""
        query = 'SELECT * FROM "{schema}"."{table}" limit 0'.format(table=self.table_name, schema=self.schema)
        columns = get_column_names(self.cc, query).keys()

        if exclude and isinstance(exclude, list):
            columns = list(set(columns) - set(exclude))

        return columns