View Issue Details

IDProjectCategoryView StatusLast Update
0007974mantisbtdb mssqlpublic2014-05-16 15:00
Reporterobouillaud Assigned Torombert  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionduplicate 
PlatformIIS 6.0 - PHP 4OSWindowsOS Version2003
Product Version1.0.7 
Summary0007974: Date problem on french MSSQL
Description

Hi

I tried to install 1.0.7 (and then 1.1.0a3) but it always crashs when trying to insert the first line into "mantis_user_table" because of a date problem. I use MS SQL Server 2005 (french)

The query is :
INSERT INTO mantis_user_table(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES ('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', '2007-05-16 10:40:25', '2007-05-16 10:40:25', 1, 0, 90, 3, 0, 0, '11b924e05cd5153cae6b6351cc4e21f7dd12fa6015b160166e3f91f74d438259')

The error reported in mantis is just "the instruction has been stopped" (in french) but when I manualy execute the query in MS SQL Management studio the detailed error is "the conversion of a datatype 'CHAR' into 'DATETIME' has given an out of limit date and time value" (in french).

It seems that it comes from the date format, when I reverse the month and the day in the dates, it works.

TagsNo tags attached.
Attached Files
user_api.diff (1,097 bytes)   
Index: user_api.php
===================================================================
--- user_api.php	(revision 4914)
+++ user_api.php	(working copy)
@@ -440,9 +440,19 @@
 				    ( username, email, password, date_created, last_visit,
 				     enabled, access_level, login_count, cookie_string, realname )
 				  VALUES
-				    ( '$c_username', '$c_email', '$c_password', " . db_now() . "," . db_now() . ",
-				     $c_enabled, $c_access_level, 0, '$t_cookie_string', '$c_realname')";
-		db_query( $query );
+				    ( " . db_param(0) . ",
+				      " . db_param(1) . ",
+				      " . db_param(2) . ",
+				      " . db_param(3) . ",
+				      " . db_param(4) . ",
+				      " . db_param(5) . ",
+				      " . db_param(6) . ",
+				      " . db_param(7) . ",
+				      " . db_param(8) . ",
+				      " . db_param(9) . "
+					)";
+		db_query_bound( $query, Array( $c_username, $c_email, $c_password, db_now(), db_now(), 
+					$c_enabled, $c_access_level, 0, $t_cookie_string, $c_realname) );
 
 		# Create preferences for the user
 		$t_user_id = db_insert_id( $t_user_table );
user_api.diff (1,097 bytes)   

Relationships

duplicate of 0007905 closeddregad Install check failed 

Activities

obouillaud

obouillaud

2007-05-16 05:28

reporter   ~0014540

Last edited: 2007-05-16 05:36

It seems that the datetime format can differ from a server to another... but I see nothing in MS SQL Administrator to define a specific format for a whole database, a table or even a table field.

You could tell that it is a mssql problem but it seems that it can be avoid by using the command :
"SET DATEFORMAT YMD"
before executing queries that involves dates. It specifies that the format of the datetime field respects the ISO format :"yyyy-mm-dd hh:mm:ss"
(I tried in SQL Management Studio : it works)
Another solution could be to cast every datetime to be sure of its format or use the odbc notation : {ts 'yyyy-mm-dd hh:mm:ss'}

dadler

dadler

2007-07-19 10:53

reporter   ~0015105

We have had the same problem in German MSSql environment.

Our quick and dirty fix was to modify the database connect functions. We added in configuration files the entry "$g_db_session_init = 'SET DATEFORMAT YMD';" and expanded the database connect functions. See below:

File: $Id: database_api.php,v 1.55 2007/04/22 07:45:34 vboctor Exp $

# Make a connection to the database
function db_connect( $p_dsn, $p_hostname = null, $p_username = null, $p_password = null, $p_database_name = null ) {
    global $g_db_connected, $g_db, $g_db_session_init; // modified

    if(  $p_dsn === false ) {
        $g_db = ADONewConnection( config_get_global( 'db_type' ) );
        $t_result = $g_db->Connect($p_hostname, $p_username, $p_password, $p_database_name );
    } else {
        $g_db = ADONewConnection( $p_dsn );
        $t_result = $g_db->IsConnected();
    }

    if ( !$t_result ) {
        db_error();
        trigger_error( ERROR_DB_CONNECT_FAILED, ERROR );
        return false;
    }

    $g_db_connected = true;

    // ****************************************************************
    // modified
    // ****************************************************************
    if ( $g_db_session_init !='') {
        db_query( $g_db_session_init );
    }

    return true;
}

# --------------------
# Make a persistent connection to the database
function db_pconnect( $p_dsn, $p_hostname = null, $p_username = null, $p_password = null, $p_database_name = null ) {
    global $g_db_connected, $g_db, $g_db_session_init; // modified

    if(  $p_dsn === false ) {
        $g_db = ADONewConnection( config_get_global( 'db_type' ) );
        $t_result = $g_db->PConnect($p_hostname, $p_username, $p_password, $p_database_name );
    } else {
        $g_db = ADONewConnection( $p_dsn );
        $t_result = $g_db->IsConnected();
    }

    if ( !$t_result ) {
        db_error();
        trigger_error( ERROR_DB_CONNECT_FAILED, ERROR );
        return false;
    }
    $g_db_connected = true;

    // ****************************************************************
    // modifiziert
    // ****************************************************************
    if ( $g_db_session_init !='') {
        db_query( $g_db_session_init );
    }

    return true;
}
vboctor

vboctor

2007-11-10 15:19

manager   ~0016148

Reminder sent to: paulr

Paul, are you able to handle this issue?

davide73italy

davide73italy

2007-11-26 09:50

reporter   ~0016287

I think that using ODBC notation {ts 'yyyy-mm-dd hh:mm:ss'} is the best solution.

NT

NT

2008-01-17 16:57

reporter   ~0016706

Last edited: 2008-01-17 17:09

I also get this error using mysql in Mantis 1.2 but not in 1.1

The difference appears to be :-
trunk (1.2)

--------------------

# return current timestamp for DB
function db_now() {
    global $g_db;

    return $g_db->DBTimeStamp(time());
}

1.1

--------------------

# return current timestamp for DB
function db_now() {
    global $g_db;

    return $g_db->DBTimeStamp(time());
}

Changing to use the 1.1 code cures the insert into mantis_user_table (uses db_query),
but I then get an error inserting into mantis_email_table (uses db_query_bound).

Nick

NT

NT

2008-01-20 15:52

reporter   ~0016728

I changed to using db_query_bound and it works with mysql
Test done :-
added user into mysql database using European date format on 20th of Jan.

I am attaching my patched code.
This needs testing using other databases (and other non-US date formats ?).

vboctor

vboctor

2009-05-20 03:11

manager   ~0021859

I've checked the latest code and it seems that we already use db_query_bound() here? Is the issue still reproducible on the latest code?

I've noticed that there is still once db_query() in this file in method user_get_logged_in_user_ids(). However, this is another issue.

For now I will target this for 1.x.x rather than 1.2.x.

grangeway

grangeway

2014-05-16 15:00

reporter   ~0040380

MantisBT currently supports Mysql and has support for other database engines.

The support for other databases is known to be problematic.

Having implemented the current database layer into Mantis 10 years ago, I'm currently working on replacing the current layer.

If you are interested in using Mantis with non-mysql databases - for example, Oracle, PGSQL or MSSQL, and would be willing to help out testing the new database layer, please drop me an email at paul@mantisforge.org

In the meantime, I'd advise running Mantis with Mysql Only to avoid issues.

Thanks
Paul