View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0007616 | mantisbt | db postgresql | public | 2006-11-28 08:51 | 2014-05-16 15:02 |
Reporter | gerb42 | Assigned To | grangeway | ||
Priority | normal | Severity | crash | Reproducibility | always |
Status | closed | Resolution | no change required | ||
Platform | Intel | OS | Windows | OS Version | 2003 Server |
Product Version | 1.1.0a1 | ||||
Summary | 0007616: Can't create tables on postgresql | ||||
Description | Just tried to get mantis 1.1.0a1 running with pgsql 8.2 rc1 as backend. This fails for several tables stating that integer value 0 is not a suitable default for a boolean column. However, it does work with 1.0.6 so there must be something broken between the two. | ||||
Steps To Reproduce | Install 1.1.0a1 as specified using a pgsql backend (I think any 8.x should behave the same) | ||||
Tags | patch | ||||
Attached Files | fix_user_management.diff (2,856 bytes)
Index: manage_user_update.php =================================================================== --- manage_user_update.php (revision 5530) +++ manage_user_update.php (working copy) @@ -56,7 +56,7 @@ # strip extra space from real name $t_realname = preg_replace('/\s+/', ' ', $f_realname); - + user_ensure_name_valid( $f_username ); user_ensure_realname_valid( $f_realname ); user_ensure_realname_unique( $f_username, $f_realname ); @@ -66,7 +66,7 @@ email_ensure_not_disposable( $f_email ); $c_email = $f_email; - $c_username = $t_username; + $c_username = $f_username; $c_realname = $f_realname; $c_protected = db_prepare_bool( $f_protected ); $c_enabled = db_prepare_bool( $f_enabled ); Index: core/database_api.php =================================================================== --- core/database_api.php (revision 5530) +++ core/database_api.php (working copy) @@ -445,11 +445,11 @@ * @param string $p_table a valid database table name * @return int last successful insert id */ - function db_insert_id($p_table = null) { + function db_insert_id($p_table = null, $p_field = "id") { global $g_db; if ( isset($p_table) && db_is_pgsql() ) { - $query = "SELECT currval('".$p_table."_id_seq')"; + $query = "SELECT currval('".$p_table."_".$p_field."_seq')"; $result = db_query_bound( $query ); return db_result($result); } @@ -713,7 +713,26 @@ * @todo Use/Behaviour of this function should be reviewed before 1.2.0 final */ function db_prepare_bool( $p_bool ) { - return (int)(bool)$p_bool; + $t_db_type = config_get_global( 'db_type' ); + + switch( $t_db_type ) { + case 'postgres': + case 'postgres64': + case 'postgres7': + case 'pgsql': + if( $p_bool ) + { + return 'true'; + } + else + { + return 'false'; + } + break; + default: + return (int)(bool)$p_bool; + break; + } } /** Index: core/email_queue_api.php =================================================================== --- core/email_queue_api.php (revision 5530) +++ core/email_queue_api.php (working copy) @@ -91,7 +91,7 @@ )"; db_query_bound( $query, Array( $c_email, $c_subject, $c_body, db_now(), $c_metadata ) ); - return db_insert_id( $t_email_table ); + return db_insert_id( $t_email_table, "email_id" ); } # -------------------- Index: core/user_api.php =================================================================== --- core/user_api.php (revision 5530) +++ core/user_api.php (working copy) @@ -460,7 +460,7 @@ # Users are added with protected set to FALSE in order to be able to update # preferences. Now set the real value of protected. if ( $c_protected ) { - user_set_field( $t_user_id, 'protected', 1 ); + user_set_field( $t_user_id, 'protected', $c_protected ); } # Send notification email ncmichiel_7616.diff (6,524 bytes)
--- ../sources/mantisbt-1.1.6/admin/schema.php 2008-12-09 20:20:28.000000000 +0100 +++ admin/schema.php 2009-04-15 11:54:36.000000000 +0200 @@ -104,7 +104,7 @@ view_state I2 NOTNULL DEFAULT '10', summary C(128) NOTNULL DEFAULT \" '' \", sponsorship_total I NOTNULL DEFAULT '0', - sticky L NOTNULL DEFAULT '0' + sticky L NOTNULL DEFAULT 0 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS'))); $upgrade[] = Array('CreateIndexSQL',Array('idx_bug_sponsorship_total',config_get('mantis_bug_table'),'sponsorship_total')); $upgrade[] = Array('CreateIndexSQL',Array('idx_bug_fixed_in_version',config_get('mantis_bug_table'),'fixed_in_version')); @@ -155,15 +155,15 @@ access_level_rw I2 NOTNULL DEFAULT '0', length_min I NOTNULL DEFAULT '0', length_max I NOTNULL DEFAULT '0', - advanced L NOTNULL DEFAULT '0', - require_report L NOTNULL DEFAULT '0', - require_update L NOTNULL DEFAULT '0', - display_report L NOTNULL DEFAULT '1', - display_update L NOTNULL DEFAULT '1', - require_resolved L NOTNULL DEFAULT '0', - display_resolved L NOTNULL DEFAULT '0', - display_closed L NOTNULL DEFAULT '0', - require_closed L NOTNULL DEFAULT '0' + advanced L NOTNULL DEFAULT 0, + require_report L NOTNULL DEFAULT 0, + require_update L NOTNULL DEFAULT 0, + display_report L NOTNULL DEFAULT 1, + display_update L NOTNULL DEFAULT 1, + require_resolved L NOTNULL DEFAULT 0, + display_resolved L NOTNULL DEFAULT 0, + display_closed L NOTNULL DEFAULT 0, + require_closed L NOTNULL DEFAULT 0 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS'))); $upgrade[] = Array('CreateIndexSQL',Array('idx_custom_field_name',config_get('mantis_custom_field_table'),'name')); $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_filters_table')," @@ -181,7 +181,7 @@ date_posted T NOTNULL DEFAULT '1970-01-01 00:00:01', last_modified T NOTNULL DEFAULT '1970-01-01 00:00:01', view_state I2 NOTNULL DEFAULT '10', - announcement L NOTNULL DEFAULT '0', + announcement L NOTNULL DEFAULT 0, headline C(64) NOTNULL DEFAULT \" '' \", body XL NOTNULL ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS'))); @@ -211,7 +211,7 @@ id I UNSIGNED PRIMARY NOTNULL AUTOINCREMENT, name C(128) NOTNULL DEFAULT \" '' \", status I2 NOTNULL DEFAULT '10', - enabled L NOTNULL DEFAULT '1', + enabled L NOTNULL DEFAULT 1, view_state I2 NOTNULL DEFAULT '10', access_min I2 NOTNULL DEFAULT '10', file_path C(250) NOTNULL DEFAULT \" '' \", @@ -232,7 +232,7 @@ version C(64) NOTNULL DEFAULT \" '' \", date_order T NOTNULL DEFAULT '1970-01-01 00:00:01', description XL NOTNULL, - released L NOTNULL DEFAULT '1' + released L NOTNULL DEFAULT 1 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS'))); $upgrade[] = Array('CreateIndexSQL',Array('idx_project_version',config_get('mantis_project_version_table'),'project_id,version',Array('UNIQUE'))); $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_sponsorship_table')," @@ -242,7 +242,7 @@ amount I NOTNULL DEFAULT '0', logo C(128) NOTNULL DEFAULT \" '' \", url C(128) NOTNULL DEFAULT \" '' \", - paid L NOTNULL DEFAULT '0', + paid L NOTNULL DEFAULT 0, date_submitted T NOTNULL DEFAULT '1970-01-01 00:00:01', last_updated T NOTNULL DEFAULT '1970-01-01 00:00:01' ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS'))); @@ -262,21 +262,21 @@ project_id I UNSIGNED NOTNULL DEFAULT '0', default_profile I UNSIGNED NOTNULL DEFAULT '0', default_project I UNSIGNED NOTNULL DEFAULT '0', - advanced_report L NOTNULL DEFAULT '0', - advanced_view L NOTNULL DEFAULT '0', - advanced_update L NOTNULL DEFAULT '0', + advanced_report L NOTNULL DEFAULT 0, + advanced_view L NOTNULL DEFAULT 0, + advanced_update L NOTNULL DEFAULT 0, refresh_delay I NOTNULL DEFAULT '0', - redirect_delay L NOTNULL DEFAULT '0', + redirect_delay L NOTNULL DEFAULT 0, bugnote_order C(4) NOTNULL DEFAULT 'ASC', - email_on_new L NOTNULL DEFAULT '0', - email_on_assigned L NOTNULL DEFAULT '0', - email_on_feedback L NOTNULL DEFAULT '0', - email_on_resolved L NOTNULL DEFAULT '0', - email_on_closed L NOTNULL DEFAULT '0', - email_on_reopened L NOTNULL DEFAULT '0', - email_on_bugnote L NOTNULL DEFAULT '0', - email_on_status L NOTNULL DEFAULT '0', - email_on_priority L NOTNULL DEFAULT '0', + email_on_new L NOTNULL DEFAULT 0, + email_on_assigned L NOTNULL DEFAULT 0, + email_on_feedback L NOTNULL DEFAULT 0, + email_on_resolved L NOTNULL DEFAULT 0, + email_on_closed L NOTNULL DEFAULT 0, + email_on_reopened L NOTNULL DEFAULT 0, + email_on_bugnote L NOTNULL DEFAULT 0, + email_on_status L NOTNULL DEFAULT 0, + email_on_priority L NOTNULL DEFAULT 0, email_on_priority_min_severity I2 NOTNULL DEFAULT '10', email_on_status_min_severity I2 NOTNULL DEFAULT '10', email_on_bugnote_min_severity I2 NOTNULL DEFAULT '10', @@ -309,8 +309,8 @@ password C(32) NOTNULL DEFAULT \" '' \", date_created T NOTNULL DEFAULT '1970-01-01 00:00:01', last_visit T NOTNULL DEFAULT '1970-01-01 00:00:01', - enabled L NOTNULL DEFAULT '1', - protected L NOTNULL DEFAULT '0', + enabled L NOTNULL DEFAULT 1, + protected L NOTNULL DEFAULT 0, access_level I2 NOTNULL DEFAULT '10', login_count I NOTNULL DEFAULT '0', lost_password_request_count I2 NOTNULL DEFAULT '0', @@ -323,7 +323,7 @@ $upgrade[] = Array('CreateIndexSQL',Array('idx_access',config_get('mantis_user_table'),'access_level')); $upgrade[] = Array('InsertData', Array( config_get('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', " . db_now() . ", " . db_now() . ", 1, 0, 90, 3, 0, 0, '" . + ('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', " . db_now() . ", " . db_now() . ", true, false, 90, 3, 0, 0, '" . md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) ); $upgrade[] = Array('AlterColumnSQL', Array( config_get( 'mantis_bug_history_table' ), "old_value C(255) NOTNULL" ) ); $upgrade[] = Array('AlterColumnSQL', Array( config_get( 'mantis_bug_history_table' ), "new_value C(255) NOTNULL" ) ); mantisbt-svn5752.register-user-on-postgresql.patch (2,382 bytes)
diff -ruaN mantisbt-svn5752.orig/core/database_api.php mantisbt-svn5752/core/database_api.php --- mantisbt-svn5752.orig/core/database_api.php 2008-10-11 00:10:54.000000000 +0300 +++ mantisbt-svn5752/core/database_api.php 2009-05-16 19:16:50.000000000 +0300 @@ -285,6 +285,8 @@ for( $i = 0;$i < $params;$i++ ) { if( $arr_parms[$i] === false ) { $arr_parms[$i] = 0; + } else if( $arr_parms[$i] === true ) { + $arr_parms[$i] = 1; } } } @@ -462,11 +464,11 @@ * @param string $p_table a valid database table name * @return int last successful insert id */ -function db_insert_id( $p_table = null ) { +function db_insert_id($p_table = null, $p_field = "id") { global $g_db; if( isset( $p_table ) && db_is_pgsql() ) { - $query = "SELECT currval('" . $p_table . "_id_seq')"; + $query = "SELECT currval('".$p_table."_".$p_field."_seq')"; $result = db_query_bound( $query ); return db_result( $result ); } @@ -739,7 +741,20 @@ * @todo Use/Behaviour of this function should be reviewed before 1.2.0 final */ function db_prepare_bool( $p_bool ) { - return (int) (bool) $p_bool; + if (db_is_pgsql()) { + if( $p_bool ) + { + return 'true'; + } + else + { + return 'false'; + } + } + else + { + return (int)(bool)$p_bool; + } } /** diff -ruaN mantisbt-svn5752.orig/core/email_queue_api.php mantisbt-svn5752/core/email_queue_api.php --- mantisbt-svn5752.orig/core/email_queue_api.php 2008-10-11 00:10:54.000000000 +0300 +++ mantisbt-svn5752/core/email_queue_api.php 2009-05-16 18:26:06.000000000 +0300 @@ -88,7 +88,7 @@ )"; db_query_bound( $query, Array( $c_email, $c_subject, $c_body, db_now(), $c_metadata ) ); - return db_insert_id( $t_email_table ); + return db_insert_id( $t_email_table, "email_id" ); } function email_queue_row_to_object( $p_row ) { diff -ruaN mantisbt-svn5752.orig/core/user_api.php mantisbt-svn5752/core/user_api.php --- mantisbt-svn5752.orig/core/user_api.php 2008-10-25 19:32:32.000000000 +0300 +++ mantisbt-svn5752/core/user_api.php 2009-05-16 18:25:32.000000000 +0300 @@ -469,7 +469,7 @@ # Users are added with protected set to FALSE in order to be able to update # preferences. Now set the real value of protected. if( $c_protected ) { - user_set_field( $t_user_id, 'protected', 1 ); + user_set_field( $t_user_id, 'protected', $c_protected ); } # Send notification email mantisbt-svn5752.lost_pwd.patch (650 bytes)
--- mantisbt-svn5752.orig/lost_pwd.php 2008-09-26 00:20:01.000000000 +0300 +++ mantisbt-svn5752/lost_pwd.php 2009-05-23 18:51:09.000000000 +0300 @@ -50,7 +50,7 @@ $t_user_table = db_get_table( 'mantis_user_table' ); # @@@ Consider moving this query to user_api.php - $query = 'SELECT id FROM ' . $t_user_table . ' WHERE username = ' . db_param() . ' AND email = ' . db_param() . ' AND enabled=1'; + $query = 'SELECT id FROM ' . $t_user_table . ' WHERE username = ' . db_param() . ' AND email = ' . db_param() . ' AND enabled=\'1\''; $result = db_query_bound( $query, Array( $f_username, $f_email ) ); if ( 0 == db_num_rows( $result ) ) { | ||||
I am suspecting this bug maybe related to the upgrade of ADODB. You might want to try getting the ADODB version that is shipped with 1.0.6, put it in 1.1.0a1 and then try installing. |
|
Replaced directory adodb in core with the one from 1.0.6. Installation works now, but Database needs to be created manually with mantis user assigned full rights to DB. Now I get an error when creating a new user stating that Sequence 'mantis_email_table_id_seq' does not exist. In pgAdmin I found a Sequence 'mantis_email_table_email_id_seq' instead. After manually creating the first Sequence I get the following Message: "Database query failed. Error received from database was #-1: ERROR: currval of sequence "mantis_email_table_id_seq" is not yet defined in this session for the query: SELECT currval('mantis_email_table_id_seq')" Looks like some inconsistent naming to me. |
|
Hi, The problem is that PostgreSQLsequences are created like tablename_primarykeyname_seq for serial fields which for the mantis_email_table table gives us mantis_email_table_email_id_seq. It's not consistent with the code in db_insert_id which adds a id_seq to the name of the table so it requires the following name for the sequence: mantis_email_table_id_seq. The current code and schema have the following behaviour:
IMHO the only way to fix this problem without changing too much the existing API is to rename the email_id field of mantis_email_table to id. So that the sequence created by PostgreSQL will be named mantis_email_table_id_seq. Any comment? |
|
Agreed that the easiest fix would be to rename the email_id field to id. |
|
I think we should use the fix on the following forum thread: |
|
Fix certainly helps... $150 for you if you solve PosgreSQL related problems... |
|
This fix worked for me as well, mantis 1.1.1, pgsql 8.2. Would love to see it get rolled into the main package. |
|
Hello all, I think most of the postgres issues have been resolved in the latest SVN trunk from http://mantisbt.svn.sourceforge.net/viewvc/mantisbt/trunk/mantisbt/ [^] If one of you could test the latest SVN code to see if it improves the support for postgres, it would be appreciated. Paul |
|
testing 1.1.2 on gentoo... doesn't work... part of it seems to be in the create tables when the column is type BOOL the DEFAULT should be '0' not 0 as it is representative of the character not the integer. the value FALSE would also work. |
|
The same error exists in 1.2.0a1. |
|
Hello I'm new to Mantis. We testing it against PostgreSQL 8.2 for future production deployment. I'm still studying how Mantis is designed and how it works, but I've created and attached patch which fixes most problems with 'Manage Users'. But especially that bool problem is more related to adodb than mantis database_api.php I think (but I've fixed it in database_api.php). Excuse my English and dirty places in patch. It's against latest trunk from svn. |
|
Is there a nicer fix than the one from forums? If not I could probably look at it and post a patch... |
|
@blami: (about the attached patch) db_prepare_bool() can't return true/false because boolean fields that were created sometimes prior to 1.2 are in the database as type smallint (see 0009806:0019866). I propose returning strings "'0'" and "'1'" which works for both boolean's and smallint's. But then all the code needs to be scrubbed to eliminate usage like this, from filter_api.php, filter_db_get_available_queries(): (db_prepare_bool() should ONLY be used to construct a query; and only be called with one argument, not two like in filter_db_set_for_current_user() in the same file, but I digress...) [the code I'm commenting on is svn r5751] Alternatively, the change to real true/false can be made in the next major release, with the installer changing types from smallint to boolean. And conversely, anyone having a problem with booleans now, can change the type to smallint, which seems to work for me: ALTER TABLE t ALTER COLUMN b TYPE smallint USING CASE WHEN b THEN 1 WHEN NOT b THEN 0 ELSE null END; |
|
I think current 1.2.0 git trunk fixes most pgsql issues. I'm currently running my dev instance of mantis on a pgsql db. Paul |
|
Hello all, The latest nightly builds at http://www.mantisbt.org/builds/ should fix most of the postgres issues Let me know how you get on. THanks |
|
Paul, what about 0009720? |
|
Hi, The nightly builds do not fix my problems. I can get the thing to create tables by changing a lot of lines in admin/schema.php: L NOTNULL DEFAULT '1' -> L NOTNULL DEFAULT true But this breaks the file for mysql |
|
The attached file ncmichiel_7616.diff fixes the issue of table creation in mantis 1.1.6 Works for postgresql and mysql |
|
ncmichiel, Which nightly build file are you trying to use? Paul |
|
I tried nightly build mantisbt-1.1.6-2009-04-15-master Just tested against git trunk, all works fine there. |
|
'mantisbt-svn5752.register-user-on-postgresql.patch' - reworked 'fix_user_management.diff' patch to current SVN revision. New user registering work fine, but password request still broken. 'mantisbt-svn5752.lost_pwd.patch' - fixed password requests. |
|
Ok. I've tested it only-that on 'mantisbt-1.2.0a3'. In this version all work fine without any patches. Thank you. |
|
Note: development moved to git ( http://git.mantisbt.org/ ) so svn 5752 is about 6 months out of date. Paul |
|
Marking this as resolved - pgsql support should be fine in 1.2 rc Paul |
|
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 |
|