Skip to content

Commit

Permalink
Fix #13227: Oracle database support (oci8)
Browse files Browse the repository at this point in the history
Mantis 1.2.6 currently does not work with Oracle DB:
1. Installation:
1.1. Oracle DB autocreates PK, so index creation for same field forbidden
1.2. Oracle DB uses datetime literal format timestamp'YYYY-MM-DD HH-MI:SS'
1.3. Oracle DB don't allows altering field property NOT NULL into NOT NULL
1.4. Oracle DB max object length is 30 chars, so some index names must be reduced
1.5. Oracle DB means empty string as NULLs, so NOT NULL restriction must be disabled for some field
1.6. Oracle DB can resolve database server name through TNS, so database name cannot be required
2. General:
2.2. Direct DB query execution result accessing instead of db_fetch_array() 1.3. usage didn't works with Oracle DB
2.4. Oracle DB binds variable by name, so bind names in statement must be sorted to address them.
2.5. Oracle DB handles NULL/DEFAULT values with specific way.
2.6. Oracle DB returns NULL value as true PHP null
2.7. Oracle DB handles sequence access with specific syntax
2.8. Nothing returned by db_prepare_string() in case of oci8
2.9. Oracle DB max object length is 30 chars, so table names must be reduced
2.10. Oracle DB uses LOB literal format similar to mssql
2.11. GetRowAssoc returns empty field values with oci8, it's need to enable returning both associative and indexed arrays.

The original patch was provided by DKuranov. He reckons that this also resolves
issues #6853, #7644, #10437, #10996, #11265, #11270, #11276, #12152, #12478

Porting to 1.3 - Conflicts:
	admin/install.php
	admin/schema.php
	core/database_api.php
	manage_tags_page.php
  • Loading branch information
dregad committed Oct 16, 2013
1 parent 4d7e96f commit 2ce60e4
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 15 deletions.
2 changes: 1 addition & 1 deletion admin/install.php
Expand Up @@ -277,7 +277,7 @@ function InsertData( $p_table, $p_data ) {

print_test( 'Setting Database Username', '' !== $f_db_username, true, 'database username is blank' );
print_test( 'Setting Database Password', '' !== $f_db_password, false, 'database password is blank' );
print_test( 'Setting Database Name', '' !== $f_database_name, true, 'database name is blank' );
print_test( 'Setting Database Name', '' !== $f_database_name || $f_db_type == 'oci8' , true, 'database name is blank' );

if( $f_db_type == 'db2' ) {
print_test( 'Setting Database Schema', !is_blank( $f_db_schema ), true, 'must have a schema name for AS400 in the form of DBNAME/SCHEMA' );
Expand Down
52 changes: 44 additions & 8 deletions admin/schema.php
Expand Up @@ -233,7 +233,9 @@ function installer_db_now() {
file_path C(250) NOTNULL DEFAULT \" '' \",
description XL NOTNULL
",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS')));
$upgrade[] = array('CreateIndexSQL',array('idx_project_id',db_get_table('project'),'id'));
# Index autocreated when oci used
if( $GLOBALS['g_db_type'] != 'oci8' )
$upgrade[] = array('CreateIndexSQL',array('idx_project_id',db_get_table('project'),'id'));
$upgrade[] = array('CreateIndexSQL',array('idx_project_name',db_get_table('project'),'name',array('UNIQUE')));
$upgrade[] = array('CreateIndexSQL',array('idx_project_view',db_get_table('project'),'view_state'));
$upgrade[] = array('CreateTableSQL',array(db_get_table('project_user_list'),"
Expand Down Expand Up @@ -339,10 +341,17 @@ function installer_db_now() {
$upgrade[] = array('CreateIndexSQL',array('idx_enable',db_get_table('user'),'enabled'));
/* 50 */
$upgrade[] = array('CreateIndexSQL',array('idx_access',db_get_table('user'),'access_level'));
$upgrade[] = array('InsertData', array( db_get_table('user'),
"(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES
('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', '" . installer_db_now() . "', '" . installer_db_now() . "', '1', '0', 90, 3, 0, 0, '" .
md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) );
# Oci uses other date literal syntax
if( $GLOBALS['g_db_type'] != 'oci8' )
$upgrade[] = array('InsertData', array( db_get_table('user'),
"(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES
('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', '" . installer_db_now() . "', '" . installer_db_now() . "', '1', '0', 90, 3, 0, 0, '" .
md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) );
else
$upgrade[] = array('InsertData', array( db_get_table('user'),
"(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES
('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', timestamp" . installer_db_now() . ", timestamp" . installer_db_now() . ", '1', '0', 90, 3, 0, 0, '" .
md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "old_value C(255) NOTNULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "new_value C(255) NOTNULL" ) );

Expand All @@ -354,7 +363,9 @@ function installer_db_now() {
metadata XL NOTNULL,
body XL NOTNULL
",array('mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS')));
$upgrade[] = array('CreateIndexSQL',array('idx_email_id',db_get_table('email'),'email_id'));
# Index autocreated when oci used
if( $GLOBALS['g_db_type'] != 'oci8' )
$upgrade[] = array('CreateIndexSQL',array('idx_email_id',db_get_table('email'),'email_id'));
$upgrade[] = array('AddColumnSQL',array(db_get_table('bug'), "target_version C(64) NOTNULL DEFAULT \" '' \""));
$upgrade[] = array('AddColumnSQL',array(db_get_table('bugnote'), "time_tracking I UNSIGNED NOTNULL DEFAULT \" 0 \""));
$upgrade[] = array('CreateIndexSQL',array('idx_diskfile',db_get_table('bug_file'),'diskfile'));
Expand Down Expand Up @@ -388,7 +399,11 @@ function installer_db_now() {
enabled L NOTNULL DEFAULT \" '0' \"
", array( 'mysql' => 'ENGINE=MyISAM DEFAULT CHARSET=utf8', 'pgsql' => 'WITHOUT OIDS' ) ) );

$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'user_pref' ), "redirect_delay I NOTNULL DEFAULT 0" ) );
# Field cannot be null with oci because of empty string equals NULL
if( $GLOBALS['g_db_type'] != 'oci8' )
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'user_pref' ), "redirect_delay I NOTNULL DEFAULT 0" ) );
else
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'user_pref' ), "redirect_delay I DEFAULT 0" ) );

/* apparently mysql now has a STRICT mode, where setting a DEFAULT value on a blob/text is now an error, instead of being silently ignored */
if ( isset( $f_db_type ) && ( $f_db_type == 'mysql' || $f_db_type == 'mysqli' ) ) {
Expand Down Expand Up @@ -606,13 +621,34 @@ function installer_db_now() {
$upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'user_pref'), "advanced_view" ) );
$upgrade[] = array( 'DropColumnSQL', array( db_get_table( 'user_pref'), "advanced_update" ) );
$upgrade[] = array( 'CreateIndexSQL', array( 'idx_project_hierarchy_child_id', db_get_table( 'project_hierarchy' ), 'child_id' ) );
$upgrade[] = array( 'CreateIndexSQL', array( 'idx_project_hierarchy_parent_id', db_get_table( 'project_hierarchy' ), 'parent_id' ) );
# Decrease index name length for oci8(30 chars max)
if( $GLOBALS['g_db_type'] != 'oci8' )
$upgrade[] = array( 'CreateIndexSQL', array( 'idx_project_hierarchy_parent_id', db_get_table( 'project_hierarchy' ), 'parent_id' ) );
else
$upgrade[] = array( 'CreateIndexSQL', array( 'idx_prj_hier_parent_id', db_get_table( 'project_hierarchy' ), 'parent_id' ) );

/* 180 */
$upgrade[] = array( 'CreateIndexSQL', array( 'idx_tag_name', db_get_table( 'tag' ), 'name' ) );
$upgrade[] = array( 'CreateIndexSQL', array( 'idx_bug_tag_tag_id', db_get_table( 'bug_tag' ), 'tag_id' ) );
$upgrade[] = array( 'CreateIndexSQL', array( 'idx_email_id', db_get_table( 'email' ), 'email_id', array( 'DROP' ) ), array( 'db_index_exists', array( db_get_table( 'email' ), 'idx_email_id') ) );
$upgrade[] = array( 'UpdateFunction', 'correct_multiselect_custom_fields_db_format' );

# Field cannot be null with oci because of empty string equals NULL
if( $GLOBALS['g_db_type'] == 'oci8' ) {
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug' ), "sticky NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "new_value NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "old_value NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_history' ), "field_name NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_text' ), "additional_information NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'bug_text' ), "steps_to_reproduce NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'project' ), "description NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'project_version' ), "description NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'tag' ), "description NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'user_pref' ), "email_on_priority NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'user_pref' ), "email_on_status NULL" ) );
$upgrade[] = array('AlterColumnSQL', array( db_get_table( 'user_profile' ), "description NULL" ) );
}

$upgrade[] = array( 'UpdateFunction', "stored_filter_migrate" );
$upgrade[] = array( 'AddColumnSQL', array( db_get_table( 'custom_field_string' ), "
text XL NULL DEFAULT NULL " ) );
Expand Down

0 comments on commit 2ce60e4

Please sign in to comment.