Skip to content

Commit

Permalink
Oracle: properly store file attachments as BLOBs
Browse files Browse the repository at this point in the history
Uses new db_update_blob() function, instead of relying on hex-encoding
the binary data and passing the resulting string to db_query_bound()
because this method limits the size of attachments to 4000 bytes.

Fixes #16336

Porting to 1.3 - Conflicts:
	core/file_api.php
  • Loading branch information
dregad committed Oct 16, 2013
1 parent f3552d4 commit b36ff70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
3 changes: 1 addition & 2 deletions core/database_api.php
Expand Up @@ -788,8 +788,7 @@ function db_prepare_binary_string( $p_string ) {
return $g_db->BlobEncode( $p_string );
break;
case 'oci8':
$content = unpack( "H*hex", $p_string );
return $content['hex'];
# Fall through, oci8 stores raw data in BLOB
default:
return $p_string;
break;
Expand Down
36 changes: 26 additions & 10 deletions core/file_api.php
Expand Up @@ -827,14 +827,10 @@ function file_add( $p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc
$t_file_table = db_get_table( $p_table . '_file' );
$t_id_col = $p_table . "_id";

$query = "INSERT INTO $t_file_table
( $t_id_col, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, user_id )
VALUES
( " . db_param() . ", " . db_param() . ", " . db_param() . ", "
. db_param() . ", " . db_param() . ", " . db_param() . ", "
. db_param() . ", " . db_param() . ", " . db_param() . ", "
. db_param() . ", " . db_param() . " )";
db_query_bound( $query, array(
$t_query_fields = "
$t_id_col, title, description, diskfile, filename, folder,
filesize, file_type, date_added, user_id";
$t_param = array(
$t_id,
$p_title,
$p_desc,
Expand All @@ -844,9 +840,29 @@ function file_add( $p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc
$t_file_size,
$p_file['type'],
$p_date_added,
$c_content,
(int)$p_user_id,
) );
);

# oci8 stores contents in a BLOB, which is updated separately
if( !db_is_oracle() ) {
$t_query_fields .= ", content";
$t_param[] = $c_content;
}

$t_query_param = db_param();
for( $i = 1; $i < count( $t_param ); $i++ ){
$t_query_param .= ", " . db_param();
}

$t_query = "INSERT INTO $t_file_table ( $t_query_fields )
VALUES
( $t_query_param )";

db_query_bound( $t_query, $t_param );

if( db_is_oracle() ) {
db_update_blob( $t_file_table, 'content', $c_content, "diskfile='$t_unique_name'" );
}

if( 'bug' == $p_table ) {
# update the last_updated date
Expand Down

0 comments on commit b36ff70

Please sign in to comment.