!!! Only supports MySQL
556856
public static List<String> findSchemas(JdbcTemplate jdbcTemplate, final String schemaPattern,
                                           final DdlSchemaFilter ddlSchemaFilter) {
        List<String> schemas = findSchemas(jdbcTemplate, schemaPattern);
        if (ddlSchemaFilter == null) {
            return schemas;
        }
        List<String> filterSchemas = new ArrayList<String>();
        for (String schema : schemas) {
            if (ddlSchemaFilter.accept(schema)) {
                filterSchemas.add(schema);
            }
        }
        return filterSchemas;
    }
412489
function _query($sql,$inputarr=false)
	{
	global $ADODB_COUNTRECS;

		if ($ADODB_COUNTRECS == false && ADODB_PHPVER >= 0x4300)
			return sybase_unbuffered_query($sql,$this->_connectionID);
		else
			return sybase_query($sql,$this->_connectionID);
	}
538020
def create_mysql_oursql(username, password, host, port, database, **kwargs):  # pragma: no cover
    
    return create_engine(
        _create_mysql_oursql(username, password, host, port, database),
        **kwargs
    )
519129
public function connect() {
        if (!function_exists('\mysql_connect')) throw new RuntimeException('Undefined function mysql_connect(), mysql extension is not available');

        $host = $this->host; if ($this->port) $host .= ':'.$this->port;
        $user = $this->username;
        $pass = $this->password;

        // connect
        try {                                                                      // flags: CLIENT_FOUND_ROWS = 2
            $php_errormsg = '';
            $this->hConnection = mysql_connect($host, $user, $pass, $newLink=true/*, $flags=2*/);
            !$this->hConnection && trigger_error($php_errormsg, E_USER_ERROR);
        }
        catch (\Exception $ex) {
            if (!$ex instanceof IRosasurferException)
                $ex = new DatabaseException($ex->getMessage(), $ex->getCode(), $ex);
            throw $ex->addMessage('Can not connect to MySQL server on "'.$host.'"');
        }

        $this->setConnectionOptions();
        $this->selectDatabase();
        return $this;
    }
1091274
public function up()
    {
        // CAUTION: only works and tested on MySQL
        // Legacy support, default type MyISAM doesn't support foreign key
        // Convert table to InnoDB
        if (Schema::hasTable('products')) {
            DB::statement('ALTER TABLE products ENGINE = InnoDB');
        }
        
        if (Schema::hasTable('categories')) {
            DB::statement('ALTER TABLE categories ENGINE = InnoDB');
        }

        if (Schema::hasTable('pricelists')) {
            DB::statement('ALTER TABLE pricelists ENGINE = InnoDB');
        }
        
        if (Schema::hasTable('medias')) {
            DB::statement('ALTER TABLE medias ENGINE = InnoDB');
        }
        
        if (Schema::hasTable('modules')) {
            DB::statement('ALTER TABLE modules ENGINE = InnoDB');
        }
        
        if (Schema::hasTable('memberships')) {
            DB::statement('ALTER TABLE memberships ENGINE = InnoDB');
        }
        
        if (Schema::hasTable('coupons')) {
            DB::statement('ALTER TABLE coupons ENGINE = InnoDB');
        }
    }
1371669
function generateTableSQL( $tableName, $tableDef, $params, $asArray, $separateTypes = false )
    {
        $diffFriendly = isset( $params['diff_friendly'] ) ? $params['diff_friendly'] : false;
        $mysqlCompatible = isset( $params['compatible_sql'] ) ? $params['compatible_sql'] : false;

        if ( $asArray )
        {
            if ( $separateTypes )
            {
                $sqlList = array( 'tables' => array() );
            }
            else
            {
                $sqlList = array();
            }
        }

        $sql = '';
        $skip_pk = false;
        $sql_fields = array();
        $sql .= "CREATE TABLE $tableName (\n";

        $fields = $tableDef['fields'];

        foreach ( $fields as $field_name => $field_def )
        {
            $sql_fields[] = '  ' . eZMysqlSchema::generateFieldDef( $field_name, $field_def, $skip_pk_flag, $params );
            if ( $skip_pk_flag )
            {
                $skip_pk = true;
            }
        }

        // Make sure the order is as defined by 'offset'
        $indexes = $tableDef['indexes'];

        // We need to add all keys in table definition
        foreach ( $indexes as $index_name => $index_def )
        {
            $sql_fields[] = ( $diffFriendly ? '' : '  ' ) . eZMysqlSchema::generateAddIndexSql( $tableName, $index_name, $index_def, $params, true );
        }
        $sql .= join( ",\n", $sql_fields );
        $sql .= "\n)";

        // Add some extra table options if they are required
        $extraOptions = array();
        if ( isset( $params['table_type'] ) and $params['table_type'] )
        {
            $typeName = $this->tableStorageTypeName( $params['table_type'] );
            if ( $typeName )
            {
                $extraOptions[] = "ENGINE=" . $typeName;
            }
        }
        if ( isset( $params['table_charset'] ) and $params['table_charset'] )
        {
            $charsetName = $this->tableCharsetName( $params['table_charset'] );
            if ( $charsetName )
            {
                $extraOptions[] = "DEFAULT CHARACTER SET " . $charsetName;
            }
        }
        if ( isset( $tableDef['options'] ) )
        {
            foreach( $tableDef['options'] as $optionType => $optionValue )
            {
                $optionText = $this->generateTableOption( $tableName, $tableDef, $optionType, $optionValue, $params );
                if ( $optionText )
                    $extraOptions[] = $optionText;
            }
        }

        if ( count( $extraOptions ) > 0 )
        {
            $sql .= " " . implode( $diffFriendly ? "\n" : " ", $extraOptions );
        }

        if ( $asArray )
        {
            if ( $separateTypes )
            {
                $sqlList['tables'][] = $sql;
            }
            else
            {
                $sqlList[] = $sql;
            }
        }
        else
        {
            $sql .= ";\n";

            if ( $mysqlCompatible )
            {
                $sql .= "\n\n\n";
            }
        }

        return $asArray ? $sqlList : $sql;
    }
381347
public function executeSql()
    {
        $params = func_get_args();
        $sql = array_shift($params);

        if (!$sql)
            throw new Exception\LogicException("Can't execute SQL without SQL");
        elseif (is_array($sql)) {
            $params = $sql;
            $sql = array_shift($params);
        }
        $this->_parse_query_multimark($sql, $params);

        if (!$stmt = $this->pdo->prepare($sql)) {
            list($code, $drvrcode, $msg) = $this->pdo->errorInfo();
            $e = new Exception\QueryException(
                sprintf("[PDOStatement error] [SQLSTATE %s] (%s) %s", $code, $drvrcode, $msg)
            );
            throw $e;
        } elseif (!$stmt->execute($params) && Rails::env() == 'development') {
            list($code, $drvrcode, $msg) = $stmt->errorInfo();
            $e = new Exception\QueryException(
                sprintf("[PDOStatement error] [SQLSTATE %s] (%s) %s", $code, $drvrcode, $msg)
            );
            $e->setStatement($stmt, $params);
            throw $e;
        }

        $err = $stmt->errorInfo();

        if ($err[2]) {
            ActiveRecord::setLastError($err, $this->name);
            $e = new Exception\QueryException(
                sprintf("[SQLSTATE %s] (%s) %s", $err[0], (string)$err[1], $err[2])
            );
            $e->setStatement($stmt, $params);

            $msg  = "Error on database query execution\n";
            $msg .= $e->getMessage();
            Rails::log()->warning($msg);
        }

        return $stmt;
    }
343790
public static function install()
    {
        update_option('search-statistics-db-version', 0);
        $charsetCollation = self::$wpdb->get_charset_collate();
        $tableName = self::$dbTable;

        if (!empty(get_site_option('search-statistics-db-version')) && self::$wpdb->get_var("SHOW TABLES LIKE '$tableName'") == $tableName) {
            return;
        }

        $sql = "CREATE TABLE $tableName (
            id bigint(20) NOT NULL AUTO_INCREMENT,
            query varchar(255) DEFAULT NULL,
            results bigint(20) DEFAULT 0 NOT NULL,
            site_id bigint(20) DEFAULT NULL,
            logged_in tinyint(1) DEFAULT 0 NOT NULL,
            date_searched timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
            UNIQUE KEY id (id)
        ) $charsetCollation;";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);

        update_option('search-statistics-db-version', 2);
    }
646658
public static AzkabanDataSource getMySQLDataSource(final String host, final Integer port,
      final String dbName, final String user, final String password, final Integer numConnections) {
    return new MySQLBasicDataSource(host, port, dbName, user, password,
        numConnections);
  }
404262
public function connect()
	{
		if ($this->getConnection())
		{
			return;
		}

		try
		{
			// Try to connect to MySQL
			parent::connect();
		}
		catch (ConnectionFailureException $e)
		{
			// If the connection failed, but not because of the wrong character set, then bubble up the exception.
			if (!$this->utf8mb4)
			{
				throw $e;
			}

			/*
			 * Otherwise, try connecting again without using utf8mb4 and see if maybe that was the problem. If the connection succeeds, then we
			 * will have learned that the client end of the connection does not support utf8mb4.
  			 */
			$this->utf8mb4            = false;
			$this->options['charset'] = 'utf8';

			parent::connect();
		}

		if ($this->utf8mb4)
		{
			// At this point we know the client supports utf8mb4.  Now we must check if the server supports utf8mb4 as well.
			$serverVersion = $this->connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
			$this->utf8mb4 = version_compare($serverVersion, '5.5.3', '>=');

			if (!$this->utf8mb4)
			{
				// Reconnect with the utf8 character set.
				parent::disconnect();
				$this->options['charset'] = 'utf8';
				parent::connect();
			}
		}

		$this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
		$this->connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
	}
515384
public function createMysqlClientInstance()
    {
        $dbConfig = $this->engine->getConfigVar('database')['database']['log_db'];
        $names = (isset($dbConfig['charset']) && !empty($dbConfig['charset'])) ? $dbConfig['charset'] : 'utf8';
        $dsn = sprintf(
            "%s:host=%s;port=%s;dbname=%s",
            $dbConfig['driver'], $dbConfig['host'], $dbConfig['port'], $dbConfig['db_name']);
        $params = [
            \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES {$names}",
            \PDO::ATTR_PERSISTENT => false,
            \PDO::ATTR_TIMEOUT => isset($dbConfig['timeout']) ? $dbConfig['timeout'] : 10
        ];
        try {
            $pdo = @new \PDO($dsn, $dbConfig['user'], $dbConfig['password'], $params);
        } catch (\PDOException $e) {
            $errMsg = 'database log_db config connect failed: ' . $e->getMessage();
            $this->engine->logErr($errMsg);
            return null;
        }
        if (!$pdo) {
            return null;
        }
        return $pdo;
    }
641563
protected function createPDOMySQL($location, $database, $username, $password, $errorMode, $charset)
    {
        $dsn = 'mysql:host=' . $location . ';dbname=' . $database;
        if ($charset !== null) {
            $dsn .= ';charset=' . $charset;
        }

        $db  = new \Parable\ORM\Database\PDOMySQL($dsn, $username, $password);
        $db->setAttribute(\PDO::ATTR_ERRMODE, $errorMode);

        return $db;
    }
427195
protected function buildMultiSql()
    {
        $query = $this->getQuery();
        if (
            !isset($query['table']) || empty($query['table'])
            || !isset($query['multi-fields']) || empty($query['multi-fields'])
            || !isset($query['multi-data']) || empty($query['multi-data'])
        ) {
            throw new Exception(str_cover('"{type}"查询参数不完整', [
                '{type}' => 'multi-insert'
            ]), 101300302);
        }
        $KS = [];
        foreach ($query['multi-fields'] as $k) {
            $KS[] = $this->quoteColumnName($k);
        }
        $_VS = [];
        foreach ($query['multi-data'] as $data) {
            $bks = [];
            foreach ($data as $v) {
                if ($v instanceof Expression) {
                    $bks[] = $v->expression;
                    continue;
                }
                $bks[] = $bk = $this->getBindKey();
                $this->addParam($bk, $v);
            }
            $_VS[] = '(' . implode(',', $bks) . ')';
        }
        $sql = 'INSERT INTO '
            . $this->quoteTableName($query['table'])
            . ' (' . implode(',', $KS) . ') VALUES ' . implode(',', $_VS);
        return $sql;
    }
765952
protected function _mysql()
	{
		$this->_msg( 'Changing typeid to not allow NULL values', 0 );
		$this->_status( '' );

		foreach ( $this->_mysql as $table => $stmt ) {
			$this->_msg( sprintf ( 'Checking table "%1$s": ', $table ), 1 );

			if ( $this->_schema->tableExists( $table ) === true
				&& $this->_schema->columnExists( $table, 'typeid' ) === true
				&& $this->_schema->getColumnDetails( $table, 'typeid' )->isNullable() === true )
			{
				$this->_executeList( $stmt );
				$this->_status( 'migrated' );
			} else {
				$this->_status( 'OK' );
			}
		}
	}
908208
private function mysqltype2moodletype($mysql_type) {
        $type = null;

        switch(strtoupper($mysql_type)) {
            case 'BIT':
                $type = 'L';
                break;

            case 'TINYINT':
            case 'SMALLINT':
            case 'MEDIUMINT':
            case 'INT':
            case 'INTEGER':
            case 'BIGINT':
                $type = 'I';
                break;

            case 'FLOAT':
            case 'DOUBLE':
            case 'DECIMAL':
                $type = 'N';
                break;

            case 'CHAR':
            case 'ENUM':
            case 'SET':
            case 'VARCHAR':
                $type = 'C';
                break;

            case 'TINYTEXT':
            case 'TEXT':
            case 'MEDIUMTEXT':
            case 'LONGTEXT':
                $type = 'X';
                break;

            case 'BINARY':
            case 'VARBINARY':
            case 'BLOB':
            case 'TINYBLOB':
            case 'MEDIUMBLOB':
            case 'LONGBLOB':
                $type = 'B';
                break;

            case 'DATE':
            case 'TIME':
            case 'DATETIME':
            case 'TIMESTAMP':
            case 'YEAR':
                $type = 'D';
                break;
        }

        if (!$type) {
            throw new dml_exception('invalidmysqlnativetype', $mysql_type);
        }
        return $type;
    }
1324360
public void main() {

        fMain = new Frame("HSQLDB Database Manager for Zaurus");
        imgEmpty = createImage(new MemoryImageSource(2, 2, new int[4 * 4], 2,
                2));

        fMain.setIconImage(imgEmpty);
        fMain.addWindowListener(this);

        MenuBar bar = new MenuBar();

        // no shortcuts used
        String[] fitems = {
            "-Connect...", "--", "-Open Script...", "-Save Script...",
            "-Save Result...", "--", "-Exit"
        };

        addMenu(bar, "File", fitems);

        String[] vitems = {
            "-Refresh Tree", "--", "-View Tree", "-View Command",
            "-View Result", "-View Editor", "--", "-Results in Grid",
            "-Results in Text"
        };

        addMenu(bar, "View", vitems);

        String[] sitems = {
            "-SELECT", "-INSERT", "-UPDATE", "-DELETE", "--", "-CREATE TABLE",
            "-DROP TABLE", "-CREATE INDEX", "-DROP INDEX", "--", "-SCRIPT",
            "-SHUTDOWN", "--", "-Test Script"
        };

        addMenu(bar, "SQL", sitems);

        Menu recent = new Menu("Recent");

        mRecent = new Menu("Recent");

        bar.add(mRecent);

        String[] soptions = {
            "-AutoCommit on", "-AutoCommit off", "-Commit", "-Rollback", "--",
            "-Disable MaxRows", "-Set MaxRows to 100", "--", "-Logging on",
            "-Logging off", "--",
            "-Insert test data"    // , "-Transfer"
        };

        addMenu(bar, "Options", soptions);

        String[] shelp = { "-Show HTML-Help in browser" };

        addMenu(bar, "?", shelp);
        fMain.setMenuBar(bar);
        fMain.setSize(defWidth, defHeight);
        fMain.add("Center", this);
        initGUI();

        sRecent = new String[iMaxRecent];

        Dimension d    = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension size = fMain.getSize();

        // (ulrivo): arguments from command line or
        // full size on screen with less than 640 width
        if (d.width > 640) {
            fMain.setLocation((d.width - size.width) / 2,
                              (d.height - size.height) / 2);
        } else if (defWidth > 0 && defHeight > 0) {
            fMain.setLocation(defLocX, defLocY);
            fMain.setSize(defWidth, defHeight);
        } else {
            fMain.setLocation(0, 0);
            fMain.setSize(d);
        }

        fMain.show();

        // (ulrivo): load query from command line
        if (defQuery != null) {
            txtCommand.setText(DatabaseManagerCommon.readFile(defQuery));
        }

        txtCommand.requestFocus();
    }
810821
function MariaDB (sessionConfig, sessionLogger) {
  if (!_filled(sessionConfig.DB_HOST) ||
    !_filled(sessionConfig.DB_USER) ||
    !_filled(sessionConfig.DB_PASS) ||
    !_filled(sessionConfig.DB_NAME)) {

    return undefined;
  }

  this.dbConfig = {
    "DB_HOST": sessionConfig.DB_HOST,
    "DB_USER": sessionConfig.DB_USER,
    "DB_PASS": sessionConfig.DB_PASS,
    "DB_NAME": sessionConfig.DB_NAME
  };

  if (_filled(sessionLogger) && typeof sessionLogger === "function") {
    this.logger = sessionLogger
  }

  mariadbObj = this;

  /*
   * 2015-07-29, Curitiba - Brazil
   * Author: Eduardo Quagliato<eduardo@quagliato.me>
   * Description: Creates the connection to the database
   */
  this.connectDB = function () {
    var conn = mysql.createConnection({
      host     : mariadbObj.dbConfig.DB_HOST,
      user     : mariadbObj.dbConfig.DB_USER,
      password : mariadbObj.dbConfig.DB_PASS,
      database : mariadbObj.dbConfig.DB_NAME
    });
    mariadbObj.logger("Instanced MariaDB Connection.");

    conn.connect();
    mariadbObj.logger("Connected to MariaDB Server");

    return conn;
  };

  /*
   * 2015-07-29, Curitiba - Brazil
   * Author: Eduardo Quagliato<eduardo@quagliato.me>
   * Description: Disconnects from database
   */
  this.disconnectDB = function (conn) {
    mariadbObj.logger("Connection to MariaDB Server ended.");
    conn.end();
  };

  
  /*
   * 2015-07-29, Curitiba - Brazil
   * Author: Eduardo Quagliato<eduardo@quagliato.me>
   * Description: Execute a query to the database
   */
  this.query = function (queryStr, callback) {
    mariadbObj.logger("SQL: {0}".format(queryStr));
    var connection = mariadbObj.connectDB();
    connection.query(queryStr, function(err, rows, fields) {
      if (err) {
        mariadbObj.logger("SQL: {0} - {1}".format(queryStr, err), "CRITICAL");
        return callback(-1);
      }
      
      var size = 0;
      var result = [];
      var is_select = true;
      if (rows.affectedRows > 0) { // Insert, update, delete
        is_select = false;
        result = rows;
      } else if (rows && rows != null && rows.length > 0) {
        size = rows.length;

        if (size > 0) {
          for (var i = 0; i < rows.length; i++) {
            var newRow = {};
            for (var j = 0; j < fields.length; j++) {
              newRow[fields[j].name]= rows[i][fields[j].name]
            }
            result.push(newRow);
          }
        }

        if (size === 1) result = result[0];
      }
      
      callback(parseInt(size), result);
      mariadbObj.disconnectDB(connection);
    });
  };
}