Skip to content

Commit

Permalink
Refector out some more calls to row_count
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis authored and davidhicks committed Jul 30, 2011
1 parent ceb4a44 commit 087c44a
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 43 deletions.
12 changes: 6 additions & 6 deletions application/core/bug_api.php
Expand Up @@ -610,7 +610,9 @@ function bug_cache_row( $p_bug_id, $p_trigger_errors = true ) {
WHERE id=" . db_param();
$result = db_query_bound( $query, Array( $c_bug_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
$g_cache_bug[$c_bug_id] = false;

if( $p_trigger_errors ) {
Expand All @@ -621,8 +623,6 @@ function bug_cache_row( $p_bug_id, $p_trigger_errors = true ) {
}
}

$row = db_fetch_array( $result );

return bug_add_to_cache( $row );
}

Expand Down Expand Up @@ -722,7 +722,9 @@ function bug_text_cache_row( $p_bug_id, $p_trigger_errors = true ) {
b.bug_text_id = bt.id";
$result = db_query_bound( $query, Array( $c_bug_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
$g_cache_bug_text[$c_bug_id] = false;

if( $p_trigger_errors ) {
Expand All @@ -733,8 +735,6 @@ function bug_text_cache_row( $p_bug_id, $p_trigger_errors = true ) {
}
}

$row = db_fetch_array( $result );

$g_cache_bug_text[$c_bug_id] = $row;

return $row;
Expand Down
11 changes: 4 additions & 7 deletions application/core/category_api.php
Expand Up @@ -314,12 +314,11 @@ function category_get_row( $p_category_id ) {
$query = "SELECT * FROM $t_category_table
WHERE id=" . db_param();
$result = db_query_bound( $query, array( $c_category_id ) );
$count = db_num_rows( $result );
if( 0 == $count ) {
$row = db_fetch_array( $result );
if( !$row ) {
trigger_error( ERROR_CATEGORY_NOT_FOUND, ERROR );
}

$row = db_fetch_array( $result );
$g_category_cache[$p_category_id] = $row;
return $row;
}
Expand Down Expand Up @@ -499,11 +498,9 @@ function category_get_all_rows( $p_project_id, $p_inherit = null, $p_sort_by_pro
WHERE $t_project_where
ORDER BY c.name ";
$result = db_query_bound( $query );
$count = db_num_rows( $result );
$rows = array();
for( $i = 0;$i < $count;$i++ ) {
$row = db_fetch_array( $result );

$rows = array();
while( $row = db_fetch_array( $result ) ) {
$rows[] = $row;
$g_category_cache[(int) $row['id']] = $row;
}
Expand Down
12 changes: 6 additions & 6 deletions application/core/custom_field_api.php
Expand Up @@ -120,7 +120,9 @@ function custom_field_cache_row( $p_field_id, $p_trigger_errors = true ) {
WHERE id=" . db_param();
$result = db_query_bound( $query, Array( $c_field_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
if( $p_trigger_errors ) {
error_parameters( 'Custom ' . $p_field_id );
trigger_error( ERROR_CUSTOM_FIELD_NOT_FOUND, ERROR );
Expand All @@ -129,8 +131,6 @@ function custom_field_cache_row( $p_field_id, $p_trigger_errors = true ) {
}
}

$row = db_fetch_array( $result );

$g_cache_custom_field[$c_field_id] = $row;
$g_cache_name_to_id_map[$row['name']] = $c_field_id;

Expand Down Expand Up @@ -1120,12 +1120,12 @@ function custom_field_get_sequence( $p_field_id, $p_project_id ) {
project_id=" . db_param();
$result = db_query_bound( $query, Array( $c_field_id, $c_project_id ), 1 );

if( 0 == db_num_rows( $result ) ) {
$t_row = db_fetch_array( $result );

if( !$row ) {
return false;
}

$t_row = db_fetch_array( $result );

return $t_row['sequence'];
}

Expand Down
6 changes: 3 additions & 3 deletions application/core/filter_api.php
Expand Up @@ -4319,7 +4319,9 @@ function filter_cache_row( $p_filter_id, $p_trigger_errors = true ) {
WHERE id=' . db_param();
$result = db_query_bound( $query, Array( $c_filter_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
if( $p_trigger_errors ) {
error_parameters( $p_filter_id );
trigger_error( ERROR_FILTER_NOT_FOUND, ERROR );
Expand All @@ -4328,8 +4330,6 @@ function filter_cache_row( $p_filter_id, $p_trigger_errors = true ) {
}
}

$row = db_fetch_array( $result );

$g_cache_filter[$c_filter_id] = $row;

return $row;
Expand Down
5 changes: 3 additions & 2 deletions application/core/news_api.php
Expand Up @@ -172,10 +172,11 @@ function news_get_row( $p_news_id ) {
WHERE id=" . db_param();
$result = db_query_bound( $query, Array( $c_news_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
trigger_error( ERROR_NEWS_NOT_FOUND, ERROR );
} else {
$row = db_fetch_array( $result );
return $row;
}
}
Expand Down
7 changes: 4 additions & 3 deletions application/core/sponsorship_api.php
Expand Up @@ -90,7 +90,9 @@ function sponsorship_cache_row( $p_sponsorship_id, $p_trigger_errors = true ) {
WHERE id=" . db_param();
$result = db_query_bound( $query, Array( $c_sponsorship_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
$g_cache_sponsorships[$c_sponsorship_id] = false;

if( $p_trigger_errors ) {
Expand All @@ -100,8 +102,7 @@ function sponsorship_cache_row( $p_sponsorship_id, $p_trigger_errors = true ) {
return false;
}
}

$row = db_fetch_array( $result );

$g_cache_sponsorships[$c_sponsorship_id] = $row;

return $row;
Expand Down
10 changes: 6 additions & 4 deletions application/core/tag_api.php
Expand Up @@ -245,10 +245,11 @@ function tag_get( $p_tag_id ) {
WHERE id=" . db_param();
$result = db_query_bound( $query, Array( $c_tag_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
return false;
}
$row = db_fetch_array( $result );

return $row;
}
Expand All @@ -265,10 +266,11 @@ function tag_get_by_name( $p_name ) {
WHERE " . db_helper_like( 'name' );
$result = db_query_bound( $query, Array( $p_name ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
return false;
}
$row = db_fetch_array( $result );

return $row;
}
Expand Down
15 changes: 8 additions & 7 deletions application/core/user_api.php
Expand Up @@ -675,10 +675,11 @@ function user_get_id_by_email( $p_email ) {
WHERE email=" . db_param();
$result = db_query_bound( $query, Array( $p_email ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
return false;
} else {
$row = db_fetch_array( $result );
user_cache_database_result( $row );
return $row['id'];
}
Expand All @@ -698,10 +699,11 @@ function user_get_id_by_realname( $p_realname ) {
WHERE realname=" . db_param();
$result = db_query_bound( $query, Array( $p_realname ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
return false;
} else {
$row = db_fetch_array( $result );
user_cache_database_result( $row );
return $row['id'];
}
Expand Down Expand Up @@ -1167,12 +1169,11 @@ function user_get_profile_row( $p_user_id, $p_profile_id ) {
user_id=" . db_param();
$result = db_query_bound( $query, Array( $c_profile_id, $c_user_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );
if( !$row ) {
trigger_error( ERROR_USER_PROFILE_NOT_FOUND, ERROR );
}

$row = db_fetch_array( $result );

return $row;
}

Expand Down
6 changes: 3 additions & 3 deletions application/core/user_pref_api.php
Expand Up @@ -189,7 +189,9 @@ function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS, $p_trigg
WHERE user_id=" . db_param() . " AND project_id=" . db_param();
$result = db_query_bound( $query, Array( (int)$p_user_id, (int)$p_project_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
if( $p_trigger_errors ) {
trigger_error( ERROR_USER_PREFS_NOT_FOUND, ERROR );
} else {
Expand All @@ -198,8 +200,6 @@ function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS, $p_trigg
}
}

$row = db_fetch_array( $result );

if( !isset( $g_cache_user_pref[(int)$p_user_id] ) ) {
$g_cache_user_pref[(int)$p_user_id] = array();
}
Expand Down
5 changes: 3 additions & 2 deletions application/core/version_api.php
Expand Up @@ -114,7 +114,9 @@ function version_cache_row( $p_version_id, $p_trigger_errors = true ) {
WHERE id=" . db_param();
$result = db_query_bound( $query, Array( $c_version_id ) );

if( 0 == db_num_rows( $result ) ) {
$row = db_fetch_array( $result );

if( !$row ) {
$g_cache_versions[$c_version_id] = false;

if( $p_trigger_errors ) {
Expand All @@ -125,7 +127,6 @@ function version_cache_row( $p_version_id, $p_trigger_errors = true ) {
}
}

$row = db_fetch_array( $result );
$g_cache_versions[$c_version_id] = $row;

return $row;
Expand Down

0 comments on commit 087c44a

Please sign in to comment.