Posted on 2009-04-28
Last Modified: 2012-05-06

         I am using sql2wiki extension to retrieve data from sql table. Given a pagename "xyz", is it possible to use it as given in the page below such that the pagename matches the project name and yields result. The result i get is only the header of the table the records do not appear. What should I do.


<sql2wiki database="eqrunners">

 SELECT * from asset where project_id = (select project_id from projects where projects.project_name = "{{lc:{{PAGENAME}}}}");


Open in new window

Question by:eyeqube

    Author Comment

    other way to put it may i take the pagename from wiki and pass it as a string to the sqlquery in sql2wiki extension

    {{PAGENAME}} = "xyz"
    LVL 49

    Expert Comment

    Have you tested with the subquery solely?

    SELECT * FROM projects WHERE projects.project_name = "{{lc:{{PAGENAME}}}}"

    Author Comment

    yes. I gives the header of the fields. the data area is blank. Another question.
    LVL 49

    Accepted Solution

    When I install and configure this locally, I see that the {{lc:{{PAGENAME}}}} just isn't parsed. Should I have more extension installed as well?

    When I run it with a prefilled project name it works fine:

    <sql2wiki database="eqrunners">
    SELECT * from asset where project_id = (select project_id from projects where projects.project_name = "sql2wiki");

    I wonder however if it is not safer to masquee sql2wiki, and build an additional wiki extension of your own that does not expose your sql like this:
    <assetlist project="sql2wiki" />

    Or when you want to use the current pagename, just allows for use without a project param.


    Create a new file assetList.php and put it in your extensions folder. Paste in the below code, and then update your $localSettings.php to include
    include "extensions/assetList.php";

    This allows for wrapping sql2wiki and not exposing your queries inside the actual wiki test.
    # Let mediawiki know we have a new extension
    $wgExtensionFunctions[] = "wfAssetList";
    # The wfAssetList makes the parser recognize <assetlist> tags
    function wfAssetList() {
    	GLOBAL $wgParser;
    # This function is called when you put in an <assetlist>
    # It detects if you use a project argument, or not
    function wfAssetList_Hook($input, $argv, &$parser) {
    	GLOBAL $wgTitle;
    	if(isset($argv['project'])) {
    		# We have a project=".." argument
    		$project = $argv['project'];
    	} else {
    		# We don't have a project, so we use the current page name
    		$project = $wgTitle->mTextform;
    	# We now create our query, and let sql2wiki handle the rest.
    	return renderSQL('SELECT * from asset where project_id = (select project_id from projects where projects.project_name = "'.$project.'")', array('database' => 'eqrunners'), $parser);

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now