1

Topic: for performance of requests

Prompt, in what side to look.
The example, is in a class methods for performance of requests.

procedure InitQuery (var Query: TIBQuery; ParamNames: string;
ParamValues: array of Variant);
var
Par: TParam;
pc, i:Integer;
begin
pc: = WordCount (ParamNames, '; ')-1;
for i: = 0 to pc do
begin
par: = Query. Params. FindParam (ExtractWord (ParamNames, '; ', i+1));
par. Value: = ParamValues [i];
function QSelSQL (SQL, ParamNames: string;
ParamValues: array of Variant): TIBQuery;
begin
IBQuery1.SQL.Add (SQL);
InitQuery (IBQuery1, ParamNames, ParamValues);
IBQuery1.Prepare;
IBQuery1.Open;
Result: = IBQuery1;
Q: = QSelSQL (' select * from table where field =:field ', ' field ', [' 1 '])

If in ParamValues to transfer it is more than 13  characters an error

EIBClientError with message Trying to store a string of length 14 into a field that can only contant 13

I understand that swears for length of a line but why so it turns out?
If simply to write

IBQuery1.Transaction. StartTransaction;
IBQuery1.SQL.Clear;
IBQuery1.SQL.Add (' select * from table where field =:field ');
IBQuery1. ParamByName (' field ').asstring: ='11111111111111111 ';
IBQuery1.Prepare;
IBQuery1.Open;

All apprx.

2

Re: for performance of requests

Because a field in the DB table it is restricted by 13th characters
As it is written by clear text in the message

3

Re: for performance of requests

defecator wrote:

because a field in the DB table it is restricted by 13th characters
As it is written by clear text in the message

Actually at me the following construction.
Sampling of procedure

select * from SELECT_PRICE (:ID_BUILDER)

In  procedures are a condition

where ((:ID_BUILDER containing ' ~ ' || D.ID || ' ~ ') or (' ~ ' || D.ID || ' ~ ' containing:ID_BUILDER))

I should transfer some values in procedure parameter, made according to http://www.ibase.ru/ibfaq/#inparam
The line  on the client looks like: ~1~4~54~25~14~63~521~78 ~
When I do
IBQuery1.Transaction. StartTransaction;
IBQuery1.SQL.Clear;
IBQuery1.SQL.Add (' select * from SELECT_PRICE (:ID_BUILDER) ');
IBQuery1. ParamByName (' field ').asstring: = ' ~ 1~4~54~25~14~63~521~78 ~ ';
IBQuery1.Prepare;
IBQuery1.Open;
Fulfills without errors.
When through   a problem with restriction of characters.

4

Re: for performance of requests

Debugger it is necessary  and to look that is really transferred

5

Re: for performance of requests

Sashaua wrote:

When I do
IBQuery1.SQL.Clear;
IBQuery1.SQL.Add (' select * from SELECT_PRICE (:ID_BUILDER) ');

It is not necessary to repeat the bad examples behind all successively.....
And if rewrite from a fence in a writing-book, it is necessary to consider that rewrite and what for it is necessary.

Sashaua wrote:

function QSelSQL (SQL, ParamNames: string;
ParamValues: array of Variant): TIBQuery;
begin
IBQuery1.SQL.Add (SQL);
InitQuery (IBQuery1, ParamNames, ParamValues);

Where call TStrings. Clear?
And on why simply not to make normal a: = b?

function QSelSQL (const SQL, ParamNames: string;
ParamValues: array of Variant): TIBQuery;
begin
IBQuery1.SQL.Text: = SQL;

And here you are one more wrapper http://www.loginovprojects.ru/index.php?page=ibxfbutils

6

Re: for performance of requests

Sashaua wrote:

procedure InitQuery (var Query: TIBQuery;

Why var?????
const should be

7

Re: for performance of requests

Sashaua wrote:

pc: = WordCount (ParamNames, '; ')-1;
par: = Query. Params. FindParam (ExtractWord (ParamNames, '; ', i+1));

Here it is necessary to invent brakes for no reason....
Do not read on fences of lines s of that
ExtractWord is when one word from , well at most 2-3 is necessary only.
If are necessary all - take at once an array of lines in one step and then use it.
And you n+1 do searching about a line instead of unique.
https://stackoverflow.com/questions/262 … -delimiter

8

Re: for performance of requests

Arioch;

wrote:

  const should be

It is absolutely not necessary modifiers. In its case of sense hardly less than is not present absolutely in them.

9

Re: for performance of requests

Still a variant, since Delphi XE .

10

Re: for performance of requests

makhaon;
It is better to begin with the modifier const just as all new needs to be entered terms of classes as striuct private
To add possibilities if  - you will be in time.
And it is necessary to begin with the maximum flexibility and safety.
Therefore by default - const. And if  and by mistake you will try to jam the pointer on object - the compiler corrects you at once. And it is useful, from own errors at once on the automatic machine to be protected.

11

Re: for performance of requests

alekcvp wrote:

it is passed...
Still a variant, since Delphi XE .

There it already is, twice:-D

12

Re: for performance of requests

Arioch wrote:

makhaon;
It is better to begin with the modifier const just as all new needs to be entered terms of classes as striuct private
To add possibilities if  - you will be in time.
And it is necessary to begin with the maximum flexibility and safety.
Therefore by default - const. And if  and by mistake you will try to jam the pointer on object - the compiler corrects you at once. And it is useful, from own errors at once on the automatic machine to be protected.

If it was so useful, the environment by default would interpose. And just fingers superfluous characters to type and code size to increase.

13

Re: for performance of requests

schi wrote:

the environment by default would interpose

Aha, also would invent instead of the person what and how many function parameters are necessary

14

Re: for performance of requests

Arioch;
Even if jams - that a maximum within a function interior (if any will not be, with var - the most bad variant). And that needs absolutely to be blunted.

15

Re: for performance of requests

Arioch;
, for example, presence const in this place considers as the bad style.

16

Re: for performance of requests

makhaon;
o_O
And she somehow motivates it?

makhaon wrote:

a maximum within a function interior

Basically - yes if it is made "on the classic" and the object forms and deleted in one place.
But all the same, even in limits - it can be unpleasant.
On the other hand, I generally read everyone  preventively I do not love variables (at which it is possible to change value):-D