Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to extract the SQL command?

Posted on 2001-06-29
9
Medium Priority
?
415 Views
Last Modified: 2011-10-03
Hi,
  I would like to ask how to extract the SQL command?
I got a program to create a file,in this program ppl can create a file with just select the fields that shown in the combo box.after selecting the fields then save the sql statement in this file.
  now I have to edit this file and extract the sql statement.let said the sql statement is: SELECT A,B,C FROM TIME. now i need to extract the A,B,C to the variable
a=A, b=B, c=C..so what I need to do?thans..for helping me.
0
Comment
Question by:leeboonseong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 

Author Comment

by:leeboonseong
ID: 6239255
One more question..How can I pass the variable form form1 to form2? and also how to call fuction,procedure from form2 to form1?thanks
0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 6239364
As far as passing a var from one form to another:


Any variable declared in the INTERFACE portion of a unit is available to other units who use THAT unit.

So in Form1, interface section, declar a variable like this:

var
  Form1: TForm1;
  FormOneVar : string;  //Form 2 will access this

In Form2, you can click a button and access the contents of Form1, like this:

//OnClick for a button that fills an edit box with the Form1.FormOneVar:

//This is in Form2
procedure TForm2.Button1Click(Sender: TObject);
begin
  //Unit1 is the .pas file for Form1
  Edit1.Text := Unit1.FormOneVar
end;

Notice that Form2 (Unit2.pas)  USES Form1 (Unit1.pas):

...
...
...
var
  Form2: TForm2;

implementation

uses Unit1;  //Unit 2 uses Unit1

{$R *.DFM}

...
...
...





TO SEE THIS IN ACTION:

1) Open a new Project in Delphi with two forms (keep generic naming)
2)  On Form 1 drop a button.  The onclick for this button will open form 2.
3)  On Form 2 drop a TEdit and 2 buttons.  One button will close the form, the other will pull the variable from Form1 and display it's value in the TEdit on Form2.



//FORM 1 CODE:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ButtonOpenFormTwo: TButton;
    procedure FormCreate(Sender: TObject);
    procedure ButtonOpenFormTwoClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  FormOneVar : string;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FormOneVar := 'Hello from Form One';
end;

procedure TForm1.ButtonOpenFormTwoClick(Sender: TObject);
begin
  Form2 := TForm2.Create(Application);
  try
    Form2.ShowModal;
  finally
    Form2.Free;
  end;

end;

end.
 



//FORM 2 CODE

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.DFM}

procedure TForm2.Button1Click(Sender: TObject);
begin
  Edit1.Text := Unit1.FormOneVar
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
 Close;
end;

end.
0
 
LVL 4

Expert Comment

by:YodaMage
ID: 6239380
If people have picked the fields, then basically do something like:

TQuery.SQL.Close;
TQuery.SQL := 'select * from ' + Choice1 + ',' + choice2 + (You get the idea, or you can pass the string value of the item index directly) + 'where (any conditions you need);
TQuery.ExecSQL;
TQuery.Open;

as far as the variable and procedure calls, have each form use the other. Then all you have to do is:

Variable from form 1 caled in form 2 as:

Form1.VarName

Procs and Functions in form 2 called in 1 as:

Form2.ProcName(Params);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Accepted Solution

by:
Tom Knowlton earned 200 total points
ID: 6239413
//Quick and dirty

procedure ExtractVars(temp_SQL_statement : string);
var
 A, B, C : string;
 temp_str : string;
begin
  temp_str := temp_SQL_statement;
  //Delete phrase SELECT FROM from the SQL statement
  temp_str := Copy(temp_str, Pos('from', temp_str) + 4, 200);
  //Delete WHERE blah blah blah from the SQL_statement
  temp_str := Copy(temp_str, 1, Pos('where', temp_str));
  //Left with A, B, C now...
  A := Copy(temp_str, 1, Pos(',', temp_str));
  temp_str := Copy(temp_str, Pos(',', temp_str), 200);

  B := Copy(temp_str, 1, Pos(',', temp_str));
  temp_str := Copy(temp_str, Pos(',', temp_str), 200);

  C := Copy(temp_str, 1, 200);
  temp_str := Copy(temp_str, Pos(',', temp_str), 200);

end;
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6240385
Hi leeboonseong,

if your application is responsible for executed prepared by user file with SQL statement then you can do it by another way.

Do not save prepared SQL statement  to the file, save user selection line by line instead.

E.g.
user choosed table TABLENAME
and fields F1, F2, F3, F4
then file will looks something like this:
TABLENAME
F1
F2
F3
F4

Now you can easy prepare SQL statement for executing and do not need to parse statement because you know file structure, is it?

-----
Igor

PS: You can prepare, save and load file by using TStrinList. There is good properties Values.

List.Values['TABLE'] := 'TABLENAME';
List.Values['FIELD1'] := 'SOMEFIELD';

List.SaveToFile.....
List.LoadFromFile....
0
 

Author Comment

by:leeboonseong
ID: 6240466
if the variable is in the form1..one procedure..can i use the same method to call this fuction..but where is place for me to declare the varible?
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6240511
not very clear, what function do you mean?
0
 

Author Comment

by:leeboonseong
ID: 6249460
thnaks for you help..can i have ur e-mail..so that next time i can send u my question?
0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 6250400
Thank you.

Tom Knowlton

knowltonfamily@yahoo.com

Send me any question you have, I will do my best to answer.

Experts-Exchange is also a GREAT resource for these types of questions.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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