Use Parameters in TLiteQuery
Use Parameters in TLiteQuery
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
Hello,
You should enable the UseUnicode option in LiteConnection before connectiong to the database and assign parameter values using the asSttring property.
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
Thank you. I have another question. How would one check to see if a query returned results?
Re: Use Parameters in TLiteQuery
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:
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
When trying the code that you gave:
I get True, but it should return False as the values that I enter are in my database.
The database values are
And my code is
Code: Select all
ShowMessage(VarToStr(LiteQuery1.IsEmpty));
The database values are
Code: Select all
uname=admin;passw=admin
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
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).
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
Version 1.6.4 has add the TLiteSQL and TLiteQuery.
Data base connection make sure.
Requirement is C++,Turbo.
Data base connection make sure.
Requirement is C++,Turbo.
Re: Use Parameters in TLiteQuery
Hello,
We cannot reproduce the problem, please send the DB file to alexp*devart*com
We cannot reproduce the problem, please send the DB file to alexp*devart*com