View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0022208 | mantisbt | db mssql | public | 2017-01-16 04:06 | 2023-04-22 10:58 |
Reporter | Haplo | Assigned To | dregad | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | 1.3.0-beta.1 | ||||
Target Version | 1.3.9 | Fixed in Version | 1.3.9 | ||
Summary | 0022208: File upload to MS-SQL not working | ||||
Description | The file upload to the MS SQL database isn't working. To fix the Problem I've integrated the changes proposed by another user (don't remember who it was, sorry) and with it it is working. I've added my used MS SQL base script and the fixed file_api.php | ||||
Additional Information | Mantis 2.0.0 | ||||
Tags | No tags attached. | ||||
Attached Files | |||||
The attached patch file replaces the originally uploaded PHP file (file_api__fixed_upload_200.php). I had a quick look at the code (but didn't test as I don't have access to MSSQL). Looks like you're replacing a query parameter by inline value, so this is probably not the right fix for the problem. Probably better look into why the file contents are not being inserted. file_api_fixed_upload.patch (1,192 bytes)
diff --git a/core/file_api.php b/core/file_api.php index fef6404..4d816fd 100644 --- a/core/file_api.php +++ b/core/file_api.php @@ -795,7 +795,7 @@ function file_add( $p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p 'user_id' => (int)$p_user_id, ); # Oracle has to update BLOBs separately - if( !db_is_oracle() ) { + if( !db_is_oracle() && !db_is_mssql() ) { $t_param['content'] = $c_content; } $t_query_param = db_param(); @@ -803,10 +803,18 @@ function file_add( $p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p $t_query_param .= ', ' . db_param(); } - $t_query = 'INSERT INTO ' . $t_file_table . ' - ( ' . implode(', ', array_keys( $t_param ) ) . ' ) - VALUES - ( ' . $t_query_param . ' )'; + if ( !db_is_mssql() ) { + $t_query = 'INSERT INTO ' . $t_file_table . ' + ( ' . implode(', ', array_keys( $t_param ) ) . ' ) + VALUES + ( ' . $t_query_param . ' )'; + } else { + $t_query = 'INSERT INTO ' . $t_file_table . ' + ( ' . implode(', ', array_keys( $t_param ) ) . ', content ) + VALUES + ( ' . $t_query_param . ', ' . $c_content . ' )'; + } + db_query( $t_query, array_values( $t_param ) ); if( db_is_oracle() ) { |
|
I'm also not an PHP/SQL specialist, so am maybe not the right person for detailed php/SQL questions. |
|
@Haplo Did you check the 'bug_file_table' if the content field is really empty? I had an issue file_add(file_api.php) calls db_prepare_binary_string(database_api.php) for method=DATABASE, I simply commented out "case 'mssqlnative':" in that function to get it work, at least in my |
|
No sorry, I didn't actually check if it really was empty or not. |
|
I did a quick test for this and it looks like that is the problem. Here is the changed function I used: function db_prepare_binary_string( $p_string ) {
} |
|
I also had problems with File upload when upgrading an old Mantis installation to 2.0 (With MSSQL as our database). I noticed that the files uploaded become hex encoded twice. So to fix it I commented out this line. It is essentially the same fix as Haplo posted above. |
|
Had this problem as well, thank-you for posting the fix Haplo! |
|
The file upload is still not working in 2.1.0. |
|
Backported to 1.3.x and applied to supported 2.x branches. Thanks @obmsch |
|
MantisBT: master-1.3.x 43c4b6fb 2017-03-22 06:32 Committer: dregad Details Diff |
mssql: don't encode contents when uploading attachments Downloads are broken and inline preview doesn't work. Move "case 'mssqlnative':" down next to 'oci8' in db_prepare_binary_string (database_api) to effectively return the string unchanged via 'default:'. Adjust comment. Fixes 0022208 Signed-off-by: Damien Regad <dregad@mantisbt.org> |
Affected Issues 0022208 |
|
mod - core/database_api.php | Diff File | ||
MantisBT: master-2.1 b9fccabf 2017-03-22 06:32 Committer: dregad Details Diff |
mssql: don't encode contents when uploading attachments Downloads are broken and inline preview doesn't work. Move "case 'mssqlnative':" down next to 'oci8' in db_prepare_binary_string (database_api) to effectively return the string unchanged via 'default:'. Adjust comment. Fixes 0022208 Signed-off-by: Damien Regad <dregad@mantisbt.org> |
Affected Issues 0022208 |
|
mod - core/database_api.php | Diff File | ||
MantisBT: master-2.2 4a06c6e8 2017-03-22 06:32 Committer: dregad Details Diff |
mssql: don't encode contents when uploading attachments Downloads are broken and inline preview doesn't work. Move "case 'mssqlnative':" down next to 'oci8' in db_prepare_binary_string (database_api) to effectively return the string unchanged via 'default:'. Adjust comment. Fixes 0022208 Signed-off-by: Damien Regad <dregad@mantisbt.org> |
Affected Issues 0022208 |
|
mod - core/database_api.php | Diff File |