Skip to content

Commit

Permalink
Further removal of db_get_table()
Browse files Browse the repository at this point in the history
This commit also fixes a number of cases of references to unused table
name variables after the last commit removing db_get_table() calls.

The db_get_table() function has been removed too.
  • Loading branch information
davidhicks committed Jul 30, 2011
1 parent f81584f commit 75deecf
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 123 deletions.
10 changes: 5 additions & 5 deletions application/core/bug_api.php
Expand Up @@ -325,7 +325,7 @@ function create() {
# NOTE: this is guarranteed to be the correct one.
# The value LAST_INSERT_ID is stored on a per connection basis.

$t_text_id = db_insert_id( $t_bug_text_table );
$t_text_id = db_insert_id( 'bug_text' );

# check to see if we want to assign this right off
$t_starting_status = config_get( 'bug_submit_status' );
Expand Down Expand Up @@ -371,7 +371,7 @@ function create() {

db_query_bound( $query, array( $this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $t_status, $this->resolution, $this->projection, $this->category_id, $this->date_submitted, $this->last_updated, $this->eta, $t_text_id, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->profile_id, $this->summary, $this->view_state, $this->sponsorship_total, $this->sticky, $this->fixed_in_version, $this->target_version, $this->due_date ) );

$this->id = db_insert_id( $t_bug_table );
$this->id = db_insert_id( 'bug' );

# log new bug
history_log_event_special( $this->id, NEW_BUG );
Expand Down Expand Up @@ -556,7 +556,7 @@ function update( $p_update_extended = false, $p_bypass_mail = false ) {

/**
* Cache a database result-set containing full contents of bug_table row.
* @param array p_bug_database_result database row containing all columns from mantis_bug_table
* @param array p_bug_database_result database row containing all columns from 'bug' table
* @param array p_stats (optional) array representing bugnote stats
* @return array returns an array representing the bug row if bug exists
* @access public
Expand All @@ -573,7 +573,7 @@ function bug_cache_database_result( $p_bug_database_result, $p_stats = null ) {

/**
* Cache a bug row if necessary and return the cached copy
* @param array p_bug_id id of bug to cache from mantis_bug_table
* @param array p_bug_id id of bug to cache from 'bug' table
* @param array p_trigger_errors set to true to trigger an error if the bug does not exist.
* @return bool|array returns an array representing the bug row if bug exists or false if bug does not exist
* @access public
Expand Down Expand Up @@ -956,7 +956,7 @@ function bug_copy( $p_bug_id, $p_target_project_id = null, $p_copy_custom_fields
if( $t_bugnote_text = db_fetch_array( $result2 ) ) {
$query2 = "INSERT INTO {bugnote_text} ( note ) VALUES ( " . db_param() . ' )';
db_query_bound( $query2, array( $t_bugnote_text['note'] ) );
$t_bugnote_text_insert_id = db_insert_id( $t_mantis_bugnote_text_table );
$t_bugnote_text_insert_id = db_insert_id( 'bugnote_text' );
}

$query2 = "INSERT INTO {bugnote} ( bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified )
Expand Down
2 changes: 1 addition & 1 deletion application/core/bug_revision_api.php
Expand Up @@ -83,7 +83,7 @@ function bug_revision_add( $p_bug_id, $p_user_id, $p_type, $p_value, $p_bugnote_
$p_value
) );

return db_insert_id( $t_bug_rev_table );
return db_insert_id( 'bug_rev' );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions application/core/bugnote_api.php
Expand Up @@ -173,7 +173,7 @@ function bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_
db_query_bound( $query, array( $t_bugnote_text ) );

# retrieve bugnote text id number
$t_bugnote_text_id = db_insert_id( $t_bugnote_text_table );
$t_bugnote_text_id = db_insert_id( 'bugnote_text' );

# get user information
if( $p_user_id === null ) {
Expand All @@ -197,7 +197,7 @@ function bugnote_add( $p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_
db_query_bound( $query, array( $c_bug_id, $c_user_id, $t_bugnote_text_id, $t_view_state, $c_date_submitted, $c_last_modified, $c_type, $p_attr, $c_time_tracking ) );

# get bugnote id
$t_bugnote_id = db_insert_id( $t_bugnote_table );
$t_bugnote_id = db_insert_id( 'bugnote' );

# update bug last updated
if ( !$p_skip_bug_update ) {
Expand Down
2 changes: 1 addition & 1 deletion application/core/category_api.php
Expand Up @@ -142,7 +142,7 @@ function category_add( $p_project_id, $p_name ) {
db_query_bound( $query, array( $c_project_id, $p_name ) );

# db_query errors on failure so:
return db_insert_id( $t_category_table );
return db_insert_id( 'category' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/core/columns_api.php
Expand Up @@ -237,7 +237,7 @@ function columns_get_all( $p_project_id = null ) {

/**
* Checks if the specified column is an extended column. Extended columns are native columns that are
* associated with the issue but are saved in mantis_bug_text_table.
* associated with the issue but are saved in the 'bug_text' table.
* @param string $p_column The column name
* @return bool true for extended; false otherwise.
* @access public
Expand Down
7 changes: 3 additions & 4 deletions application/core/config_api.php
Expand Up @@ -80,8 +80,7 @@ function config_get( $p_option, $p_default = null, $p_user = null, $p_project =
# @@ debug @@ if ( ! db_is_connected() ) { echo "no db "; }
# @@ debug @@ echo "lu table=" . ( db_table_exists( $t_config_table ) ? "yes " : "no " );
if( !$g_cache_db_table_exists ) {
$t_config_table = db_get_table( 'config' );
$g_cache_db_table_exists = ( TRUE === db_is_connected() ) && db_table_exists( $t_config_table );
$g_cache_db_table_exists = ( TRUE === db_is_connected() ) && db_table_exists( 'config' );
}

if( $g_cache_db_table_exists ) {
Expand Down Expand Up @@ -454,12 +453,12 @@ function config_delete( $p_option, $p_user = ALL_USERS, $p_project = ALL_PROJECT
# @@ debug @@ if ($t_bypass_lookup) { echo "bp=$p_option match=$t_match_pattern <br />"; }
# @@ debug @@ if ( ! db_is_connected() ) { echo "no db"; }

if(( !$t_bypass_lookup ) && ( TRUE === db_is_connected() ) && ( db_table_exists( db_get_table( 'config' ) ) ) ) {
if(( !$t_bypass_lookup ) && ( TRUE === db_is_connected() ) && ( db_table_exists( 'config' ) ) ) {
if( !config_can_delete( $p_option ) ) {
return;
}

# @@ debug @@ echo "lu table=" . ( db_table_exists( $t_config_table ) ? "yes" : "no" );
# @@ debug @@ echo "lu table=" . ( db_table_exists( 'config' ) ? "yes" : "no" );
# @@ debug @@ error_print_stack_trace();

$c_user = db_prepare_int( $p_user );
Expand Down
5 changes: 2 additions & 3 deletions application/core/custom_field_api.php
Expand Up @@ -411,7 +411,7 @@ function custom_field_create( $p_name ) {

db_query_bound( $query, array( $c_name, '' ) );

return db_insert_id( $t_custom_field_table );
return db_insert_id( 'custom_field' );
}

/**
Expand Down Expand Up @@ -816,7 +816,6 @@ function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS ) {
if( !isset( $g_cache_cf_linked[$p_project_id] ) ) {

$p_project_id = (int) $p_project_id;
$t_custom_field_table = db_get_table( 'custom_field' );

if( ALL_PROJECTS == $p_project_id ) {
$t_user_id = auth_get_current_user_id();
Expand All @@ -838,7 +837,7 @@ function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS ) {
# e.g., all fields in public projects, or private projects where the user is listed
# or private projects where the user is implicitly listed
$query = "SELECT DISTINCT cft.id
FROM {custom_field} cft, $t_user_table ut, {project} pt, {custom_field_project} cfpt
FROM {custom_field} cft, {user} ut, {project} pt, {custom_field_project} cfpt
LEFT JOIN {project_user_list} pult
on cfpt.project_id = pult.project_id and pult.user_id = $t_user_id
WHERE cft.id = cfpt.field_id AND cfpt.project_id = pt.id AND ut.id = $t_user_id AND
Expand Down
17 changes: 0 additions & 17 deletions application/core/database_api.php
Expand Up @@ -526,23 +526,6 @@ function db_time_queries() {
return $total;
}

/**
* get database table name
* @return string containing full database table name
*/
function db_get_table( $option ) {
$table = $option;
$prefix = config_get_global( 'db_table_prefix' );
$suffix = config_get_global( 'db_table_suffix' );
if ( $prefix ) {
$table = $prefix . '_' . $table;
}
if ( $suffix ) {
$table .= $suffix;
}
return $table;
}

/**
* get list database tables
* @return array containing table names
Expand Down
2 changes: 1 addition & 1 deletion application/core/email_queue_api.php
Expand Up @@ -111,7 +111,7 @@ function email_queue_add( $p_email_data ) {
)";
db_query_bound( $query, array( $c_email, $c_subject, $c_body, db_now(), $c_metadata ) );

return db_insert_id( $t_email_table, 'email_id' );
return db_insert_id( 'email', 'email_id' );
}

/**
Expand Down
41 changes: 13 additions & 28 deletions application/core/file_api.php
Expand Up @@ -337,8 +337,7 @@ function file_delete_attachments( $p_bug_id ) {
$t_method = config_get( 'file_upload_method' );

# Delete files from disk
$t_query = "SELECT diskfile, filename FROM {bug_file}
WHERE bug_id=" . db_param();
$t_query = "SELECT diskfile, filename FROM {bug_file} WHERE bug_id=" . db_param();
$t_result = db_query_bound( $t_query, array( $c_bug_id ) );

$t_files = array();
Expand Down Expand Up @@ -372,8 +371,7 @@ function file_delete_attachments( $p_bug_id ) {
}

# Delete the corresponding db records
$t_query = "DELETE FROM $t_bug_file_table
WHERE bug_id=" . db_param();
$t_query = "DELETE FROM {bug_file} WHERE bug_id=" . db_param();
$t_result = db_query_bound( $t_query, array( $c_bug_id ) );

# db_query errors on failure so:
Expand All @@ -387,9 +385,7 @@ function file_delete_project_files( $p_project_id ) {
if ( ( $t_method == DISK ) || ( $t_method == FTP ) ) {

# Delete files from disk
$t_query = "SELECT diskfile, filename
FROM {project_file}
WHERE project_id=" . db_param();
$t_query = "SELECT diskfile, filename FROM {project_file} WHERE project_id=" . db_param();
$t_result = db_query_bound( $t_query, array( (int) $p_project_id ) );

$t_files = array();
Expand Down Expand Up @@ -417,8 +413,7 @@ function file_delete_project_files( $p_project_id ) {
}

# Delete the corresponding db records
$t_query = "DELETE FROM {project_file}
WHERE project_id=" . db_param();
$t_query = "DELETE FROM {project_file} WHERE project_id=" . db_param();
$t_result = db_query_bound( $t_query, array( (int) $p_project_id ) );
}

Expand Down Expand Up @@ -471,12 +466,10 @@ function file_delete_local( $p_filename ) {
# Return the specified field value
function file_get_field( $p_file_id, $p_field_name, $p_table = 'bug' ) {
$c_field_name = db_prepare_string( $p_field_name );
$t_bug_file_table = db_get_table( $p_table . '_file' );
$t_file_table = '{' . $p_table . '_file}';

# get info
$query = "SELECT $c_field_name
FROM $t_bug_file_table
WHERE id=" . db_param();
$query = "SELECT $c_field_name FROM $t_file_table WHERE id=" . db_param();
$result = db_query_bound( $query, array( (int) $p_file_id ), 1 );

return db_result( $result );
Expand Down Expand Up @@ -514,9 +507,8 @@ function file_delete( $p_file_id, $p_table = 'bug' ) {
history_log_event_special( $t_bug_id, FILE_DELETED, file_get_display_name( $t_filename ) );
}

$t_file_table = db_get_table( $p_table . '_file' );
$query = "DELETE FROM $t_file_table
WHERE id=" . db_param();
$t_file_table = '{' . $p_table . '_file}';
$query = "DELETE FROM $t_file_table WHERE id=" . db_param();
db_query_bound( $query, array( $c_file_id ) );
return true;
}
Expand Down Expand Up @@ -593,8 +585,7 @@ function diskfile_is_name_unique( $p_name, $p_filepath ) {

# Return true if the file name identifier is unique, false otherwise
function file_is_name_unique( $p_name, $p_bug_id ) {
$query = "SELECT COUNT(*) FROM {bug_file}
WHERE filename=" . db_param() . " AND bug_id=" . db_param();
$query = "SELECT COUNT(*) FROM {bug_file} WHERE filename=" . db_param() . " AND bug_id=" . db_param();
$result = db_query_bound( $query, array( $p_name, $p_bug_id ) );
$t_count = db_result( $result );

Expand Down Expand Up @@ -711,7 +702,7 @@ function file_add( $p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc
trigger_error( ERROR_GENERIC, ERROR );
}

$t_file_table = db_get_table( $p_table . '_file' );
$t_file_table = '{' . $p_table . '_file}';
$c_id = ( 'bug' == $p_table ) ? $c_bug_id : $c_project_id;

$query = "INSERT INTO $t_file_table
Expand Down Expand Up @@ -969,12 +960,8 @@ function file_move_bug_attachments( $p_bug_id, $p_project_id_to ) {
}

# Initialize the update query to update a single row
$t_bug_file_table = db_get_table( 'bug_file' );
$c_bug_id = db_prepare_int( $p_bug_id );
$query_disk_attachment_update = "UPDATE $t_bug_file_table
SET folder=" . db_param() . "
WHERE bug_id=" . db_param() . "
AND id =" . db_param();
$query_disk_attachment_update = "UPDATE {bug_file} SET folder=" . db_param() . " WHERE bug_id=" . db_param() . " AND id =" . db_param();

$t_attachment_rows = bug_get_attachments( $p_bug_id );
$t_attachments_count = count( $t_attachment_rows );
Expand Down Expand Up @@ -1011,9 +998,7 @@ function file_move_bug_attachments( $p_bug_id, $p_project_id_to ) {
*/
function file_copy_attachments( $p_source_bug_id, $p_dest_bug_id ) {

$t_mantis_bug_file_table = db_get_table( 'bug_file' );

$t_query = 'SELECT * FROM ' . $t_mantis_bug_file_table . ' WHERE bug_id = ' . db_param();
$t_query = 'SELECT * FROM {bug_file} WHERE bug_id = ' . db_param();
$t_result = db_query_bound( $t_query, Array( $p_source_bug_id ) );

$t_bug_file = array();
Expand All @@ -1027,7 +1012,7 @@ function file_copy_attachments( $p_source_bug_id, $p_dest_bug_id ) {
chmod( $t_new_diskfile_name, config_get( 'attachments_file_permissions' ) );
}

$t_query = "INSERT INTO $t_mantis_bug_file_table
$t_query = "INSERT INTO {bug_file}
( bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content )
VALUES ( " . db_param() . ",
" . db_param() . ",
Expand Down
2 changes: 1 addition & 1 deletion application/core/filter_api.php
Expand Up @@ -939,7 +939,7 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause
$t_def = custom_field_get_definition( $t_custom_field_id );
$t_value_field = ( $t_def['type'] == CUSTOM_FIELD_TYPE_TEXTAREA ? 'text' : 'value' );
$c_cf_alias = str_replace( ' ', '_', $t_custom_field );
$t_cf_table_alias = $t_custom_field_string_table . '_' . $t_custom_field_id;
$t_cf_table_alias = 'custom_field_string_' . $t_custom_field_id;
$t_cf_select = "$t_cf_table_alias.$t_value_field $c_cf_alias";

# check to be sure this field wasn't already added to the query.
Expand Down
8 changes: 4 additions & 4 deletions application/core/install_helper_functions_api.php
Expand Up @@ -154,7 +154,7 @@ function install_category_migrate() {
$query = "INSERT INTO {category} ( name, project_id, user_id ) VALUES ( " .
db_param() . ', ' . db_param() . ', ' . db_param() . ' )';
db_query_bound( $query, array( $t_name, $t_project_id, $t_user_id ) );
$t_category_id = db_insert_id( $t_category_table );
$t_category_id = db_insert_id( 'category' );
$t_inserted[$t_lower_name] = $t_category_id;
} else {
$t_category_id = $t_inserted[$t_lower_name];
Expand Down Expand Up @@ -187,7 +187,7 @@ function install_date_migrate( $p_data) {
$t_log_queries = null;
}

$t_table = $p_data[0];
$t_table = '{' . $p_data[0] . '}';
$t_id_column = $p_data[1];

if ( is_array( $p_data[2] ) ) {
Expand Down Expand Up @@ -373,7 +373,7 @@ function install_stored_filter_migrate() {
$t_filter_serialized = serialize( $t_filter_arr );
$t_filter_string = $t_cookie_version . '#' . $t_filter_serialized;

$t_update_query = "UPDATE $t_filters_table SET filter_string=" . db_param() . ' WHERE id=' . db_param();
$t_update_query = "UPDATE {filters} SET filter_string=" . db_param() . ' WHERE id=' . db_param();
$t_update_result = db_query_bound( $t_update_query, array( $t_filter_string, $t_row['id'] ) );
}

Expand Down Expand Up @@ -415,7 +415,7 @@ function install_create_admin_if_not_exist( $p_data ) {
db_query_bound( $query, array( $p_username, $p_email, $t_password, db_now(), db_now(), 1, 0, 90, 0, $t_cookie_string, '' ) );

# Create preferences for the user
$t_user_id = db_insert_id( $t_user_table );
$t_user_id = db_insert_id( 'user' );

if( $t_user_id === 1 ) {
return 2;
Expand Down
7 changes: 2 additions & 5 deletions application/core/news_api.php
Expand Up @@ -65,10 +65,7 @@ function news_create( $p_project_id, $p_poster_id, $p_view_state, $p_announcemen
}

# Add item
$query = "INSERT
INTO {news}
( project_id, poster_id, date_posted, last_modified,
view_state, announcement, headline, body )
$query = "INSERT INTO {news} ( project_id, poster_id, date_posted, last_modified, view_state, announcement, headline, body )
VALUES
( " . db_param() . ",
" . db_param() . ",
Expand All @@ -81,7 +78,7 @@ function news_create( $p_project_id, $p_poster_id, $p_view_state, $p_announcemen
)";
db_query_bound( $query, array( $c_project_id, $c_poster_id, db_now(), db_now(), $c_view_state, $c_announcement, $p_headline, $p_body ) );

$t_news_id = db_insert_id( $t_news_table );
$t_news_id = db_insert_id( 'news' );

twitter_news( $t_news_id );

Expand Down
4 changes: 2 additions & 2 deletions application/core/plugin_api.php
Expand Up @@ -165,7 +165,7 @@ function plugin_table( $p_name, $p_basename = null ) {
} else {
$t_current = $p_basename;
}
return db_get_table( 'plugin_' . $t_current . '_' . $p_name );
return 'plugin_' . $t_current . '_' . $p_name;
}

/**
Expand Down Expand Up @@ -816,7 +816,7 @@ function plugin_register_installed() {
* Post-signals EVENT_PLUGIN_INIT.
*/
function plugin_init_installed() {
if( OFF == config_get_global( 'plugins_enabled' ) || !db_table_exists( db_get_table( 'plugin' ) ) ) {
if( OFF == config_get_global( 'plugins_enabled' ) || !db_table_exists( 'plugin' ) ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion application/core/profile_api.php
Expand Up @@ -80,7 +80,7 @@ function profile_create( $p_user_id, $p_platform, $p_os, $p_os_build, $p_descrip
( " . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ' )';
db_query_bound( $t_query, array( $p_user_id, $p_platform, $p_os, $p_os_build, $p_description ) );

return db_insert_id( $t_user_profile_table );
return db_insert_id( 'user_profile' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/core/project_api.php
Expand Up @@ -279,7 +279,7 @@ function project_create( $p_name, $p_description, $p_status, $p_view_state = VS_
db_query_bound( $query, array( $p_name, (int) $p_status, $c_enabled, (int) $p_view_state, $p_file_path, $p_description, $c_inherit_global ) );

# return the id of the new project
return db_insert_id( $t_project_table );
return db_insert_id( 'project' );
}

# --------------------
Expand Down

0 comments on commit 75deecf

Please sign in to comment.