Establish Database and Table intended to work with
(in case the DB is omitted get the default one)

@param string $tblSrc
330268
private function establishDatabaseAndTable($tblSrc)
    {
        if (strpos($tblSrc, '.') === false) {
            if (!array_key_exists('workingDatabase', $this->advCache)) {
                $this->advCache['workingDatabase'] = $this->getMySqlCurrentDatabase();
            }
            return [$this->advCache['workingDatabase'], $tblSrc];
        }
        return explode('.', str_replace('`', '', $tblSrc));
    }
444141
public static function buildTableMap()
    {
        $dbMap = Propel::getServiceContainer()->getDatabaseMap(SkillTableMap::DATABASE_NAME);
        if (!$dbMap->hasTable(SkillTableMap::TABLE_NAME)) {
            $dbMap->addTableObject(new SkillTableMap());
        }
    }
233755
public function requireDefaultRecords()
    {
        if (!$this->owner) {
            return;
        }
        // Migration for Group.SubsiteID data from when Groups only had a single subsite
        $schema = DataObject::getSchema();
        $groupTable = Convert::raw2sql($schema->tableName(Group::class));
        $groupFields = DB::field_list($groupTable);

        // Detection of SubsiteID field is the trigger for old-style-subsiteID migration
        if (isset($groupFields['SubsiteID'])) {
            // Migrate subsite-specific data
            DB::query('INSERT INTO "Group_Subsites" ("GroupID", "SubsiteID")
				SELECT "ID", "SubsiteID" FROM "' . $groupTable . '" WHERE "SubsiteID" > 0');

            // Migrate global-access data
            DB::query('UPDATE "' . $groupTable . '" SET "AccessAllSubsites" = 1 WHERE "SubsiteID" = 0');

            // Move the field out of the way so that this migration doesn't get executed again
            DB::get_schema()->renameField($groupTable, 'SubsiteID', '_obsolete_SubsiteID');

            // No subsite access on anything means that we've just installed the subsites module.
            // Make all previous groups global-access groups
        } else {
            if (!DB::query('SELECT "Group"."ID" FROM "' . $groupTable . '"
			LEFT JOIN "Group_Subsites" ON "Group_Subsites"."GroupID" = "Group"."ID" AND "Group_Subsites"."SubsiteID" > 0
			WHERE "AccessAllSubsites" = 1
			OR "Group_Subsites"."GroupID" IS NOT NULL ')->value()
            ) {
                DB::query('UPDATE "' . $groupTable . '" SET "AccessAllSubsites" = 1');
            }
        }
    }
592351
protected function AssignFrom( $src )
	{
		$this->context = $src->context;
		$this->typeTest = $src->typeTest;
		$this->nameTest = $src->nameTest;
		$this->matchSelf = $src->matchSelf;
		$this->iter = $src->iter->CloneInstance();
	}
439852
public static function buildTableMap()
    {
      $dbMap = Propel::getServiceContainer()->getDatabaseMap(TeamTableMap::DATABASE_NAME);
      if (!$dbMap->hasTable(TeamTableMap::TABLE_NAME)) {
        $dbMap->addTableObject(new TeamTableMap());
      }
    }
485384
public function requireDefaultRecords() {

        parent::requireDefaultRecords();

        // The tables to migrate.

        $from = 'SilverStripeAustralia\ContentServiceAssets\ContentServiceAsset';
        $to = 'Symbiote\ContentServiceAssets\ContentServiceAsset';
        $escaped = 'Symbiote\\\\ContentServiceAssets\\\\ContentServiceAsset';

        // This only ever needs to run once, so we need to do an efficient check here.

        if(
            !\DB::query("SELECT EXISTS(SELECT 1 FROM \"{$to}\" LIMIT 1);")->value() &&
            \ClassInfo::hasTable($from) &&
            \DB::query("SELECT EXISTS(SELECT 1 FROM \"{$from}\" LIMIT 1);")->value()
        ) {

            // Copy the records across, and make sure the class name is correct.

            \DB::query("INSERT INTO \"{$to}\" SELECT * FROM \"{$from}\";");
            \DB::query("UPDATE \"{$to}\" SET ClassName = '{$escaped}';");
        }
    }
1240002
private static function mysqltcsCheck(Mysqltcs $mysqltcs)
    {
        if($mysqltcs == null || !($mysqltcs instanceof Mysqltcs)) {
            throw new MysqltcsException("mysqltcs passed is not an instance of Mysqltcs");
        }

        if (!$mysqltcs->isConnected()) {
            throw new MysqltcsException("mysqltcs passed is not connected");
        }
    }
657842
public void createTable(String tblName, Schema sch, Transaction tx) {
		if (tblName != TCAT_TBLNAME && tblName != FCAT_TBLNAME)
			formatFileHeader(tblName, tx);
		// Optimization: store the ti
		tiMap.put(tblName, new TableInfo(tblName, sch));

		// insert one record into tblcat
		RecordFile tcatfile = tcatInfo.open(tx, true);
		tcatfile.insert();
		tcatfile.setVal(TCAT_TBLNAME, new VarcharConstant(tblName));
		tcatfile.close();

		// insert a record into fldcat for each field
		RecordFile fcatfile = fcatInfo.open(tx, true);
		for (String fldname : sch.fields()) {
			fcatfile.insert();
			fcatfile.setVal(FCAT_TBLNAME, new VarcharConstant(tblName));
			fcatfile.setVal(FCAT_FLDNAME, new VarcharConstant(fldname));
			fcatfile.setVal(FCAT_TYPE, new IntegerConstant(sch.type(fldname)
					.getSqlType()));
			fcatfile.setVal(FCAT_TYPEARG, new IntegerConstant(sch.type(fldname)
					.getArgument()));
		}
		fcatfile.close();
	}
25835
protected function createTable()
    {
        if ($this->db->getTableSchema($this->tableName) === null) {
            $this->db->createCommand()
                ->createTable($this->tableName, [
                    'id' => 'pk',
                    'created_at' => 'integer',
                    'updated_at' => 'integer',
                    'data' => 'binary',
                ])->execute();
            $this->db->getTableSchema($this->tableName, true);
        }
    }
829002
def alter_table_with_environment_context(self, dbname, tbl_name, new_tbl, environment_context):
    
    self.send_alter_table_with_environment_context(dbname, tbl_name, new_tbl, environment_context)
    self.recv_alter_table_with_environment_context()
1053228
public function build($exec = TRUE)
    {
        // check if table exists
        if (!in_array($this->name, $this->schema->getTables()))
            trigger_error(sprintf(self::TEXT_TableNotExisting, $this->name),E_USER_ERROR);

        if ($sqlite = preg_match('/sqlite2?/', $this->db->driver())) {
            $sqlite_queries = array();
        }
        $rebuild = false;
        $additional_queries = $this->queries;
        $this->queries = array();
        // add new columns
        foreach ($this->columns as $cname => $column) {
            /** @var Column $column */
            // not nullable fields should have a default value, when altering a table
            if ($column->default === false && $column->nullable === false) {
                trigger_error(sprintf(self::TEXT_NotNullFieldNeedsDefault, $column->name),E_USER_ERROR);
                return false;
            }
            // no defaults for TEXT type
            if($column->default !== false && is_int(strpos(strtoupper($column->type),'TEXT'))) {
                trigger_error(sprintf(self::TEXT_NoDefaultForTEXT, $column->name),E_USER_ERROR);
                return false;
            }
            $table = $this->db->quotekey($this->name);
            $col_query = $column->getColumnQuery();
            if ($sqlite) {
                // sqlite: dynamic column default only works when rebuilding the table
                if($column->default === Schema::DF_CURRENT_TIMESTAMP) {
                    $rebuild = true;
                    break;
                } else
                    $sqlite_queries[] = "ALTER TABLE $table ADD $col_query;";
            } else {
                $cmd = array(
                    'mysql|pgsql|mssql|sybase|dblib|odbc|sqlsrv' =>
                        "ALTER TABLE $table ADD $col_query;",
                    'ibm' =>
                        "ALTER TABLE $table ADD COLUMN $col_query;",
                );
                $this->queries[] = $this->findQuery($cmd);
            }
        }
        if ($sqlite)
            if ($rebuild || !empty($this->rebuild_cmd)) $this->_sqlite_rebuild($exec);
            else $this->queries += $sqlite_queries;
        $this->queries = array_merge($this->queries,$additional_queries);
        // add new indexes
        foreach ($this->columns as $cname => $column)
            if ($column->index)
                $this->addIndex($cname, $column->unique);
        if (empty($this->queries))
            return false;
        if (is_array($this->queries) && count($this->queries) == 1)
            $this->queries = $this->queries[0];
        if (!$exec) return $this->queries;
        $result = ($this->suppress)
            ? @$this->db->exec($this->queries) : $this->db->exec($this->queries);
        $this->queries = $this->columns = $this->rebuild_cmd = array();
        return $result;
    }
138482
private function getTblStructure()
    {
        if (strpos($this->tbl, '{db_prefix}') !== 0 || strpos($this->tbl, $this->prefix) !== 0) {
            $this->tbl = $this->prefix . $this->tbl;
        }
        else {
            $this->tbl = str_replace('{db_prefix}', $this->prefix, $this->tbl);
        }
        
        $driver_class = '\Core\Data\Db\\' . ucfirst($this->db->dbh->getPrefix());
        
        /* @var $db_subs TableInfoAbstract */
        $db_subs = new $driver_class($this, $this->tbl);
        
        $db_subs->loadColumns($this->tbl);
        $this->columns = $db_subs->getColumns();
        
        $db_subs->loadIndexes($this->tbl);
        $this->indexes = $db_subs->getIndexes();
    }
1118016
public static function db_init($dir)
    {
        $db = self::db();

        $file = $dir . '/' . $db->db_provider . '.initial.sql';
        if (!file_exists($file)) {
            rcube::raise_error("DDL file $file not found", false, true);
        }

        echo "Creating database schema... ";

        if ($sql = file_get_contents($file)) {
            if (!$db->exec_script($sql)) {
                $error = $db->is_error();
            }
        }
        else {
            $error = "Unable to read file $file or it is empty";
        }

        if ($error) {
            echo "[FAILED]\n";
            rcube::raise_error($error, false, true);
        }
        else {
            echo "[OK]\n";
        }
    }
983452
private function createTable()
    {
        $stmt = 'CREATE TABLE IF NOT EXISTS "' . $this->name;
        $stmt.= '" ("' . $this->keyColumnName . '" TEXT PRIMARY KEY, "';
        $stmt.= $this->valueColumnName . '" TEXT);';
        $this->db->exec($stmt);
    }
720613
public function setDbConnection( $dbc ){
		if( !is_object( $dbc ) )
			throw new \InvalidArgumentException( 'Database connection resource must be an object' );
		if( !is_a( $dbc, 'PDO' ) )
			throw new \InvalidArgumentException( 'Database connection resource must be a direct or inherited PDO object' );
		$this->dbc = $dbc;
	}
1073476
private function createComponentsTbl()
    {
        Schema::create('tbl_components', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->string('vendor');
            $table->string('name');
            $table->tinyInteger('status')->default(1);
            $table->boolean('required')->default(0);
            $table->text('options')->nullable();

            $table->unique(['vendor', 'name']);
        });
    }
342018
def get_table(self, dbname, tbl_name):
    
    self.send_get_table(dbname, tbl_name)
    return self.recv_get_table()