[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CREATE TQUERY AND TUPDATESQL IN RUN TIME AND INSERTING ROW IN MY DATABASE

Posted on 2006-07-15
4
Medium Priority
?
351 Views
Last Modified: 2010-04-05
I WOULD LIKE TO CREATE ONE OBJECT TQUERY AND ONE TUPDATESQL TO INSERT ONE ROW IN MY DATABASE.

HERE IS THE CODE THAT I USE FOR DO THAT, BUT LIKE I SAD I WANT CREATE THIS OBJECTS (TQUERY AND TUPDATESQL) IN RUNTIME:
SQLERRO IS TUPDATESQL AND QUERY_ERRO IS TQUERY

   SQLErro.InsertSQL.Clear;
   SQLErro.InsertSQL.Add('insert into TB_ERRO');
   SQLErro.InsertSQL.Add('(DATA, MENSAGEM, FORMNAME, FORMCAPTION, OBJETOATIVO)');
   SQLErro.InsertSQL.Add(' values');
   SQLErro.InsertSQL.Add('(''' + DateTimeToStr(now()) + ''',');
   SQLErro.InsertSQL.Add('''' + E.Message + ''',');
   SQLErro.InsertSQL.Add('''' + screen.ActiveForm.Name + ''',');
   SQLErro.InsertSQL.Add('''' + Screen.ActiveForm.Caption + ''',');
   SQLErro.InsertSQL.Add('''' + screen.ActiveControl.Name + ''')');
   Query_Erro.Insert;
   Query_Erro.ApplyUpdates;
   SQLErro.InsertSQL.Clear;
0
Comment
Question by:rafaelrgl
[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
4 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 2000 total points
ID: 17115834
the simple way to do this is to select the query on the form
then do a ctrl-c (copy)
next, find a nice spot in your unit and paste

you should get something like

object Query1: TQuery
  DatabaseName = 'DBDEMOS'
  SQL.Strings = (
    'select * from biolife')
  Left = 424
  Top = 296
end

object UpdateSQL1: TUpdateSQL
  Left = 432
  Top = 304
end

now simply replace the bits you need with delkphi code
e.g.
Query_Erro :=  TQuery.create(nil);
Query_Erro.DatabaseName := 'DBDEMOS';
Query_Erro.SQL.Text := 'select * from biolife';

SQLErro := TUpdateSQL.create(nil);

0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17116001
[Error] FrmPrinc.pas(445): Undeclared identifier: 'Query_Erro'
[Error] FrmPrinc.pas(445): Undeclared identifier: 'TQuery'
[Error] FrmPrinc.pas(446): Undeclared identifier: 'SQLErro'
[Error] FrmPrinc.pas(446): Undeclared identifier: 'TUpdateSQL'
[Error] FrmPrinc.pas(446): Missing operator or semicolon
[Error] FrmPrinc.pas(447): Missing operator or semicolon
[Hint] FrmPrinc.pas(233): Private symbol 'UniqueUser' declared but never used
[Fatal Error] Nucleo_Server.dpr(31): Could not compile used unit 'FrmPrinc.pas'
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17116871
Sorry, i thought you knew that bit.
If you wish to create it dynamically you will need to make a variable for it somewhere

eg. if you wish to create it for your form you'd have

private // at the top of your unit you will seee this section
    Query_erro: TQuery;
    SQLErro: TUpdateSQL;
end;

but if you wish to create it in an object, eg. for yout TIdTCPServer, then you'd put it in the data object you create for that
eg.
type
    TClientSpecificData = class(TObject)
  private
    Query_erro: TQuery;
    SQLErro: TUpdateSQL;
...
etc...
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17116889
you will also need to add DB, and DBTables to your USES clause at the top of your unit
eg.
uses windows..(etc)...,DBTables, DB;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

656 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