SQL for TAGs provides wrong keys

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
us3r
Posts: 4
Joined: 16 May 2012, 12:55

SQL for TAGs provides wrong keys

Post by us3r »

Hello,

I successfully installed MantisBT Version 1.2.10 using MSSQL and am at the moment busy configuring it to my needs.

One feature I definitely want to use is tagging.

I can create tags in
Manage -> Manage Tags
without problems. There appears a new entry in the available tags which looks like:

Code: Select all

Name   Creator   Date Created       Last Updated 
       user0     1970-01-01 01:00   1970-01-01 01:00 
I cannot change it, as the link for changing would be the name which is not there.


In the detail view of a Ticket the 'existing tags' drop down is empty. I can enter manually tags and assign them to the Ticket, they are assigned correctly.



I started to debug, and the problem seems to be core/tag_api.php line 236 - 239

Code: Select all

  $t_query = "SELECT * FROM $t_tag_table
		$t_where ORDER BY name";
	
  $t_result = db_query_bound( $t_query, $t_where_params, $p_count, $p_offset);
I added

Code: Select all

  foreach ( $t_result as $res ) 
  {
    echo "<pre>";
    print_r( $res );
    echo "</pre>";
  }
which gives me as a result

Array
(
[0] => 1
[1] => 2
[2] => test
[3] => test
[4] => 1338816196
[5] => 1338816196
)

In manage_tags_page.php for example, the returned result from tag_api.php is used as follows:

Code: Select all

  $t_tag_row['name']
  $t_tag_row['description']  
  $t_tag_row['id']
  $t_tag_row['user_id']
  $t_tag_row['date_created']
  $t_tag_row['date_updated'] 
After I added the following code in manage_tags_page.php before <!-- Tag Table Start -->

Code: Select all

  $t_tag_row['name']         = $t_tag_row[2];
  $t_tag_row['description']  = $t_tag_row[3];
  $t_tag_row['id']           = $t_tag_row[0];
  $t_tag_row['user_id']      = $t_tag_row[1];
  $t_tag_row['date_created'] = $t_tag_row[4];
  $t_tag_row['date_updated'] = $t_tag_row[5];
everything works fine when displaying the tags!


I guess I have the same problem in the 'existing tags' drop down in the detail view of Tickets.


Is this a problem of my setup?
Is this a problem of using MSSQL?

I am a bit at a loss now.

I could add my remapping of the result keys at all places where the displaying of tags does not work, but this does not sound like a good idea.

Is there a way to specify somewhere that SQL results are always returned with numeric and named keys?

Is there any other way to solve this?

I was not able to find this problem in this forum, the bug list or google.

Your help is very much appreciated.

Kind Regards

Us3r
atrol
Site Admin
Posts: 8553
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: SQL for TAGs provides wrong keys

Post by atrol »

Please use Search before posting and read the Manual
us3r
Posts: 4
Joined: 16 May 2012, 12:55

Re: SQL for TAGs provides wrong keys

Post by us3r »

Okay, I made a little progress.

First, I updated to 1.2.11 (although I do not know if this had any effect).

I set
define('ADODB_FETCH_ASSOC',2);
to
define('ADODB_FETCH_ASSOC',1);
in library/adodb/adodb.inc.php line 110.

This made the table in
Manage -> Manage Tags
work, all the columns are filled with the correct values of existing tags (inlcuding the name, allowing now to change tags or their description).


Still, in view.php the drop down field for tag selection shows only 'Existing Tags'.

When I look into the source code I find:

Code: Select all

<option value="0">Existing tags</option><p style="color:red">
SYSTEM WARNING: 'Invalid argument supplied for foreach()' in 'C:\[...]mantis\core\print_api.php' line 321</p>
So here the problem seems to be with

Code: Select all

$query = "SELECT t.id FROM $t_tag_table t
LEFT JOIN $t_bug_tag_table b ON t.id=b.tag_id
WHERE b.bug_id IS NULL OR b.bug_id != " . db_param();
in tag_api.php line 468.

What I cannot understand, as soon as I change this SQL, like

Code: Select all

$query = "SELECT t.id FROM $t_tag_table t
LEFT JOIN $t_bug_tag_table b ON t.id=b.tag_id
WHERE b.bug_id IS NULL ";
or

Code: Select all

$query = "SELECT t.id FROM $t_tag_table t
LEFT JOIN $t_bug_tag_table b ON t.id=b.tag_id
WHERE b.bug_id IS NULL OR b.bug_id != 1";
I receive the error:
Database query failed. Error received from database was #2812: Could not find stored procedure 'NE'. for the query: SELECT t.id FROM mantis_tag_table t
LEFT JOIN mantis_bug_tag_table b ON t.id=b.tag_id
WHERE b.bug_id IS NULL OR b.bug_id != 1.


Has anybody any idea what this hints at? When I use the second query ( OR b.bug_id != 1 ) directly in the database I get a result.

db_param() returns '?'. When I run the query "OR b.bug_id != ?" directly in the database I also get an error. Is this an MSSQL problem?

I would really appreciate any hints.

Kind Regards

Us3r
Post Reply