Tags:
create new tag
view all tags

Question

I am using the DatabasePlugin (version 1.3) and I am doing a "DATABASE_SQL_REPEAT". Within this "tag" I am doing a "DATABASE_SQL_TABLE".

When I do this, I use the result of the "repeat" as an input to the command in the "table" tag.

The problem is that the plugin doesn't seem to be expanding the %var% in the "table" tag. I was wondering if there was a way to do this.

A contrived example:

%DATABASE_SQL_REPEAT{description="db" columns="id, date" command="select id, date from atable where status='done'"}%

%date%

%DATABASE_SQL_TABLE{description="db" headers="Name, Details" command="select name, details from atable where id = %id% order by details desc"}%

%DATABASE_SQL_REPEAT%

So, in this example, the "%id%" is passed straight to the db, and this error is seen in the browser: DBD::mysql::st execute failed: You have an error in your SQL syntax near '%id% order by details desc' at line 1 at /usr/share/perl5/TWiki/Plugins/DatabasePlugin.pm line 336.

Environment

TWiki version: TWikiRelease01Feb2003
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin, DatabasePlugin
Server OS: Debian woody, kernel 2.4.18-bf2.4
Web server: Apache/1.3.26 (Unix) Debian GNU/Linux
Perl version: 5.6.1
Client OS:  
Web Browser:  

-- TrevorGlen - 15 May 2004

Answer

I fixed this by changing the order of evaluation in DatabasePlugin.pm:

574d573
<     $_[0] =~ s/%DATABASE_SQL_REPEAT{(.*?)}%(.*?)%DATABASE_SQL_REPEAT%/&do_sql_repeat($1, $2)/seog;
577a577
>     $_[0] =~ s/%DATABASE_SQL_REPEAT{(.*?)}%(.*?)%DATABASE_SQL_REPEAT%/&do_sql_repeat($1, $2)/seog;

This is not really an acceptable fix (eg if a DATABASE_SQL_REPEAT occurs within a DATABASE_REPEAT). I haven't thought about how to implement this properly, but it works for my purposes.

Should the status be changed to "AnsweredQuestions"?

-- TrevorGlen - 13 Aug 2004

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2004-08-13 - TrevorGlen
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.