View Issue Details

IDProjectCategoryView StatusLast Update
0012571mantisbtdb mssqlpublic2014-12-08 00:33
Reporterottog Assigned Tograngeway  
PriorityhighSeveritymajorReproducibilityalways
Status closedResolutionfixed 
PlatformIISOSWindowsOS Version2003
Product Version1.2.3 
Target Version1.3.0-beta.1Fixed in Version1.3.0-beta.1 
Summary0012571: Some configuration options cannot be saved to MS SQL Server (fix attached)
Description

SQL Server is picky about data-type matching between SQL arguments and column types. This affected at least the saving of configuration options of type "int", as the code would try to update a "text" column using an "int" value.

The attached diff for config_api.php fixes the problem and also takes removes various calls to deprecated database functions.

As the actual column type is text, I cannot see how these changes could cause any problems for other, obviously less picky, database backends.

The str_replace() call for "float" options was inspired by a similar operation in adodb.inc.php said to counteract problems where regional settings cause floats to be converted to strings with commas as decimal separators -- I am not sure under what circumstances (PHP versions and regional settings) the precaution may actually be necessary but it cannot reasonably be harmful.

Also, I had previously done changes of a similar nature to tokens_api.php, so I attach a patch file for that as well, even though I do not remember any more exactly what SQL Server-related problem the changes fixed. But at the very least, the patch does away with deprecated function calls.

Tagspatch
Attached Files
config_api.diff (861 bytes)   
319c319
< 		$c_value = (float) $p_value;
---
> 		$c_value = str_replace( ',', '.', $p_value );
322c322
< 		$c_value = db_prepare_int( $p_value );
---
> 		$c_value = (string) $p_value;
325c325
< 		$c_value = $p_value;
---
> 		$c_value = (string) $p_value;
330,332c330,332
< 		$c_user = db_prepare_int( $p_user );
< 		$c_project = db_prepare_int( $p_project );
< 		$c_access = db_prepare_int( $p_access );
---
> 		$c_user = (int) $p_user;
> 		$c_project = (int) $p_project;
> 		$c_access = (int) $p_access;
458,459c458,459
< 		$c_user = db_prepare_int( $p_user );
< 		$c_project = db_prepare_int( $p_project );
---
> 		$c_user = (int) $p_user;
> 		$c_project = (int) $p_project;
482c482
< 	$c_user_id = db_prepare_int( $p_user_id );
---
> 	$c_user_id = (int) $p_user_id;
495c495
< 	$c_project = db_prepare_int( $p_project );
---
> 	$c_project = (int) $p_project;
config_api.diff (861 bytes)   
tokens_api.diff (1,912 bytes)   
37c37
< 	$c_token_id = db_prepare_int( $p_token_id );
---
> 	$c_token_id = (int) $p_token_id;
71,72c71,72
< 	$c_type = db_prepare_int( $p_type );
< 	$c_user_id = db_prepare_int( $p_user_id == null ? auth_get_current_user_id() : $p_user_id );
---
> 	$c_type =(int) $p_type;
> 	$c_user_id = (int) ( $p_user_id == null ? auth_get_current_user_id() : $p_user_id );
130c130
< 	$c_token_id = db_prepare_int( $p_token_id );
---
> 	$c_token_id = (int) $p_token_id;
149,150c149,150
< 	$c_type = db_prepare_int( $p_type );
< 	$c_user_id = db_prepare_int( $p_user_id == null ? auth_get_current_user_id() : $p_user_id );
---
> 	$c_type = (int) $p_type;
> 	$c_user_id = (int) ( $p_user_id == null ? auth_get_current_user_id() : $p_user_id );
170c170
< 		$c_user_id = db_prepare_int( $p_user_id );
---
> 		$c_user_id = (int) $p_user_id;
193,194c193,195
< 	$c_type = db_prepare_int( $p_type );
< 	$c_timestamp = db_now();
---
> 	$c_type = (int) $p_type;
>     $c_value = (string) $p_value;
>     $c_timestamp = db_now();
196c197
< 	$c_user_id = db_prepare_int( $p_user_id == null ? auth_get_current_user_id() : $p_user_id );
---
> 	$c_user_id = (int) ( $p_user_id == null ? auth_get_current_user_id() : $p_user_id );
203c204
< 	db_query_bound( $t_query, Array( $c_type, $p_value, $c_timestamp, $c_expiry, $c_user_id ) );
---
> 	db_query_bound( $t_query, Array( $c_type, $c_value, $c_timestamp, $c_expiry, $c_user_id ) );
216c217,218
< 	$c_token_id = db_prepare_int( $p_token_id );
---
> 	$c_token_id = (int) $p_token_id;
>     $c_value = (string) $p_value;
224c226
< 	db_query_bound( $t_query, Array( $p_value, $c_expiry, $c_token_id ) );
---
> 	db_query_bound( $t_query, Array( $c_value, $c_expiry, $c_token_id ) );
235c237
< 	$c_token_type = db_prepare_int( $p_token_type );
---
> 	$c_token_type = (int) $p_token_type;
259c261
< 		$c_token_type = db_prepare_int( $p_token_type );
---
> 		$c_token_type = (int) $p_token_type;
tokens_api.diff (1,912 bytes)   

Relationships

related to 0015721 closedgrangeway Functionality to consider porting to master-2.0.x 

Activities

grangeway

grangeway

2012-02-05 12:04

reporter   ~0031137

db_prepare_int has been removed in 1.3.x