views:

79

answers:

3

I am wondering if there is some tool available, that will take as input a SQL command, and as output will return valid Drupal code that can be used in the Drupal Api?

EDIT

The idea is I have large, 25 lines of SQL commands ready to be used on the database. And they are somehow complicated, so I am wondering how could I rewrite them with a tool to use the object members on the db_query to do the same stuff as my large SQL command line.

+3  A: 

i assume there's no such tools.
Just read:
sql coding conventions
http://drupal.org/writing-secure-code

Nikit
A: 

This might save some time, depending on what you are trying to do with SQL.

http://drupal.org/project/views

Kevin
In your opinion how will this save time?
Pentium10
The original post sounded like you were wanting to take queries and display data. Now it sounds like you want to do operations which Views won't do, at least without Views Bulk Operations. What are you trying to do exactly?
Kevin
What I would like to do is to transform a 25 line of SQL into valid independent drupal nested object call using the db_query, and the most of the object calls instead of the plain raw sql query string.
Pentium10
A: 

Plain 'ol non-Drupal SQL will still work in db_query ... it's just not a best practice since the database API can't retool the SQL to work in any supported environment, and doesn't take advantage of Drupal's SQL injection protections, among other things.

But it still works.

If you're going to use the SQL in a known environment (e.g. a system where these commands are already in use), I'd say just use them as they are for now and gradually convert them over to Drupal standards as new code is developed.

(Of course, if this code is meant to be distributed to other environments, you'll want to put in sweat equity and convert the strings, or write a tool to do so)

anschauung