Board index » delphi » Extracting SQL into resourceStrings...Tool?

Extracting SQL into resourceStrings...Tool?


2006-03-30 12:57:20 AM
delphi113
Does anyone know of any kind of tool that would facilitate converting
{*word*99} like this:
SQL.Clear;
SQL.Add( 'Select * from' );
SQL.Add( 'Customer ' );
SQL.Add(' Where Custid = :cid' );
to resourceStrings that I can put in:
SQL.Text := SQL_CONST
The refactoring in BDS2006 doesn't help because the lines are not a
single string (it won't even help with multiple concatenated string
lines). MMX doesn't seem to be too helpful, either.
I have so many of these to replace (thousands) that I am considering
writing a tool to use regular expressions and what not to refactor this
in an automated way, when it occurred to me that maybe someone else had
gone through the hell of extracting legacy SQL out of applications into
resourceStrings or a common module containing them or something.
Any help would be appreciated, otherwise, it is time for me to write my
own tool.
Thanks,
Randy
--
 
 

Re:Extracting SQL into resourceStrings...Tool?

Gerrit,
Consider, though - SQL is a TStrings object. Considering the valuable
refactor of extracting strings, don't you think that a conversion from
"TStrings.Add( )" blocks to TStrings.Text := RES_STR would be valuable?
IT stinks that I have got so much resourcifiable Code (SQL and other),
that I can not easily resourcify.
Randy
--
Gerrit Beuze writes:
Quote
Hello Randy,

>SQL.Clear;
>SQL.Add( 'Select * from' );
>SQL.Add( 'Customer ' );
>SQL.Add(' Where Custid = :cid' );
>
>to resourceStrings that I can put in:
>
>SQL.Text := SQL_CONST

>Any help would be appreciated, otherwise, it is time for me to write
>my own tool.

I think this is too specific for a generic tool and you will have to
create your own tool that does this. If the pattern is really as
specific as in the above you could possible get a long way with just
a tokenizer (rather than a full parser) to locate the strings and the
preceding identifiers.

Gerrit Beuze
ModelMaker Tools
 

Re:Extracting SQL into resourceStrings...Tool?

Actually this leads to a good followup question...
Have you ever considered the viability/doability of making MMX
extensible so a user could create their own 'block' operations with
some API that might leverage some of the stuff you've gotten by parsing
the code? Or would it just be too redundant to IOTA.
Randy
--
Gerrit Beuze writes:
Quote
Hello Randy,

>SQL.Clear;
>SQL.Add( 'Select * from' );
>SQL.Add( 'Customer ' );
>SQL.Add(' Where Custid = :cid' );
>
>to resourceStrings that I can put in:
>
>SQL.Text := SQL_CONST

>Any help would be appreciated, otherwise, it is time for me to write
>my own tool.

I think this is too specific for a generic tool and you will have to
create your own tool that does this. If the pattern is really as
specific as in the above you could possible get a long way with just
a tokenizer (rather than a full parser) to locate the strings and the
preceding identifiers.

Gerrit Beuze
ModelMaker Tools
 

Re:Extracting SQL into resourceStrings...Tool?

Randy Magruder writes:
Quote
Does anyone know of any kind of tool that would facilitate converting
{*word*99} like this:

SQL.Clear;
SQL.Add( 'Select * from' );
SQL.Add( 'Customer ' );
SQL.Add(' Where Custid = :cid' );

If the programming style is consistent, you could probably use the
Delphi editor's macro recorder to do most of the work.
Not sure why you would use resource strings rather than consts, it
doesn't seem like the kind of thing that needs to be localized.
I use a custom design-time component as a placeholder for multiline
strings - basically a TComponent with a TStringList. That keeps the
text completely out of sight and free of code formatting.
 

Re:Extracting SQL into resourceStrings...Tool?

Johannes Bjerregaard writes:
Quote
If the programming style is consistent,
ROFL->LMAO :) it is hard enough getting a small team to be consistent
let alone a code-inheritance chain that dates back to '96 and God knows
how many developers. it is a mess...I wish I could count on consistency
:)
Quote
you could probably use the
Delphi editor's macro recorder to do most of the work.
I often do. But I want to go a step beyond that.
Quote
Not sure why you would use resource strings rather than consts, it
doesn't seem like the kind of thing that needs to be localized.
Honestly, I don't care if they are consts or resourceStrings. I just
want the injected SQL OUT of the source files like this.
Randy
 

Re:Extracting SQL into resourceStrings...Tool?

Holger,
I know, it was one of those rare/conscious decisions I made - because
I wasn't sure which one would be the right one (one could argue it is a
database question but I didn't put it in there. I also don't know how
many people regularly read the 3rd party thread). So yeah, I violated
my normal 'one-group-only' because I wanted to be sure the most
eyeballs saw it.
Sorry.
Randy
Holger Flick writes:
Quote
Randy Magruder writes:
>Does anyone know of any kind of tool that would facilitate
>converting {*word*99} like this:

So nice of you to cross-post into any group I read... :-(
 

Re:Extracting SQL into resourceStrings...Tool?

It has my vote - it has many redeeming qualities ;)
--
Don Strenczewilk writes:
Quote
This won't help with your current situation, but you might want to
vote for this

qc.borland.com/wc/qcmain.aspx

to help eliminate the problem in the future.
 

Re:Extracting SQL into resourceStrings...Tool?

Hello Randy,
Quote
SQL.Clear;
SQL.Add( 'Select * from' );
SQL.Add( 'Customer ' );
SQL.Add(' Where Custid = :cid' );

to resourceStrings that I can put in:

SQL.Text := SQL_CONST
Any help would be appreciated, otherwise, it is time for me to write my
own tool.
I think this is too specific for a generic tool and you will have to create
your own tool that does this. If the pattern is really as specific as in the above
you could possible get a long way with just a tokenizer (rather than a full parser)
to locate the strings and the preceding identifiers.
Gerrit Beuze
ModelMaker Tools
 

Re:Extracting SQL into resourceStrings...Tool?

Randy Magruder writes:
Quote
Does anyone know of any kind of tool that would facilitate converting
{*word*99} like this:
So nice of you to cross-post into any group I read... :-(
--
Holger
Blog: www.flickdotnet.de
 

Re:Extracting SQL into resourceStrings...Tool?

This won't help with your current situation, but you might want to vote for
this
qc.borland.com/wc/qcmain.aspx
to help eliminate the problem in the future.
 

Re:Extracting SQL into resourceStrings...Tool?

"Randy Magruder" <XXXX@XXXXX.COM>writes
Quote
Johannes Bjerregaard writes:

>If the programming style is consistent,

ROFL->LMAO :) it is hard enough getting a small team to be consistent
let alone a code-inheritance chain that dates back to '96 and God knows
how many developers. it is a mess...I wish I could count on consistency
:)

>you could probably use the
>Delphi editor's macro recorder to do most of the work.

I often do. But I want to go a step beyond that.

>Not sure why you would use resource strings rather than consts, it
>doesn't seem like the kind of thing that needs to be localized.

Honestly, I don't care if they are consts or resourceStrings. I just
want the injected SQL OUT of the source files like this.

Randy
I have no help for automatically extracting the SQL; parsing the code with
regular expressions seems like best way to me.
Also, might not be exactly what you want, but if the resource string doesn't
work you might want to read a 3-part series of articles in Delphi Informant
written a few years ago by Rick Spence on creating a component by
subclassing TQuery to store SQL strings in a database and automatically
retrieve them as the TQuery was opened. I remember trying it out with
TDBISAMQueries and thought it was neat. Has advantages over extracting to
resource strings because having the sql in the db itself makes easier to
edit, create versions for different db's, etc. I am sure there is some
performance hit, but I am guessing it would be minimal. (Not sure, but the
method in the article could also probably be adopted to get the SQL strings
from resource strings.) Anyway, the code and articles would be available on
the Delphi Informant CD:
www.delphizine.com/
-- Herb Sitz
 

Re:Extracting SQL into resourceStrings...Tool?

Quote
Just write a DFM parser to do this, all you have to do is
"capture" all the TDataset objects that have a SQL property
and parse it into a TStrings descendant, clear it and then
save the TStrings text to a file. Then take the file(s)
created and create a separate resourcestrings or consts unit.
Um, a lot of these are defined dynamically in code. Yes there are some
in the DFM, but most are in code :(
But thanks.
Randy
 

Re:Extracting SQL into resourceStrings...Tool?

In article <442aca80$XXXX@XXXXX.COM>, XXXX@XXXXX.COM
says...
Quote
Does anyone know of any kind of tool that would facilitate converting
{*word*99} like this:

<SNIP>
Quote
to resourceStrings that I can put in:

SQL.Text := SQL_CONST

<SNIP>
Just write a DFM parser to do this, all you have to do is
"capture" all the TDataset objects that have a SQL property
and parse it into a TStrings descendant, clear it and then
save the TStrings text to a file. Then take the file(s)
created and create a separate resourcestrings or consts unit.
This isn't very difficult to do, and even easier if you use
Jeff Rafter's DFM->XML (ObjectBinaryToXML) functions. Let
me know if you require those.
 

Re:Extracting SQL into resourceStrings...Tool?

Quote
don't you think that a conversion from
"TStrings.Add( )" blocks to TStrings.Text := RES_STR would be valuable?
I think it is more a question of difficulty than value. Consider that your
example is a simple case, and that string expressions might also be in the Add
calls and it all starts to get much more complex
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________
 

Re:Extracting SQL into resourceStrings...Tool?

Quote
Just write a DFM parser to do this
Won't help, since none of that info is in the dfm
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper XXXX@XXXXX.COM
Skype : jim.cooper
Tabdee Ltd www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________