View Issue Details

IDProjectCategoryView StatusLast Update
0007028mantisbtdb mssqlpublic2014-05-16 15:00
Reportervboctor Assigned Tovboctor  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.0.0rc3 
Fixed in Version1.0.3 
Summary0007028: Port: "Prune Accounts" function doesn't work with MS SQL
Description

I am running Mantis with MS SQL (because my manager says so, not out of choice :-), and testing has revealed that the "Prune Accounts" button on the "Manage Users" page doesn't work.

After looking at the code, this is because the SELECT statement for this function uses the MySQL-specific DB function "TO_DAYS".

I have edited the code to use the db_helper_compare_days function, which I found in the database_api.php file, and the Prune function now works correctly on MySQL and MS SQL systems (I have testing version of both).

There is also a note above the db_helper_compare_days function saying "Check if there is a way to do this using ADODB rather than implementing it here." (around line 329)

There is a way to do this using ADODB. Code follows. Which types of diff file would you like?

Drew

Additional Information

The original manage_user_prune.php code:

    # Delete the users who have never logged in and are older than 1 week
$days_old = 7;
$days_old = (integer)$days_old;
$query = "SELECT id
        FROM $t_user_table
        WHERE login_count=0 AND TO_DAYS(".db_now().") - '$days_old' > TO_DAYS(date_created)";
$result = db_query($query);

$count = db_num_rows( $result );

The newer version using db_helper_compare_days:

    # Delete the users who have never logged in and are older than 1 week
$days_old = 7;
$days_old = (integer)$days_old;
$date_calc = db_helper_compare_days(db_now(),"date_created","> $days_old");     
$query = "SELECT id
        FROM $t_user_table
            WHERE login_count=0 AND $date_calc";

$result = db_query($query);

$count = db_num_rows( $result );

The latest version using ADODB:

    # Delete the users who have never logged in and are older than 1 week
$days_old = 7;
$days_old = (integer)$days_old;
global $g_db;
$date_calc = $g_db->OffsetDate(-7) . "> date_created";

$query = "SELECT id
        FROM $t_user_table
                WHERE login_count=0 AND $date_calc";

$result = db_query($query);

$count = db_num_rows( $result );

TagsNo tags attached.

Relationships

child of 0006559 closedvboctor "Prune Accounts" function doesn't work with MS SQL 
child of 0006971 closedvboctor Mantis 1.0.3 Release 

Activities

grangeway

grangeway

2014-05-16 15:00

reporter   ~0040422

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