Exemplo n.º 1
0
function db_connect($p_dsn, $p_hostname = null, $p_username = null, $p_password = null, $p_database_name = null, $p_db_schema = null, $p_pconnect = false)
{
    global $g_db_connected, $g_db;
    if ($p_dsn === false) {
        $t_db_type = config_get_global('db_type');
        $g_db = ADONewConnection($t_db_type);
        if ($p_pconnect) {
            $t_result = $g_db->PConnect($p_hostname, $p_username, $p_password, $p_database_name);
        } else {
            $t_result = $g_db->Connect($p_hostname, $p_username, $p_password, $p_database_name);
        }
    } else {
        $g_db = ADONewConnection($p_dsn);
        $t_result = $g_db->IsConnected();
    }
    if ($t_result) {
        # For MySQL, the charset for the connection needs to be specified.
        if (db_is_mysql()) {
            $c_charset = db_prepare_string(lang_get('charset'));
            # @@@ Is there a way to translate any charset name to MySQL format? e.g. remote the dashes?
            # @@@ Is this needed for other databases?
            if (strtolower($c_charset) === 'utf-8') {
                db_query('SET NAMES UTF8');
            }
        } elseif (db_is_db2() && $p_db_schema !== null && !is_blank($p_db_schema)) {
            $t_result2 = db_query('set schema ' . $p_db_schema);
            if ($t_result2 === false) {
                db_error();
                trigger_error(ERROR_DB_CONNECT_FAILED, ERROR);
                return false;
            }
        }
    } else {
        db_error();
        trigger_error(ERROR_DB_CONNECT_FAILED, ERROR);
        return false;
    }
    $g_db_connected = true;
    return true;
}
Exemplo n.º 2
0
/**
 * Open a connection to the database.
 * @param string $p_dsn Database connection string ( specified instead of other params)
 * @param string $p_hostname Database server hostname
 * @param string $p_username database server username
 * @param string $p_password database server password
 * @param string $p_database_name database name
 * @param string $p_db_schema Schema name (only used if database type is DB2)
 * @param bool $p_pconnect Use a Persistent connection to database
 * @return bool indicating if the connection was successful
 */
function db_connect($p_dsn, $p_hostname = null, $p_username = null, $p_password = null, $p_database_name = null, $p_db_schema = null, $p_pconnect = false)
{
    global $g_db_connected, $g_db;
    $t_db_type = config_get_global('db_type');
    if (!db_check_database_support($t_db_type)) {
        error_parameters(0, 'PHP Support for database is not enabled');
        trigger_error(ERROR_DB_CONNECT_FAILED, ERROR);
    }
    if ($p_dsn === false) {
        $g_db = ADONewConnection($t_db_type);
        if ($p_pconnect) {
            $t_result = $g_db->PConnect($p_hostname, $p_username, $p_password, $p_database_name);
        } else {
            $t_result = $g_db->Connect($p_hostname, $p_username, $p_password, $p_database_name);
        }
    } else {
        $g_db = ADONewConnection($p_dsn);
        $t_result = $g_db->IsConnected();
    }
    if ($t_result) {
        // For MySQL, the charset for the connection needs to be specified.
        if (db_is_mysql()) {
            /** @todo Is there a way to translate any charset name to MySQL format? e.g. remote the dashes? */
            /** @todo Is this needed for other databases? */
            db_query_bound('SET NAMES UTF8');
        } else {
            if (db_is_db2() && $p_db_schema !== null && !is_blank($p_db_schema)) {
                $t_result2 = db_query_bound('set schema ' . $p_db_schema);
                if ($t_result2 === false) {
                    db_error();
                    trigger_error(ERROR_DB_CONNECT_FAILED, ERROR);
                    return false;
                }
            }
        }
    } else {
        db_error();
        trigger_error(ERROR_DB_CONNECT_FAILED, ERROR);
        return false;
    }
    $g_db_connected = true;
    return true;
}
Exemplo n.º 3
0
function test_database_utf8()
{
    if (!db_is_mysql()) {
        return;
    }
    // table collation/character set check
    $result = db_query_bound('SHOW TABLE STATUS');
    while ($row = db_fetch_array($result)) {
        if ($row['Comment'] !== 'VIEW') {
            print_test_row('Checking Table Collation is utf8 for ' . $row['Name'] . '....', substr($row['Collation'], 0, 5) === 'utf8_', $row['Collation']);
        }
    }
    foreach (db_get_table_list() as $t_table) {
        if (db_table_exists($t_table)) {
            $result = db_query_bound('SHOW FULL FIELDS FROM ' . $t_table);
            while ($row = db_fetch_array($result)) {
                if ($row['Collation'] === null) {
                    continue;
                }
                print_test_row('Checking Non-null Column Collation in ' . $t_table . ' is utf8 for ' . $row['Field'] . '....', substr($row['Collation'], 0, 5) === 'utf8_', $row['Collation'] . ' ( ' . $row['Type'] . ')');
            }
        }
    }
}
Exemplo n.º 4
0
}

$t_table_prefix = config_get_global( 'db_table_prefix' );
check_print_info_row(
	'Prefix added to each MantisBT table name',
	htmlentities( $t_table_prefix )
);

$t_table_suffix = config_get_global( 'db_table_suffix' );
check_print_info_row(
	'Suffix added to each MantisBT table name',
	htmlentities( $t_table_suffix )
);

if( db_is_mysql() ) {

	$t_table_prefix_regex_safe = preg_quote( $t_table_prefix, '/' );
	$t_table_suffix_regex_safe = preg_quote( $t_table_suffix, '/' );

	$t_result = db_query_bound( 'SHOW TABLE STATUS' );
	while( $t_row = db_fetch_array( $t_result ) ) {
		if( $t_row['Comment'] !== 'VIEW' &&
		    preg_match( "/^$t_table_prefix_regex_safe.+?$t_table_suffix_regex_safe\$/", $t_row['Name'] ) ) {
			check_print_test_row(
				'Table <em>' . htmlentities( $t_row['Name'] ) . '</em> is using UTF-8 collation',
				substr( $t_row['Collation'], 0, 5 ) === 'utf8_',
				array( false => 'Table ' . htmlentities( $t_row['Name'] ) . ' is using ' . htmlentities( $t_row['Collation'] ) . ' collation where UTF-8 collation is required.' )
			);
		}
	}
Exemplo n.º 5
0
/**
 * If database uses mysql, it changes table to InnoDB engine (to support transactions).
 * @param string $table table name.
 */
function change_mysql_table_to_InnoDB($table)
{
    if (db_is_mysql()) {
        $CI =& get_instance();
        $CI->db->query('ALTER TABLE `' . $table . '` ENGINE = INNODB');
    }
}
Exemplo n.º 6
0
 /**
  * Will be executed, if the user hits the install link on the plugin
  * overview page and before schema()
  */
 function install()
 {
     $t_plugin_path = config_get_global('plugin_path') . plugin_get_current() . DIRECTORY_SEPARATOR;
     // Install site key
     plugin_config_set('gadiv_sitekey', md5(uniqid(rand(), true)));
     $this->installConfigurationParams();
     // Create custom fields
     $this->create_custom_field('ProductBacklog', array('possible_values' => '', 'type' => '6'));
     // List
     $this->create_custom_field('Sprint', array('possible_values' => '', 'type' => '6'));
     // List
     $this->create_custom_field('Storypoints', array('possible_values' => '', 'type' => '1'));
     // Number
     $this->create_custom_field('BusinessValue', array('possible_values' => '', 'type' => '0'));
     // Text
     $this->create_custom_field('RankingOrder', array('possible_values' => '', 'type' => '1'));
     // Number
     $this->create_custom_field('Presentable', array('possible_values' => '1|2|3', 'type' => '6'));
     // List
     $this->create_custom_field('Technical', array('possible_values' => 'Ja', 'type' => '5'));
     // Checkbox
     $this->create_custom_field('InReleaseDocu', array('possible_values' => 'Ja', 'type' => '5'));
     // Checkbox
     $this->create_custom_field('PlannedWork', array('possible_values' => '', 'type' => '1'));
     // Number
     $this->create_custom_field('PlannedWorkUnit', array('possible_values' => '0|1|2|3', 'type' => '0', 'filter_by' => '0'));
     // Text
     // If old tables exists, that where not created by ADODB, the setting 'plugin_agileMantis_schema'
     // needs to be set to the last block of the schema that was created without ADODB.
     // e.g. if the last table created without ADODB was 'gadiv_teams', the plugin_agileMantis_schema
     // needs to be set to the corresponding schema block. Only the blocks after that will be executed.
     if (plugin_config_get('schema', -1) == -1) {
         if (db_is_mysql()) {
             if ($this->getDBVersion() == '2.0.0') {
                 // Version 2.0. is installed, set block to #21
                 plugin_config_set('schema', 21);
             } else {
                 if (db_field_exists('expert', 'gadiv_additional_user_fields')) {
                     // Version 1.3 is installed, set block to #14
                     plugin_config_set('schema', 14);
                 } else {
                     if (db_table_exists('gadiv_sprints')) {
                         // Version < 1.3 is installed, set block to #13
                         plugin_config_set('schema', 13);
                     }
                 }
             }
         } else {
             if (db_is_mssql()) {
                 plugin_config_set('schema', -1);
             }
         }
     }
     return TRUE;
 }
Exemplo n.º 7
0
 function getLatestSprints($team_id, $amountOfSprints = 0, $sprintName = "", $previous = "")
 {
     $top = "";
     if (db_is_mysql()) {
         if ($amountOfSprints != "") {
             $addSql = " ORDER BY id DESC LIMIT 0, " . (int) $amountOfSprints;
         }
         if ($previous == true) {
             $addSql = " ORDER BY id DESC LIMIT 1, " . (int) $amountOfSprints;
         }
     } else {
         //mssql
         $addSql = " ORDER BY id DESC ";
         if ($amountOfSprints > 0) {
             $top = " top " . (int) $amountOfSprints . " ";
         }
     }
     $t_params[0] = $team_id;
     if ($sprintName != "") {
         $addSql = " AND name=" . db_param(1);
         $t_params[1] = $sprintName;
     }
     $t_sql = "SELECT " . $top . " id,\n\t\t\t\t\t\t\tteam_id,\n\t\t\t\t\t\t\tpb_id,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\tdaily_scrum,\n\t\t\t\t\t\t\tstart,\n\t\t\t\t\t\t\tdispose as " . AGILEMANTIS_COMMIT_FIELD . ",\n\t\t\t\t\t\t\tenddate as " . AGILEMANTIS_END_FIELD . ",\n\t\t\t\t\t\t\tclosed,\n\t\t\t\t\t\t\tunit_storypoints,\n\t\t\t\t\t\t\tunit_planned_work,\n\t\t\t\t\t\t\tunit_planned_task,\n\t\t\t\t\t\t\tworkday_length,\n\t\t\t\t\t\t\tsprint_id,\n\t\t\t\t\t\t\tcount_user_stories,\n\t\t\t\t\t\t\tcount_task_sprint,\n\t\t\t\t\t\t\tcount_splitted_user_stories_sprint,\n\t\t\t\t\t\t\tstorypoints_sprint,\n\t\t\t\t\t\t\tstorypoints_in_splitted_user_stories,\n\t\t\t\t\t\t\twork_planned_sprint,\n\t\t\t\t\t\t\twork_performed,\n\t\t\t\t\t\t\twork_moved,\n\t\t\t\t\t\t\tstorypoints_moved,\n\t\t\t\t\t\t\tcount_developer_team,\n\t\t\t\t\t\t\ttotal_developer_capacity,\n\t\t\t\t\t\t\tcount_developer_team_task,\n\t\t\t\t\t\t\ttotal_developer_capacity_task\n\t\t\t\tFROM gadiv_sprints \n\t\t\t\tLEFT JOIN gadiv_rel_sprint_closed_information ON sprint_id = id \n\t\t\t\tWHERE team_id=" . db_param(0) . $addSql;
     return $this->executeQuery($t_sql, $t_params);
 }
Exemplo n.º 8
0
/**
 * Replace 4-byte UTF-8 chars
 * This is a workaround to avoid data getting truncated on MySQL databases
 * using native utf8 encoding, which only supports 3 bytes chars (see #20431)
 * @param string $p_string
 * @return string
 */
function db_mysql_fix_utf8($p_string)
{
    if (!db_is_mysql()) {
        return $p_string;
    }
    return preg_replace('/[\\xF0-\\xF7].../s', "�", $p_string);
}