Page 1 of 1

Use Parameters in TLiteQuery

Posted: Sun 27 Jan 2013 14:18
by bjaustin
I am creating a login form and I need to set the parameters of a query component through the code. How should I do that (both the parameters are UnicodeStrings)?

Re: Use Parameters in TLiteQuery

Posted: Mon 28 Jan 2013 10:08
by AlexP
Hello,

You should enable the UseUnicode option in LiteConnection before connectiong to the database and assign parameter values using the asSttring property.

Code: Select all

  LiteConnection1.Options.UseUnicode := True;
  LiteConnection1.Connect;
  LiteQuery1.SQL.Text := 'select :p1';
  LiteQuery1.ParamByName('p1').AsString := Edit1.text;
  LiteQuery1.Open;

Re: Use Parameters in TLiteQuery

Posted: Thu 31 Jan 2013 23:01
by bjaustin
Thank you. I have another question. How would one check to see if a query returned results?

Re: Use Parameters in TLiteQuery

Posted: Fri 01 Feb 2013 11:16
by AlexP
Hello,

To define DataSet or not, you can use two properties: IsEmpty and RecordCount,
the first one returns True if the DataSet is empty, the second one - 0, for example:

Code: Select all

  LiteQuery1.SQL.Text := 'select :p1 where 1<>1';
  LiteQuery1.ParamByName('p1').AsInteger := 1;
  LiteQuery1.Open;
  ShowMessage(VarToStr(LiteQuery1.IsEmpty)); //True
  ShowMessage(VarToStr(LiteQuery1.RecordCount = 0)); //True

Re: Use Parameters in TLiteQuery

Posted: Sat 02 Feb 2013 13:31
by bjaustin
When trying the code that you gave:

Code: Select all

ShowMessage(VarToStr(LiteQuery1.IsEmpty));
I get True, but it should return False as the values that I enter are in my database.

The database values are

Code: Select all

uname=admin;passw=admin
And my code is

Code: Select all

this->LiteQuery1->ParamByName("uname")->AsString = uname; //admin
	   this->LiteQuery1->ParamByName("passw")->AsString = pwd; //admin
	   ShowMessage(VarToStr(this->LiteQuery1->IsEmpty()));

Re: Use Parameters in TLiteQuery

Posted: Mon 04 Feb 2013 11:40
by AlexP
Hello,

Please check that, after opening the DataSet, the RecordCount property returns a value greater than 0, and that the data in the database is equal to that you set in the parameters (no spaces, the case of symbols is the same).

Code: Select all

this->LiteQuery1->ParamByName("uname")->AsString = uname; //admin
this->LiteQuery1->ParamByName("passw")->AsString = pwd; //admin
this->LiteQuery1->Open;
ShowMessage(VarToStr(this->LiteQuery1->IsEmpty()));
ShowMessage(VarToStr(this->LiteQuery1->RecordCount));
assert((this->LiteQuery1->RecordCount = 0) = this->LiteQuery1->IsEmpty());

Re: Use Parameters in TLiteQuery

Posted: Fri 08 Feb 2013 09:52
by ecig12
Version 1.6.4 has add the TLiteSQL and TLiteQuery.
Data base connection make sure.

Requirement is C++,Turbo.

Re: Use Parameters in TLiteQuery

Posted: Fri 08 Feb 2013 13:42
by AlexP
Hello,

We cannot reproduce the problem, please send the DB file to alexp*devart*com