[Lazarus] Cannot open a non-select statement.

William Ferreira williamoferreira at outlook.com
Fri Sep 26 19:07:21 CEST 2014


For SELECT statements use TSQLQuery.Open;
For INSERT, DELETE or UPDATE, use TSQLQuery.ExecSQL;

Date: Fri, 26 Sep 2014 15:52:07 +0200
From: izac.kruger at gmail.com
To: lazarus at lists.lazarus.freepascal.org
Subject: [Lazarus] Cannot open a non-select statement.

Hi All,
I am new on lazarus,
I got one form on which I performed  2 onClick even on 2 button:
The first button its for INSERT the data in the SQLite database,
The second button its for CLEAR the information on the form.
After I have clicked on the first button to INSERT the data, the operation goes successfully; if I clicked on the second button who is to removed all the data on the fields, then after  refield again the information and clicked on the INSERT button, I received a funny message: SQLQeuryLite: Cannot open a non-select statement.
I tried to re-activate/restart the transaction component but still having the same error.
Please see below my codes:
------------------------------------------------FIRST BUTTON----------------------------------------------

else begin
       //DB connections.
    if DataModuleConn.SQLTransSQLite.Active=False then
      begin
       DataModuleConn.SQLite3Conn.Connected:=True;
       DataModuleConn.SQLTransSQLite.Active:=True;
       DataModuleConn.SQLQuerySQLite.Active:=True;

       DataModuleConn.SQLQuerySQLite.SQL.Text:='INSERT INTO loginConnection (hostname, hostip, dbname, username, password) VALUES ('
                                               +':getHOSTNAME, :getHOSTIP, :getDBNAME, :getUSERNAME, :getPASSWORD);';
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getHOSTNAME').AsString:=lblEdtHostFQDN.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getHOSTIP').AsString:=lblEdtHostIP.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getDBNAME').AsString:=lblEdtDBName.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getUSERNAME').AsString:=lblEdtDBuserName.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getPASSWORD').AsString:=lblEdtDBPassword.Text;

       DataModuleConn.SQLQuerySQLite.ExecSQL;

       DataModuleConn.SQLQuerySQLite.SQL.Text:='INSERT INTO textConnection (hostname, hostip, dbname, username, password) VALUES ('
                                               +':getHOSTNAME, :getHOSTIP, :getDBNAME, :getUSERNAME, :getPASSWORD);';
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getHOSTNAME').AsString:=lblEdtHostFQDN1.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getHOSTIP').AsString:=lblEdtHostIP1.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getDBNAME').AsString:=lblEdtDBName1.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getUSERNAME').AsString:=lblEdtDBuserName1.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getPASSWORD').AsString:=lblEdtDBPassword1.Text;

       DataModuleConn.SQLQuerySQLite.ExecSQL;

       DataModuleConn.SQLQuerySQLite.SQL.Text:='INSERT INTO binaryConnection (hostname, hostip, dbname, username, password) VALUES ('
                                               +':getHOSTNAME, :getHOSTIP, :getDBNAME, :getUSERNAME, :getPASSWORD);';
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getHOSTNAME').AsString:=lblEdtHostFQDN2.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getHOSTIP').AsString:=lblEdtHostIP2.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getDBNAME').AsString:=lblEdtDBName2.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getUSERNAME').AsString:=lblEdtDBuserName2.Text;
       DataModuleConn.SQLQuerySQLite.Params.ParamByName('getPASSWORD').AsString:=lblEdtDBPassword2.Text;

       DataModuleConn.SQLQuerySQLite.ExecSQL;

       ShowMessage(msgSuccessful + lisLineEnding + msgSaved);

       DataModuleConn.SQLTransSQLite.Commit;
       //DataModuleConn.SQLQuerySQLite.Close;

          bitBtnOK.Caption:=liBtnUpdate;
          bitBtnOK.Enabled:=False;
          //DataModuleConn.SQLTransSQLite.StartTransaction;
    end else
       begin
       DataModuleConn.SQLite3Conn.Connected:=False;
       DataModuleConn.SQLTransSQLite.Active:=False;
       DataModuleConn.SQLQuerySQLite.Active:=False;
       end;
  end;  

------------------------------------------------SECOND BUTTON-----------------------------------------

                   
begin
   lblEdtHostFQDN.Text:='';
   lblEdtHostIP.Text:='';
   lblEdtDBName.Text:='';
   lblEdtDBuserName.Text:='';
   lblEdtDBPassword.Text:='';
   lblEdtDBPasswordRepeat.Text:='';

   lblEdtHostFQDN1.Text:='';
   lblEdtHostIP1.Text:='';
   lblEdtDBName1.Text:='';
   lblEdtDBuserName1.Text:='';
   lblEdtDBPassword1.Text:='';
   lblEdtDBPasswordRepeat1.Text:='';

   lblEdtHostFQDN2.Text:='';
   lblEdtHostIP2.Text:='';
   lblEdtDBName2.Text:='';
   lblEdtDBuserName2.Text:='';
   lblEdtDBPassword2.Text:='';
   lblEdtDBPasswordRepeat2.Text:='';

   ckBoxShowPassword.Checked:=False;
   ckBoxShowPassword1.Checked:=False;
   ckBoxShowPassword2.Checked:=False;
   ckBoxSameAsLogin.Checked:=False;
   ckBoxSameAsLogin1.Checked:=False;
   ckBoxSameAsTData.Checked:=False;

   lblEdtHostFQDN.SetFocus;

   bitBtnOK.Caption:=lisOK;
   bitBtnOK.Enabled:=True;

   if DataModuleConn.SQLTransSQLite.Active=True then
       DataModuleConn.SQLTransSQLite.Active:=False;
end;                

THANKS                 

--
_______________________________________________
Lazarus mailing list
Lazarus at lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140926/4b1ad020/attachment-0003.html>


More information about the Lazarus mailing list