Convert SQL query to Drupal Database abstraction layer code.

Project page: http://drupal.org/sandbox/denisz/1939706
Git repositoy: git clone http://git.drupal.org/sandbox/denisz/1939706.git query_coder - Drupal 7 project

Other project application reviews:
http://drupal.org/node/1856530#comment-7174030
http://drupal.org/node/1927760#comment-7174102
http://drupal.org/node/1917832#comment-7191192

CommentFileSizeAuthor
query_coder.png28.24 KBdenisz

Comments

arnoldbird’s picture

You're still working on the master branch.

Please see the project application checklist: http://drupal.org/node/1587704

In particular please see 2.2 and 4.2 in the checklist.

It looks like you have non-GPL code in the php-sql-parser directory.

Good luck with your project and thanks for submitting.

arnoldbird’s picture

Status: Needs review » Needs work
denisz’s picture

Status: Needs work » Needs review

About 2.2 - I set up version branch 7.x-1.0
About 2.4 - php-sql-parser library has New BSD License. I'm not quite sure. Is it acceptable if I remove php-sql-parser library from repository and add 3rd party dependence with Libraries API module?

Thank you! Waiting for reply.

arnoldbird’s picture

Status: Needs review » Needs work

@denisz -- I'm no expert on the licensing, but I think you have the right idea. If it is non-GPL, you have to remove it from your repo and include instructions for downloading the library in your README or INSTALL files. That's what I would do. I will change this back to "needs work" until you indicate that you have removed the non-GPL code.

denisz’s picture

Status: Needs work » Needs review

I remove php-sql-parser library from repo and add install instruction in README.txt and on project page. So now project has not non-GPL code.

klausi’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://ventral.org/pareview/httpgitdrupalorgsandboxdenisz1939706git

We are currently quite busy with all the project applications and I can only review projects with a review bonus. Please help me reviewing and put yourself on the PAReview: review bonus high priority list. Then I'll take a look at your project right away :-)

denisz’s picture

Status: Needs work » Needs review
arnoldbird’s picture

@denisz
I tried this query...

SELECT users.* FROM users

Your form output...

$query = db_select('users', '');
$query->fields('users', array('*'));
$result = $query->execute();

...I pasted that code into a module file and ran it. I got this PDO error:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS FROM users users' at line 1: SELECT users. AS FROM {users} users; Array ( )

The same MySQL query runs fine if I paste it into the sql form in phpMyAdmin.

What is your use case for this module? Getting something like this to work consistently seems like a very difficult task, so I wonder what your motivation is? How will you use this? Is this module maintainable?

Thank you.

denisz’s picture

For now module support only queries with defined aliases for all tables:

If you use this form: "SELECT * FROM users u"
Your will get right result:

$query = db_select('users', 'u');
$query->fields('u');
$result = $query->execute();

I will add information about aliases to project page.

denisz’s picture

By the way, now module suppor all queries types (SELECT, UPDATE, INSERT, DELETE).

Also in previous comment I forgot answer the questions:

Q:What is your use case for this module?
Q:How will you use this?
A:Same answer for both questins. This module created for help developers convert SQL queries to Database abstracion layer php code during development process. For me is regular task, when I create query I first wright it in pure SQL syntax, then check if it work and then convert query to php code by hand. This module can automate this convertion porcess. I think this module will be helpful for lot of developers. Also you must not forget, this module not do your work for you, it just help and if some parts of query convert not wirght you can check it by yourself and correct.

Q:Is this module maintainable?
A:Yes, it module maintanable.

Thank you!

denisz’s picture

Issue tags: +PAreview: review bonus

Add "PAReview: review bonus" tag

arnoldbird’s picture

Status: Needs review » Needs work
Issue tags: -PAreview: review bonus

For me is regular task

I suppose that's good enough for me. It's not part of my workflow, but that doesn't mean it isn't part of yours.

Please provide some mention in the README and project page re: which databases the underlying library works with. You could provide one sentence about it, so people immediately understand the module uses a parser that aims to work with numerous databases, but only fully supports MySQL. Just to save someone a minute.

Here is a good example of a README.txt: http://drupal.org/node/1271064
Yours doesn't have to be as long, but you could at least add a bit more information, such as a link to the project page.

The module fails for some queries. I fetched your latest code and re-installed the module. I tried the following query...

INSERT INTO shop VALUES (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45), (3,'C',1.69),(3,'D',1.25),(4,'D',19.95);

The result shown was "INSERT queries not supported now". I think you intend to support insert queries. Anything regarding queries you don't intend to support should probably not be displayed below a heading that says "Results". Another way to display such a message would be to use drupal_set_message(). That might be more appropriate in a case like this. And of course, queries you don't support must be mentioned in the README and project page.

You need to write more tests. For your tests, be sure you are using a wide variety of queries you didn't think of yourself, from places like http://dev.mysql.com/doc/refman/5.0/en/examples.html
It's hard to say how many tests you need for a project like this, but you likely need many more than you've provided.

The module code appears to be quite clean, and it's certainly a difficult task you've set for yourself. But this module has enough remaining issues at this point that removing the bonus tag seems appropriate.

arnoldbird’s picture

The result shown was "INSERT queries not supported now".

I was wrong about this part. I didn't have the latest version of your module. I see now that the form does output some code for the query, but the code is not correct.

You could also work this query into your tests:
SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1' OR field2_index = '1'
At the moment the form isn't handling that query correctly.

denisz’s picture

Status: Needs work » Needs review
Issue tags: +PAreview: review bonus

Hi, arnoldbird. Thank you for your feedback !

About this query INSERT INTO shop VALUES (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45), (3,'C',1.69),(3,'D',1.25),(4,'D',19.95);
I think is not right example, because it shows multiple insertion and also in the README.txt and on project page I specify list of known issues where the first item is "INSERT queries must be specified in form "INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)" ", because cover all possible variants of queries is realy difficult task. So this module cover only most regular using types of queries.

Aboutn this query SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1' OR field2_index = '1'. It specified in known issues too:
"All tables and fields in SELECT query must be specified with aliases, in other (UPDATE, INSERT, DELETE) queries without aliases
Example:
RIGHT: "SELECT * FROM users u"
NOT RIGHT: "SELECT * FROM users" "

If your rewright this query with aliases like this: SELECT tt.field1_index, tt.field2_index FROM test_table tt WHERE tt.field1_index = '1' OR tt.field2_index = '1'
Your will get right result:

$query = db_select('test_table', 'tt');
$query->fields('tt', array('field1_index', 'field2_index'));

$or = db_or();
$or->condition('tt.field1_index', 1);
$or->condition('tt.field2_index', 1);
$query->condition($or);
$result = $query->execute();

Also I update README.txt and add more test with othre variants of queries (UPDATE, INSERT, DELETE).

arnoldbird’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

You might consider making the query form smaller. I doubt the textarea needs to be 15 rows. Maybe three or four rows would work?

Given the nature of the module, consider writing more tests. But it's nice that you've already included some.

In step 2 of the installation instructions, you have a typo: "Dwonload..."

arnoldbird’s picture

One more minor thing. You should put periods at the end of comments.

Right:

/**
 * @file
 * Pages for query_coder module.
 */

Wrong:

/**
 * @file
 * Pages for query_coder module
 */
denisz’s picture

Hi, arnoldbird. Thank you again for all your feedback.

I done all small fixes.
About query textarea, I set it to 10 rows, I think it optimal, 3 or 4 rows it to small.

In future I will add more tests. It just start point of this module and I planned to contribute and extand it.

denisz’s picture

Issue summary: View changes

Add project application reviews

klausi’s picture

Issue tags: -PAreview: review bonus

Removing review bonus tag, you have not done all manual reviews, you just posted the output of an automated review tool. Make sure to read through the source code of the other projects.

klausi’s picture

Issue summary: View changes

removed non-manual review.

denisz’s picture

Issue tags: +PAreview: review bonus

I just review another one project, so I back "PAReview: review bonus" tag at this point.

klausi’s picture

Status: Reviewed & tested by the community » Fixed

manual review:

  1. query_coder.module: why do you need to globally include the .functions.inc file? This will be included on every single page request, are you sure that you need to expose those functions as API? I t seems to me that they should only be included from the form submission handler?
  2. query_coder_coder_form(): when building forms use #attached instead of drupal_add_library/js/css.
  3. "variable_set('query_coder_counters' ...": looks like you are abusing the variable system here, which should be used for persistent variables. I assume that the contents of the variable is only useful within one request, so you should use a global variable instead. But remember: global variables are a code smell, if you need to access state information then you should pass that state around explicitly, i.e. as function parameter.
  4. query_coder.functions.inc: almost all function doc blocks are useless, as they just repeat what the function name already says. They should provide additional useful information like "Preprocess the query to count SQL BETWEEN statements." or whatever.
  5. I think your module should have a note somewhere that db_query() is preferred over db_select() for simple static queries, because it adds just a bunch of method calls to the runtime. See http://drupal.org/node/310075

But that are not blockers, so ...

Thanks for your contribution, denisz!

I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

denisz’s picture

Hi, klausi.

Thank you for your feedback. I will fix all issues from your manual review. And also thank you for helpful links. I will help Drupal community as many as I can.

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Add one project to "Other project application reviews" section