[Lazarus] Lazarus 1.2.6 and GDB 7.7

2014-11-14 Thread Tony Whyman
Is anyone having much luck with Lazarus 1.2.6 and GDB 7.7 (I'm using
Linux Mint 17/Ubuntu 14.4).

As soon as I start using it with anything more than a simple program and
still using the default debug settings, the debugger keeps crashing when
an exception occurs. Here's a typical error

While executing the command:
TGDBMIDebuggerInstruction: -stack-info-depth 33, [ifRequiresThread]
Thr=1
gdb reported:
/build/buildd/gdb-7.7.1/gdb/buildsym.c:746: internal-error: failed
internal consistency check\nA problem internal to GDB has been
detected,\nfurther debugging may prove unreliable.


I am also having problems inspecting class variables - as in the
debugger claims the symbol does not exist.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Component palette reordering

2014-11-14 Thread Juha Manninen
There is a new feature for reordering tabs and components in the
component palette. See Component palette in environment options.
Please test but don't open bug reports yet. The feature is under heavy
development and still has known issues.
One issue is that the tabs show in reverse order sometimes after
closing the settings window.
D'n'd does not work reliably with all widgetsets. I will add buttons.

Comments are welcome but bug reports not yet.

Regards,
Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Threads and Libraries (dll and so)

2014-11-14 Thread Reimar Grabowski
On Tue, 04 Feb 2014 14:19:07 +
Mark Morgan Lloyd markmll.laza...@telemetry.co.uk wrote:

 and in my experience the thing that's most likely to work is DVD 
 playback because the data stream is (as I understand it) sent via a 
 backdoor to the graphics chips bypassing most of the kernel and X.
On Linux and BSD at least it's the standard to bypass X when talking to the GPU.
You can talk to the GPU from different threads (with a little overhead) but you 
actually gain nothing, because of how the drivers work. There may be some way 
to get better performance if you are talking to multiple GPUs and you can do a 
better job than the vendors driver to utilize them (highly unlikely).
There are reasons to talk to the GPU from different threads but that's only 
usefull for loading resources while not interupting the main rendering thread, 
there is no speed gain.

R.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Threads and Libraries (dll and so)

2014-11-14 Thread Reimar Grabowski
My last message was just a failure in using my mail client.

Sorry for the noise.

R:


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Replacing project1 target name by the selected project name

2014-11-14 Thread Mehmet Erol Sanliturk
Dears All ,


From ( OS installed version is 1.0.8 )

Lazarus - Project - New Project from File -


a *.lpr , or *.dpr file is selected ,

it is generating a

*.lpi

file by using the selected name * everywhere in the *.lpi file ,

BUT in

CompilerOptions

Target
  Filename Value=project1/
/Target

.
.
.
.
.

 /CompilerOptions


 Filename Value is still project1 .



Is it possible also to make it * to produce the executable with name * .


Thank you very much .

Mehmet Erol Sanliturk
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus 1.2.6 and GDB 7.7

2014-11-14 Thread Martin Frb

On 14/11/2014 10:01, Tony Whyman wrote:

Is anyone having much luck with Lazarus 1.2.6 and GDB 7.7 (I'm using
Linux Mint 17/Ubuntu 14.4).

As soon as I start using it with anything more than a simple program and
still using the default debug settings, the debugger keeps crashing when
an exception occurs. Here's a typical error

While executing the command:
TGDBMIDebuggerInstruction: -stack-info-depth 33, [ifRequiresThread]
Thr=1
gdb reported:
/build/buildd/gdb-7.7.1/gdb/buildsym.c:746: internal-error: failed
internal consistency check\nA problem internal to GDB has been
detected,\nfurther debugging may prove unreliable.
From what I observed, since gdb 7.5.9 those assertions get triggered.  
With older GDB I had not observed issues like this.

In many cases those are either caused by:
1) mixing stabs and dwarf (maybe some package has different settings).
2) smart linking (On some platforms debug info remains for removed code)

I am also having problems inspecting class variables - as in the
debugger claims the symbol does not exist.



Depends on if and what debug info fpc generates for them.




--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Reimar Grabowski
On Thu, 13 Nov 2014 11:33:58 -0300
silvioprog silviop...@gmail.com wrote:

 I use an own TPreparedStatement (equivalent to TSQLQuery prepared +
 Params, but my structure does not uses TDataset) that I get the last
 inserted ID with (pseudo codes):
snip
Sorry, you lost me there, but not a problem (see my response to Marcos).

Thanks anyway
R.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Reimar Grabowski
On Thu, 13 Nov 2014 13:26:32 -0300
Marcos Douglas m...@delfire.net wrote:

 Hi,
 Take a look in Greyhound project: https://github.com/mdbs99/Greyhound
I did and could not see how it helps.
 
 Here you can see an example using last id:
 https://github.com/mdbs99/Greyhound/blob/master/test/ghsqltest.pas#L285
Yes, if you are using Greyhound, which I am not.

So it looks like there's nothing in TSQLQuery that does the job for me.
I now just use another TSQLQuery with the following SQL:

SELECT LAST_INSERT_ID() AS SomeNameIChoose;

Seems to work well, reduces the lines of code as I don't have to set parameters 
(my primary goal), can be reused for other inserts (being not table dependent) 
and took about 1 Minute to implement.

Thanks anyways.
R.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Marcos Douglas
On Fri, Nov 14, 2014 at 10:05 AM, Reimar Grabowski reimg...@web.de wrote:
 On Thu, 13 Nov 2014 13:26:32 -0300
 Marcos Douglas m...@delfire.net wrote:

 Hi,
 Take a look in Greyhound project: https://github.com/mdbs99/Greyhound
 I did and could not see how it helps.

It has a code that working with auto-inc.

 Here you can see an example using last id:
 https://github.com/mdbs99/Greyhound/blob/master/test/ghsqltest.pas#L285
 Yes, if you are using Greyhound, which I am not.

Yes, I use everyday. I'm the author. ;-)


 So it looks like there's nothing in TSQLQuery that does the job for me.
 I now just use another TSQLQuery with the following SQL:

 SELECT LAST_INSERT_ID() AS SomeNameIChoose;

 Seems to work well, reduces the lines of code as I don't have to set 
 parameters (my primary goal), can be reused for other inserts (being not 
 table dependent) and took about 1 Minute to implement.

 Thanks anyways.

Best regards,
Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, Reimar Grabowski wrote:


On Thu, 13 Nov 2014 13:26:32 -0300
Marcos Douglas m...@delfire.net wrote:


Hi,
Take a look in Greyhound project: https://github.com/mdbs99/Greyhound

I did and could not see how it helps.


Here you can see an example using last id:
https://github.com/mdbs99/Greyhound/blob/master/test/ghsqltest.pas#L285

Yes, if you are using Greyhound, which I am not.

So it looks like there's nothing in TSQLQuery that does the job for me.
I now just use another TSQLQuery with the following SQL:

SELECT LAST_INSERT_ID() AS SomeNameIChoose;

Seems to work well, reduces the lines of code as I don't have to set parameters 
(my primary goal), can be reused for other inserts (being not table dependent) 
and took about 1 Minute to implement.


Connections for databases that have lastinsertID you can call the method 
created for this:

Function GetInsertID: int64;

There is a plan to let SQLDB retrieve the value of some fields fro the DB, 
but it is not implemented yet.


Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Marcos Douglas
On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt
mich...@freepascal.org wrote:


 On Fri, 14 Nov 2014, Reimar Grabowski wrote:

 On Thu, 13 Nov 2014 13:26:32 -0300
 Marcos Douglas m...@delfire.net wrote:

 Hi,
 Take a look in Greyhound project: https://github.com/mdbs99/Greyhound

 I did and could not see how it helps.

 Here you can see an example using last id:
 https://github.com/mdbs99/Greyhound/blob/master/test/ghsqltest.pas#L285

 Yes, if you are using Greyhound, which I am not.

 So it looks like there's nothing in TSQLQuery that does the job for me.
 I now just use another TSQLQuery with the following SQL:

 SELECT LAST_INSERT_ID() AS SomeNameIChoose;

 Seems to work well, reduces the lines of code as I don't have to set
 parameters (my primary goal), can be reused for other inserts (being not
 table dependent) and took about 1 Minute to implement.


 Connections for databases that have lastinsertID you can call the method
 created for this:

 Function GetInsertID: int64;

 There is a plan to let SQLDB retrieve the value of some fields fro the DB,
 but it is not implemented yet.

Hi Michael,

To do that is need to implement a GetInsertID method in all drivers of
SQLdb and include a code, like bellow, in TSQLQuery.ApplyRecUpdate:

var
  I: Integer;
  LastId: NativeInt;
  Fld: TField;
begin
  inherited;

  if UpdateKind  ukInsert then
Exit;

  for I := 0 to Fields.Count -1 do
  begin
Fld := Fields.Fields[I];
if Fld.IsNull and
   ((Fld.DataType = ftAutoInc) or (LowerCase(Fld.FieldName) =
'id') and (Fld is TNumericField)) then
begin
  LastId := FLib.GetLastAutoIncValue;
  if LastId = 0 then
Exit;

  if Fld.ReadOnly then
Fld.ReadOnly := False;

  Edit;
  Fields[I].SetData(@LastId);
  Post;
  Exit;
end;
  end;
end;

https://github.com/mdbs99/Greyhound/blob/master/src/ghsqldblib.pas#L157


Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 9:53 AM, Reimar Grabowski reimg...@web.de wrote:

 On Thu, 13 Nov 2014 11:33:58 -0300
 silvioprog silviop...@gmail.com wrote:

  I use an own TPreparedStatement (equivalent to TSQLQuery prepared +
  Params, but my structure does not uses TDataset) that I get the last
  inserted ID with (pseudo codes):
 snip
 Sorry, you lost me there, but not a problem (see my response to Marcos).

 Thanks anyway


I saw.

The problem which I see is just:

Query.SQL.Text := 'SELECT LAST_INSERT_ID() AS SomeNameIChoose;';
Query.Open;  here
ID := Query.Fields[0].AsInt64;

This approach is ugly IMHO.

So I use INSERT X (FIELDS) VALUES (PARAMS) RETURNING PK, returning the
generated ID in same SQL cursor which I used to prepare my statement. This
idea is from JDBC and I'm using it daily. Works fine in all popular SGBDs.
=)
Even when the SGBD does not provides the RETURNING feature, I use the SQL
cursor from the database driver to generate it without TDataset.Open.

My complete code works only in FPC 2.7.1+, but in short words I get the
generated ID via buffer (pointer) on database driver.

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt 
mich...@freepascal.org wrote:
[...]

 Connections for databases that have lastinsertID you can call the method
 created for this:

 Function GetInsertID: int64;

 There is a plan to let SQLDB retrieve the value of some fields fro the DB,
 but it is not implemented yet.


Awesome news! =)

Some branch to follow this new implementations? (trunk?)

Thanks!

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, Marcos Douglas wrote:


On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt
mich...@freepascal.org wrote:



On Fri, 14 Nov 2014, Reimar Grabowski wrote:


On Thu, 13 Nov 2014 13:26:32 -0300
Marcos Douglas m...@delfire.net wrote:


Hi,
Take a look in Greyhound project: https://github.com/mdbs99/Greyhound


I did and could not see how it helps.


Here you can see an example using last id:
https://github.com/mdbs99/Greyhound/blob/master/test/ghsqltest.pas#L285


Yes, if you are using Greyhound, which I am not.

So it looks like there's nothing in TSQLQuery that does the job for me.
I now just use another TSQLQuery with the following SQL:

SELECT LAST_INSERT_ID() AS SomeNameIChoose;

Seems to work well, reduces the lines of code as I don't have to set
parameters (my primary goal), can be reused for other inserts (being not
table dependent) and took about 1 Minute to implement.



Connections for databases that have lastinsertID you can call the method
created for this:

Function GetInsertID: int64;

There is a plan to let SQLDB retrieve the value of some fields fro the DB,
but it is not implemented yet.


Hi Michael,

To do that is need to implement a GetInsertID method in all drivers of
SQLdb and include a code, like bellow, in TSQLQuery.ApplyRecUpdate:


No. Not all SQL engines support lastID. Postgres and Firebird don't.

A more general mechanism is needed.

Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, silvioprog wrote:


On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt mich...@freepascal.org 
wrote:
[...]
  Connections for databases that have lastinsertID you can call the method 
created for this:

  Function GetInsertID: int64;

  There is a plan to let SQLDB retrieve the value of some fields fro the 
DB, but it is not implemented
  yet.


Awesome news! =)

Some branch to follow this new implementations? (trunk?)


It will be implemented in trunk.

Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Reimar Grabowski
On Fri, 14 Nov 2014 14:15:08 +0100 (CET)
Michael Van Canneyt mich...@freepascal.org wrote:

 Connections for databases that have lastinsertID you can call the method 
 created for this:
 
 Function GetInsertID: int64;
That is actually exactly what I was looking for.
I was just too dense to realize that it belongs to the connection, not the 
query and didn't look for it there.
Shame on me.

Thanks a lot
R.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Marcos Douglas
On Fri, Nov 14, 2014 at 10:39 AM, Michael Van Canneyt
mich...@freepascal.org wrote:


 On Fri, 14 Nov 2014, Marcos Douglas wrote:

 On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt
 mich...@freepascal.org wrote:



 On Fri, 14 Nov 2014, Reimar Grabowski wrote:

 On Thu, 13 Nov 2014 13:26:32 -0300
 Marcos Douglas m...@delfire.net wrote:

 Hi,
 Take a look in Greyhound project: https://github.com/mdbs99/Greyhound


 I did and could not see how it helps.

 Here you can see an example using last id:
 https://github.com/mdbs99/Greyhound/blob/master/test/ghsqltest.pas#L285


 Yes, if you are using Greyhound, which I am not.

 So it looks like there's nothing in TSQLQuery that does the job for me.
 I now just use another TSQLQuery with the following SQL:

 SELECT LAST_INSERT_ID() AS SomeNameIChoose;

 Seems to work well, reduces the lines of code as I don't have to set
 parameters (my primary goal), can be reused for other inserts (being not
 table dependent) and took about 1 Minute to implement.



 Connections for databases that have lastinsertID you can call the method
 created for this:

 Function GetInsertID: int64;

 There is a plan to let SQLDB retrieve the value of some fields fro the
 DB,
 but it is not implemented yet.


 Hi Michael,

 To do that is need to implement a GetInsertID method in all drivers of
 SQLdb and include a code, like bellow, in TSQLQuery.ApplyRecUpdate:


 No. Not all SQL engines support lastID. Postgres and Firebird don't.

I know. For these the method returns 0 or the user need to code some
more to work.

If a DMBS does not support transaction, for example, I can't implement
transactions on SQLdb? Is better to implement transactions for all
DMBS that works and do nothing in few cases that not supported. The
same for auto-inc, IMHO.

 A more general mechanism is needed.

The code I posted is general, only in TSQLQuery.ApplyRecUpdate method.
In my example before, FLib instance (Greyhound's code) would be a
driver for SQLdb that will call GetLastAutoIncValue. A code for each
DBMS driver.


Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Marcos Douglas
On Fri, Nov 14, 2014 at 10:40 AM, Michael Van Canneyt
mich...@freepascal.org wrote:


 On Fri, 14 Nov 2014, silvioprog wrote:

 On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt
 mich...@freepascal.org wrote:
 [...]
   Connections for databases that have lastinsertID you can call the
 method created for this:

   Function GetInsertID: int64;

   There is a plan to let SQLDB retrieve the value of some fields fro
 the DB, but it is not implemented
   yet.


 Awesome news! =)

 Some branch to follow this new implementations? (trunk?)


 It will be implemented in trunk.

If you do not put the value, automatically, on register that you
included... what the point?
IMHO this is not a general code. The user can implements the same but
he will need to put the value on record... manually.

The code I showed before works in any DMBS. Just test it.

Best regards,
Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, Marcos Douglas wrote:


On Fri, Nov 14, 2014 at 10:39 AM, Michael Van Canneyt
mich...@freepascal.org wrote:



On Fri, 14 Nov 2014, Marcos Douglas wrote:


On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt
mich...@freepascal.org wrote:




On Fri, 14 Nov 2014, Reimar Grabowski wrote:


On Thu, 13 Nov 2014 13:26:32 -0300
Marcos Douglas m...@delfire.net wrote:


Hi,
Take a look in Greyhound project: https://github.com/mdbs99/Greyhound



I did and could not see how it helps.


Here you can see an example using last id:
https://github.com/mdbs99/Greyhound/blob/master/test/ghsqltest.pas#L285



Yes, if you are using Greyhound, which I am not.

So it looks like there's nothing in TSQLQuery that does the job for me.
I now just use another TSQLQuery with the following SQL:

SELECT LAST_INSERT_ID() AS SomeNameIChoose;

Seems to work well, reduces the lines of code as I don't have to set
parameters (my primary goal), can be reused for other inserts (being not
table dependent) and took about 1 Minute to implement.




Connections for databases that have lastinsertID you can call the method
created for this:

Function GetInsertID: int64;

There is a plan to let SQLDB retrieve the value of some fields fro the
DB,
but it is not implemented yet.



Hi Michael,

To do that is need to implement a GetInsertID method in all drivers of
SQLdb and include a code, like bellow, in TSQLQuery.ApplyRecUpdate:



No. Not all SQL engines support lastID. Postgres and Firebird don't.


I know. For these the method returns 0 or the user need to code some
more to work.

If a DMBS does not support transaction, for example, I can't implement
transactions on SQLdb? Is better to implement transactions for all
DMBS that works and do nothing in few cases that not supported. The
same for auto-inc, IMHO.


No worries. We will implement it, but simply not in the way you suggest.




A more general mechanism is needed.


The code I posted is general, only in TSQLQuery.ApplyRecUpdate method.
In my example before, FLib instance (Greyhound's code) would be a
driver for SQLdb that will call GetLastAutoIncValue. A code for each
DBMS driver.


By the very nature of the problem: GetLastAutoIncValue simply cannot be 
implemented in general.

In firebird, postgres, these values are generated using a generator/sequence.
You don't know the name of the generator, and even if you did, it is impossible 
to retrieve the value that was used to fill your particular record because the 
sequence/generator may have been updated several thousands of times by the time 
your second statement arrives.


The only way to do this correctly is using a RETURNING clause when doing the 
insert.

The idea is to add [pfRefresh] to providerflags. 
When doing an insert, the fields with this flag will be added to the RETURNING 
clause and used to update the buffer.


Fields of type ftautoInc can be added to this list (i.e. they automatically
get pfRefresh in their providerflags)

This approach will work on all SQL databases that support RETURNING.
(That should include any SQL database available today)

Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Component palette reordering

2014-11-14 Thread Juha Manninen
How to set item height in ListView?
I added :
  ComponentsListView.SmallImages := IDEImages.Images_24;
in the settings GUI and somehow the height is now correct on Windows
but on Linux with GTK2 or with QT it is too low. Parts of icons are
cut off.

Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 10:50 AM, Reimar Grabowski reimg...@web.de wrote:

 On Fri, 14 Nov 2014 14:15:08 +0100 (CET)
 Michael Van Canneyt mich...@freepascal.org wrote:

  Connections for databases that have lastinsertID you can call the method
 created for this:
 
  Function GetInsertID: int64;
 That is actually exactly what I was looking for.
 I was just too dense to realize that it belongs to the connection, not the
 query and didn't look for it there.
 Shame on me.

 Thanks a lot


+1

ID/Sequence generation must work out of transactions. It will be a nice new
feature in SQLdb! =)

Currently I use it via cursor from the database driver. It is very very
fast and is transaction independent. =)

--
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 10:40 AM, Michael Van Canneyt 
mich...@freepascal.org wrote:

 On Fri, 14 Nov 2014, silvioprog wrote:

 On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt 
 mich...@freepascal.org wrote:
 [...]
   Connections for databases that have lastinsertID you can call the
 method created for this:

   Function GetInsertID: int64;

   There is a plan to let SQLDB retrieve the value of some fields fro
 the DB, but it is not implemented
   yet.


 Awesome news! =)

 Some branch to follow this new implementations? (trunk?)


 It will be implemented in trunk.


Thanks dude. I'll follow it there! (y)

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Component palette reordering

2014-11-14 Thread zeljko

On 11/14/2014 03:15 PM, Juha Manninen wrote:

How to set item height in ListView?
I added :
   ComponentsListView.SmallImages := IDEImages.Images_24;
in the settings GUI and somehow the height is now correct on Windows
but on Linux with GTK2 or with QT it is too low. Parts of icons are
cut off.


Open an issue about it. Qt will be easy to fix, not sure about gtk2.

zeljko


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Martin Schreiber
On Friday 14 November 2014 15:11:30 Michael Van Canneyt wrote:

 The idea is to add [pfRefresh] to providerflags.
 When doing an insert, the fields with this flag will be added to the
 RETURNING clause and used to update the buffer.

I suggest [pfRefreshInsert,pfRefreshUpdate] as in MSEgui. MSEgui (and AFAIK 
Zeos) also automatically updates a simple master key field by LASTINSERTID if 
the DB supports it.

Martin

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Marcos Douglas
On Fri, Nov 14, 2014 at 11:11 AM, Michael Van Canneyt
mich...@freepascal.org wrote:


 On Fri, 14 Nov 2014, Marcos Douglas wrote:

 On Fri, Nov 14, 2014 at 10:39 AM, Michael Van Canneyt
 mich...@freepascal.org wrote:



 On Fri, 14 Nov 2014, Marcos Douglas wrote:

 On Fri, Nov 14, 2014 at 10:15 AM, Michael Van Canneyt
 mich...@freepascal.org wrote:




 On Fri, 14 Nov 2014, Reimar Grabowski wrote:

 On Thu, 13 Nov 2014 13:26:32 -0300
 Marcos Douglas m...@delfire.net wrote:

 Hi,
 Take a look in Greyhound project: https://github.com/mdbs99/Greyhound



 I did and could not see how it helps.

 Here you can see an example using last id:

 https://github.com/mdbs99/Greyhound/blob/master/test/ghsqltest.pas#L285



 Yes, if you are using Greyhound, which I am not.

 So it looks like there's nothing in TSQLQuery that does the job for
 me.
 I now just use another TSQLQuery with the following SQL:

 SELECT LAST_INSERT_ID() AS SomeNameIChoose;

 Seems to work well, reduces the lines of code as I don't have to set
 parameters (my primary goal), can be reused for other inserts (being
 not
 table dependent) and took about 1 Minute to implement.




 Connections for databases that have lastinsertID you can call the
 method
 created for this:

 Function GetInsertID: int64;

 There is a plan to let SQLDB retrieve the value of some fields fro the
 DB,
 but it is not implemented yet.



 Hi Michael,

 To do that is need to implement a GetInsertID method in all drivers of
 SQLdb and include a code, like bellow, in TSQLQuery.ApplyRecUpdate:



 No. Not all SQL engines support lastID. Postgres and Firebird don't.


 I know. For these the method returns 0 or the user need to code some
 more to work.

 If a DMBS does not support transaction, for example, I can't implement
 transactions on SQLdb? Is better to implement transactions for all
 DMBS that works and do nothing in few cases that not supported. The
 same for auto-inc, IMHO.


 No worries. We will implement it, but simply not in the way you suggest.


 A more general mechanism is needed.


 The code I posted is general, only in TSQLQuery.ApplyRecUpdate method.
 In my example before, FLib instance (Greyhound's code) would be a
 driver for SQLdb that will call GetLastAutoIncValue. A code for each
 DBMS driver.


 By the very nature of the problem: GetLastAutoIncValue simply cannot be
 implemented in general.

 In firebird, postgres, these values are generated using a
 generator/sequence.

...as well as could have a trigger for these cases, encapsulating the
problem in database... but the code in these cases should be
different.

 You don't know the name of the generator, and even if you did, it is
 impossible to retrieve the value that was used to fill your particular
 record because the sequence/generator may have been updated several
 thousands of times by the time your second statement arrives.

If you use a sequence/generator, you should call it before INSERT.
If you use auto-inc, the DMBS have support to return the last id on
your session.

 The only way to do this correctly is using a RETURNING clause when doing the
 insert.

This RETURNING clause works for all DBMS?

 The idea is to add [pfRefresh] to providerflags. When doing an insert, the
 fields with this flag will be added to the RETURNING clause and used to
 update the buffer.

 Fields of type ftautoInc can be added to this list (i.e. they automatically
 get pfRefresh in their providerflags)

 This approach will work on all SQL databases that support RETURNING.
 (That should include any SQL database available today)

Nice. But this is only a part of code. How do you will get the last ID
and put in record?

Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 11:11 AM, Michael Van Canneyt 
mich...@freepascal.org wrote:
[...]

 By the very nature of the problem: GetLastAutoIncValue simply cannot be
 implemented in general.

 In firebird, postgres, these values are generated using a
 generator/sequence.
 You don't know the name of the generator, and even if you did, it is
 impossible to retrieve the value that was used to fill your particular
 record because the sequence/generator may have been updated several
 thousands of times by the time your second statement arrives.

 The only way to do this correctly is using a RETURNING clause when doing
 the insert.


Indded.


 The idea is to add [pfRefresh] to providerflags. When doing an insert, the
 fields with this flag will be added to the RETURNING clause and used to
 update the buffer.

 Fields of type ftautoInc can be added to this list (i.e. they automatically
 get pfRefresh in their providerflags)

 This approach will work on all SQL databases that support RETURNING.
 (That should include any SQL database available today)


Just a suggestion: it would be nice to implement it using interface or
abstract class (like ConnectionDef). So if a database X does not provide
the RETURNING support, a mortal programmer could do that by himself on
his own project. =D

E.g:

// implemented in FPC PQConnection.pas, using the RETURNING feature
TPGSequence = class(..., ISQLSequence)
..
  function GetLastId: int64;

// implemented in programmer project, using X feature
TXSequence = class(..., ISQLSequence)
..
  function GetLastId: int64;

So:

PQConnector1.SetSequencer(TPGSequence.Create);

or:

XYZConnector1.SetSequencer(TXSequence.Create);

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, Martin Schreiber wrote:


On Friday 14 November 2014 15:11:30 Michael Van Canneyt wrote:


The idea is to add [pfRefresh] to providerflags.
When doing an insert, the fields with this flag will be added to the
RETURNING clause and used to update the buffer.


I suggest [pfRefreshInsert,pfRefreshUpdate] as in MSEgui. MSEgui (and AFAIK
Zeos) also automatically updates a simple master key field by LASTINSERTID if
the DB supports it.


No problem. 
I didn't know MSEGui has it, and the idea to use 2 different flags for insert/update is good :)


Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, Marcos Douglas wrote:


By the very nature of the problem: GetLastAutoIncValue simply cannot be
implemented in general.

In firebird, postgres, these values are generated using a
generator/sequence.


...as well as could have a trigger for these cases, encapsulating the
problem in database... but the code in these cases should be
different.


I know. RETURNING will handle this case correctly.




You don't know the name of the generator, and even if you did, it is
impossible to retrieve the value that was used to fill your particular
record because the sequence/generator may have been updated several
thousands of times by the time your second statement arrives.


If you use a sequence/generator, you should call it before INSERT.


That is one way, but not obligatory. Mostly it is done in triggers.

This is not a problem. RETURNING handles all cases.


If you use auto-inc, the DMBS have support to return the last id on
your session.


I know.




The only way to do this correctly is using a RETURNING clause when doing the
insert.


This RETURNING clause works for all DBMS?


AFAIK Only sqlite does not (maybe it does today). 
But that is not a DBMS :-)



The idea is to add [pfRefresh] to providerflags. When doing an insert, the
fields with this flag will be added to the RETURNING clause and used to
update the buffer.

Fields of type ftautoInc can be added to this list (i.e. they automatically
get pfRefresh in their providerflags)

This approach will work on all SQL databases that support RETURNING.
(That should include any SQL database available today)


Nice. But this is only a part of code. How do you will get the last ID
and put in record?


This is the complete code, because the returning clause will contain the ID.

Your remarks sound like maybe you don't understand/know exactly what RETURNING 
does ?
It was invented exactly to deal with such things.

Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread luiz americo pereira camara
2014-11-14 11:43 GMT-03:00 Michael Van Canneyt mich...@freepascal.org:

On Fri, 14 Nov 2014, Marcos Douglas wrote:


 This RETURNING clause works for all DBMS?


 AFAIK Only sqlite does not (maybe it does today). But that is not a DBMS
 :-)


MySQL also does not implement it

This is the workaround i use today:

var
  Info: TSQLStatementInfo;
  ActualConnection: TSQLConnection;
  InsertQuery: TSQLQuery;
begin
  Result := '';
  if (FConnection is TSQLConnector) then
ActualConnection := TSQLConnectorAccess(FConnection).Proxy
  else
ActualConnection := FConnection;

  Info :=
TSQLConnectionAccess(ActualConnection).GetStatementInfo(Query.SQL.Text,
True, stNoSchema);
  InsertQuery := CreateInsertQuery(Query, Info.TableName,
ActualConnection.FieldNameQuoteChars);
  try
if (ActualConnection is TPQConnection) or (ActualConnection is
TIBConnection) then
begin
  InsertQuery.SQL.Add(Format('Returning %s', [FPrimaryKey]));
  InsertQuery.Open;
  if InsertQuery.RecordCount  0 then
 Result := InsertQuery.Fields[0].AsString;
 ActualConnection.Transaction.CommitRetaining;
  end
  else
  begin
InsertQuery.ExecSQL;
ActualConnection.Transaction.CommitRetaining;
if (ActualConnection is TSQLite3Connection) then
  Result := IntToStr(TSQLite3Connection(ActualConnection).GetInsertID)
else if (ActualConnection is TConnectionName{MySql}) then
  Result := IntToStr(TConnectionName(ActualConnection).GetInsertID);
  end;
  finally
InsertQuery.Destroy;
  end;
end;

Luiz
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, silvioprog wrote:


On Fri, Nov 14, 2014 at 11:11 AM, Michael Van Canneyt mich...@freepascal.org 
wrote:
[...]
  By the very nature of the problem: GetLastAutoIncValue simply cannot be 
implemented in general.

  In firebird, postgres, these values are generated using a 
generator/sequence.
  You don't know the name of the generator, and even if you did, it is 
impossible to retrieve the value
  that was used to fill your particular record because the 
sequence/generator may have been updated
  several thousands of times by the time your second statement arrives.

  The only way to do this correctly is using a RETURNING clause when doing 
the insert.


Indded.
 
  The idea is to add [pfRefresh] to providerflags. When doing an insert, 
the fields with this flag will
  be added to the RETURNING clause and used to update the buffer.

  Fields of type ftautoInc can be added to this list (i.e. they 
automatically
  get pfRefresh in their providerflags)

  This approach will work on all SQL databases that support RETURNING.
  (That should include any SQL database available today)


Just a suggestion: it would be nice to implement it using interface or abstract 
class (like ConnectionDef). So if
a database X does not provide the RETURNING support, a mortal programmer 
could do that by himself on his own
project. =D


I was planning some fallback mechanism, yes. 
And a class function SupportReturningClause : Boolean or something similar.

Or maybe

TDBCapability = (lastID,returningclause);
TDBCapabilities = set of TDBCapability;

and

Class function DatabaseCapabilities : TDBCapabilities;

I don't really like using interfaces when things can be done more simple.

Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Threads and Libraries (dll and so)

2014-11-14 Thread Michael Schnell

On 11/14/2014 01:16 PM, Reimar Grabowski wrote:

but you actually gain nothing, because of how the drivers work.


Are we (still) talking multi-core systems gaining performance by really 
parallel work ?


You will gain nothing in the work of the GUI framework called by the 
Lazarus program *if* the Framework software decides to use a semaphore 
to block multiple thread concurrent working directly when entering any 
framework function. We can't (easily) know this, but in fact I *suppose* 
the widget set framework libraries will only block when entering the 
driver.


But you will gain performance during the LCL's widget code if same would 
support concurrency (which it currently does not).


-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, luiz americo pereira camara wrote:



2014-11-14 11:43 GMT-03:00 Michael Van Canneyt mich...@freepascal.org:

  On Fri, 14 Nov 2014, Marcos Douglas wrote:


This RETURNING clause works for all DBMS?


  AFAIK Only sqlite does not (maybe it does today). But that is not a DBMS 
:-)


MySQL also does not implement it


Hm. I thought it did. Well, it shows that MySQL is even less of a RDBMS than 
sqlite.

People trusting their data to these databases don't care about their data :)

No problem: Like I said, there will be a fallback mechanism.

I understand sometimes you don't have a choice what database to use, 
so we must cater for that as well.


Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Threads and Libraries (dll and so)

2014-11-14 Thread Reimar Grabowski
On Fri, 14 Nov 2014 15:55:07 +0100
Michael Schnell mschn...@lumino.de wrote:

 Are we (still) talking multi-core systems gaining performance by really 
 parallel work ?
No, we aren't talking anything (see second mail).
If you did not get it there may be a problem with your mail client(1), if you 
got it (must have been about 2,5h before you replied) there may be a problem 
with your reading or comprehension skills(2).
Choose 1 or 2.
I am not thread-necrophile and this one is as dead as it gets.

R.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 11:43 AM, Michael Van Canneyt 
mich...@freepascal.org wrote:
[...]

 AFAIK Only sqlite does not (maybe it does today). But that is not a DBMS
 :-)


Yes. It would be nice execute the last_insert_rowid() to return it in the
same cursor (AFAIK, Android SDK use this mechanism in the
nativeExecuteForLastInsertedRowId). So it can be same to the MySQL
(LAST_INSERT_ID()). =)

And you can use the TSQLite3Connection.getinsertid method, no? =/

E.g in a simple raw query in MySQL:

===
INSERT INTO table_name (col1, col2,...) VALUES ('val1', 'val2'...);
SELECT LAST_INSERT_ID();

This will get you back the PRIMARY KEY value of the last row that *you*
 inserted:

The ID that was generated is maintained in the server on a *per-connection
basis*. This means that the value returned by the function to a given
client is the first AUTO_INCREMENT value generated for most recent
statement affecting an AUTO_INCREMENT column *by that client*.

So this is unaffected by other queries that might be running on the server
from other users.

S:
http://stackoverflow.com/questions/17112852/get-the-new-record-primary-key-id-from-mysql-insert-query
===

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 11:47 AM, Michael Van Canneyt 
mich...@freepascal.org wrote:
[...]

 I was planning some fallback mechanism, yes. And a class function
 SupportReturningClause : Boolean or something similar.
 Or maybe

 TDBCapability = (lastID,returningclause);
 TDBCapabilities = set of TDBCapability;

 and

 Class function DatabaseCapabilities : TDBCapabilities;

 I don't really like using interfaces when things can be done more simple.


Good too dude. =)

Protected virtual methods would be welcome too. =)

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 12:49 PM, silvioprog silviop...@gmail.com wrote:

 On Fri, Nov 14, 2014 at 11:43 AM, Michael Van Canneyt 
 mich...@freepascal.org wrote:
 [...]

 AFAIK Only sqlite does not (maybe it does today). But that is not a DBMS
 :-)


 Yes. It would be nice execute the last_insert_rowid() to return it in
 the same cursor (AFAIK, Android SDK use this mechanism in the
 nativeExecuteForLastInsertedRowId). So it can be same to the MySQL
 (LAST_INSERT_ID()). =)

 And you can use the TSQLite3Connection.getinsertid method, no? =/


It works fine in SQLite (my test table have ten records and test2 one
record):

procedure TForm1.Button1Click(Sender: TObject);
var
  id1, id2: Int64;
begin
  SQLQuery1.Close;
  SQLQuery1.SQL.Text := 'insert into test (foo) values (''TEST'')';
  SQLQuery1.ExecSQL;
  id1 := SQLite3Connection1.GetInsertID;

  SQLQuery2.Close;
  SQLQuery2.SQL.Text := 'insert into test2 (foo) values (''TEST'');';
  SQLQuery2.ExecSQL;
  id2 := SQLite3Connection1.GetInsertID;

  ShowMessageFmt('ID1: %d; ID2: %d', [id1, id2]);
end;

[Window Title]
project1

[Content]
ID1: 11; ID2: 2

[OK]

I'll test it in MySQL ...

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Reimar Grabowski
On Fri, 14 Nov 2014 12:49:44 -0300
silvioprog silviop...@gmail.com wrote:

snip 
 This means that the value returned by the function to a given
 client is the first AUTO_INCREMENT value generated for most recent
 statement affecting an AUTO_INCREMENT column *by that client*.
Just to clarify, the 'first' here is important as it means that if you insert 
multiple rows in one statement you will get the first generated id and not the 
last one as some might expect (see 
http://dev.mysql.com/doc/refman/5.6/en/information-functions.html#function_last-insert-id).

R.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Marcos Douglas
On Fri, Nov 14, 2014 at 11:43 AM, Michael Van Canneyt
mich...@freepascal.org wrote:


 On Fri, 14 Nov 2014, Marcos Douglas wrote:

 By the very nature of the problem: GetLastAutoIncValue simply cannot be
 implemented in general.

 In firebird, postgres, these values are generated using a
 generator/sequence.


 ...as well as could have a trigger for these cases, encapsulating the
 problem in database... but the code in these cases should be
 different.


 I know. RETURNING will handle this case correctly.


 You don't know the name of the generator, and even if you did, it is
 impossible to retrieve the value that was used to fill your particular
 record because the sequence/generator may have been updated several
 thousands of times by the time your second statement arrives.


 If you use a sequence/generator, you should call it before INSERT.


 That is one way, but not obligatory. Mostly it is done in triggers.

 This is not a problem. RETURNING handles all cases.

 If you use auto-inc, the DMBS have support to return the last id on
 your session.


 I know.


 The only way to do this correctly is using a RETURNING clause when doing
 the
 insert.


 This RETURNING clause works for all DBMS?


 AFAIK Only sqlite does not (maybe it does today). But that is not a DBMS :-)

Of course.  :-)


 The idea is to add [pfRefresh] to providerflags. When doing an insert,
 the
 fields with this flag will be added to the RETURNING clause and used to
 update the buffer.

 Fields of type ftautoInc can be added to this list (i.e. they
 automatically
 get pfRefresh in their providerflags)

 This approach will work on all SQL databases that support RETURNING.
 (That should include any SQL database available today)


 Nice. But this is only a part of code. How do you will get the last ID
 and put in record?


 This is the complete code, because the returning clause will contain the
 ID.

 Your remarks sound like maybe you don't understand/know exactly what
 RETURNING does ?
 It was invented exactly to deal with such things.

AFAIK RETURNING is a SQL clause. I know that but I never used before.

You tell me SQLdb will use RETURNING clause if the DMBS have support,
right? Well, AFAIK MSSQL does not have support for this... but MSSQL
have IDENTITY (auto-inc) fields. How I will use RETURNING on MSSQL? If
this clause don't exists -- if already exists, sorry -- how I can get
the ID auto-inc?

Please, don't tell me that will be implemented a parser to search a
RETURNING clause on SQL, cut this part, execute, do other things to
get the ID and paste the RETURNING again.  :)


Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Replacing project1 target name by the selected project name

2014-11-14 Thread Juha Manninen
On Fri, Nov 14, 2014 at 2:30 PM, Mehmet Erol Sanliturk
m.e.sanlit...@gmail.com wrote:
 From ( OS installed version is 1.0.8 )

You mean the Lazarus version is 1.0.8? It is old!

 Lazarus - Project - New Project from File -
  ...
 Target
   Filename Value=project1/
 /Target

I cannot reproduce in trunk. Please test again using trunk.

Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Replacing project1 target name by the selected project name

2014-11-14 Thread Mehmet Erol Sanliturk
On Fri, Nov 14, 2014 at 8:40 AM, Juha Manninen juha.mannine...@gmail.com
wrote:

 On Fri, Nov 14, 2014 at 2:30 PM, Mehmet Erol Sanliturk
 m.e.sanlit...@gmail.com wrote:
  From ( OS installed version is 1.0.8 )

 You mean the Lazarus version is 1.0.8? It is old!

  Lazarus - Project - New Project from File -
   ...
  Target
Filename Value=project1/
  /Target

 I cannot reproduce in trunk. Please test again using trunk.

 Juha

 --




This is official Fedora 20 ( latest distribution ) package supplied as
1.0.8 .

Thank you very much .

Mehmet Erol Sanliturk
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Replacing project1 target name by the selected project name

2014-11-14 Thread Reinier Olislagers
On 14/11/2014 17:46, Mehmet Erol Sanliturk wrote:
 This is official Fedora 20 ( latest distribution ) package supplied as
 1.0.8 .

Well, that may be, but it is still old. A lot of bugs have been fixed since.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Replacing project1 target name by the selected project name

2014-11-14 Thread Juha Manninen
On Fri, Nov 14, 2014 at 6:46 PM, Mehmet Erol Sanliturk
m.e.sanlit...@gmail.com wrote:
 This is official Fedora 20 ( latest distribution ) package supplied as
 1.0.8 .

Yes, the official packages of many distros are old. We cannot help that.
You should load Lazarus trunk from SVN. A new version 1.4 will be
forked soon from trunk and we try to fix as many bugs as possible for
it.

Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, Marcos Douglas wrote:


Your remarks sound like maybe you don't understand/know exactly what
RETURNING does ?
It was invented exactly to deal with such things.


AFAIK RETURNING is a SQL clause. I know that but I never used before.

You tell me SQLdb will use RETURNING clause if the DMBS have support,
right? Well, AFAIK MSSQL does not have support for this... but MSSQL
have IDENTITY (auto-inc) fields. How I will use RETURNING on MSSQL? If
this clause don't exists -- if already exists, sorry -- how I can get
the ID auto-inc?

Please, don't tell me that will be implemented a parser to search a
RETURNING clause on SQL, cut this part, execute, do other things to
get the ID and paste the RETURNING again.  :)


Nono.

What I have in mind is the following:

Add pfRefreshUpdate/pfRefreshInsert for ProviderFLags

Then:

a) If the DB engine supports RETURNING clause (it seems 3 engines do, 3 don't),
   that will be used to fetch the values. This is the most optimal approach.

b) For engines that do not support returning there is the option to specify a 
refresh SQL statement.
   (coincidentally: these are the engines that use autoInc type fields instead 
of sequences)

   the 'last_insert_id' parameter for this statement will be detected (using 
the reserved name
   or the name of the ftAutoInc field) and filled with the contents of the last 
generated ID.

   This if the engine supports getting the last insert id, this refresh 
statement will be constructed
   and automatically used in 2 cases:

   1) if pfRefreshUpdate/pfRefreshInsert is found in the list of fields.
   2) if no pfRefreshUpdate/pfRefreshInsert is found in the list of fields, but 
there is 1 ftAutoInc field and
  the database engine supports getting the last generated ID.

That should cover most, if not all, cases where a refresh is needed, with minimal 
interference of the programmer...


Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Replacing project1 target name by the selected project name

2014-11-14 Thread Mehmet Erol Sanliturk
On Fri, Nov 14, 2014 at 9:05 AM, Juha Manninen juha.mannine...@gmail.com
wrote:

 On Fri, Nov 14, 2014 at 6:46 PM, Mehmet Erol Sanliturk
 m.e.sanlit...@gmail.com wrote:
  This is official Fedora 20 ( latest distribution ) package supplied as
  1.0.8 .

 Yes, the official packages of many distros are old. We cannot help that.
 You should load Lazarus trunk from SVN. A new version 1.4 will be
 forked soon from trunk and we try to fix as many bugs as possible for
 it.

 Juha

 --
 ___




I am going to install latest release  rpm files .

Thank you very much .

Mehmet Erol Sanliturk
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Marcos Douglas
On Fri, Nov 14, 2014 at 2:11 PM, Michael Van Canneyt
mich...@freepascal.org wrote:


 On Fri, 14 Nov 2014, Marcos Douglas wrote:

 Your remarks sound like maybe you don't understand/know exactly what
 RETURNING does ?
 It was invented exactly to deal with such things.


 AFAIK RETURNING is a SQL clause. I know that but I never used before.

 You tell me SQLdb will use RETURNING clause if the DMBS have support,
 right? Well, AFAIK MSSQL does not have support for this... but MSSQL
 have IDENTITY (auto-inc) fields. How I will use RETURNING on MSSQL? If
 this clause don't exists -- if already exists, sorry -- how I can get
 the ID auto-inc?

 Please, don't tell me that will be implemented a parser to search a
 RETURNING clause on SQL, cut this part, execute, do other things to
 get the ID and paste the RETURNING again.  :)


 Nono.

:)

 What I have in mind is the following:

 Add pfRefreshUpdate/pfRefreshInsert for ProviderFLags

 Then:

 a) If the DB engine supports RETURNING clause (it seems 3 engines do, 3
 don't),
that will be used to fetch the values. This is the most optimal approach.

OK

 b) For engines that do not support returning there is the option to
 specify a refresh SQL statement.
(coincidentally: these are the engines that use autoInc type fields
 instead of sequences)

This option, to specify a SQL statement, is the programmer that write
the SQL? This should come from driver, don't?

the 'last_insert_id' parameter for this statement will be detected (using
 the reserved name
or the name of the ftAutoInc field) and filled with the contents of the
 last generated ID.

This if the engine supports getting the last insert id, this refresh
 statement will be constructed
and automatically used in 2 cases:

1) if pfRefreshUpdate/pfRefreshInsert is found in the list of fields.
2) if no pfRefreshUpdate/pfRefreshInsert is found in the list of fields,
 but there is 1 ftAutoInc field and
   the database engine supports getting the last generated ID.

OK

 That should cover most, if not all, cases where a refresh is needed, with
 minimal interference of the programmer...

Looks good.


Marcos Douglas

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Reimar Grabowski
On Fri, 14 Nov 2014 14:50:20 +0100
Reimar Grabowski reimg...@web.de wrote:

 On Fri, 14 Nov 2014 14:15:08 +0100 (CET)
 Michael Van Canneyt mich...@freepascal.org wrote:
 
  Connections for databases that have lastinsertID you can call the method 
  created for this:
  
  Function GetInsertID: int64;
Unfortunately it does not work and returns only 0, while my custom query using 
LAST_INSERT_ID() works as expected.
Debugging this is very hard as Lazarus crashes on me left and right when trying 
to step through the code and an exception is encountered.
I have one connection, one transaction and some queries bound to them on a 
FPWebModule.

ID1:=MySQL55Connection1.GetInsertID;
SQLQuery1.Open;
ID2:=SQLQuery1.FieldByName('LastInsertID').AsLargeInt;

ID1 is 0 and ID2 the correct id value.

Any ideas what I could be doing wrong?

R.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, Reimar Grabowski wrote:


On Fri, 14 Nov 2014 14:50:20 +0100
Reimar Grabowski reimg...@web.de wrote:


On Fri, 14 Nov 2014 14:15:08 +0100 (CET)
Michael Van Canneyt mich...@freepascal.org wrote:


Connections for databases that have lastinsertID you can call the method 
created for this:

Function GetInsertID: int64;

Unfortunately it does not work and returns only 0, while my custom query using 
LAST_INSERT_ID() works as expected.
Debugging this is very hard as Lazarus crashes on me left and right when trying 
to step through the code and an exception is encountered.
I have one connection, one transaction and some queries bound to them on a 
FPWebModule.

ID1:=MySQL55Connection1.GetInsertID;
SQLQuery1.Open;
ID2:=SQLQuery1.FieldByName('LastInsertID').AsLargeInt;

ID1 is 0 and ID2 the correct id value.

Any ideas what I could be doing wrong?


This is what it does:

function TConnectionName.GetInsertID: Int64;
begin
  CheckConnected;
  Result:=mysql_insert_id(GetHandle);
end;

a) Did you do an insert right before the call to GetInsertID ?
b) Is the transaction active after the insert ? 
c) The connection transaction should be the same as the transaction of the insert.


Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Michael Van Canneyt



On Fri, 14 Nov 2014, Marcos Douglas wrote:


specify a refresh SQL statement.
   (coincidentally: these are the engines that use autoInc type fields
instead of sequences)


This option, to specify a SQL statement, is the programmer that write
the SQL? This should come from driver, don't?


If the driver can create it: yes.

Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 3:23 PM, Michael Van Canneyt mich...@freepascal.org
 wrote:

 On Fri, 14 Nov 2014, Reimar Grabowski wrote:

 On Fri, 14 Nov 2014 14:50:20 +0100
 Reimar Grabowski reimg...@web.de wrote:

  On Fri, 14 Nov 2014 14:15:08 +0100 (CET)
 Michael Van Canneyt mich...@freepascal.org wrote:

  Connections for databases that have lastinsertID you can call the
 method created for this:

 Function GetInsertID: int64;

 Unfortunately it does not work and returns only 0, while my custom query
 using LAST_INSERT_ID() works as expected.
 Debugging this is very hard as Lazarus crashes on me left and right when
 trying to step through the code and an exception is encountered.
 I have one connection, one transaction and some queries bound to them on
 a FPWebModule.

 ID1:=MySQL55Connection1.GetInsertID;
 SQLQuery1.Open;
 ID2:=SQLQuery1.FieldByName('LastInsertID').AsLargeInt;

 ID1 is 0 and ID2 the correct id value.

 Any ideas what I could be doing wrong?


 This is what it does:

 function TConnectionName.GetInsertID: Int64;
 begin
   CheckConnected;
   Result:=mysql_insert_id(GetHandle);
 end;

 a) Did you do an insert right before the call to GetInsertID ?
 b) Is the transaction active after the insert ? c) The connection
 transaction should be the same as the transaction of the insert.


Work fine here (MySQL 5.5 32 bits / Lazarus 1.2.6 r46529 FPC 2.6.4
i386-win32-win32/win64 / Windows 7 64 bits):

unit1.lfm:

object Form1: TForm1
  Left = 238
  Height = 240
  Top = 144
  Width = 320
  Caption = 'Form1'
  ClientHeight = 240
  ClientWidth = 320
  LCLVersion = '1.2.6.0'
  object Button1: TButton
Left = 10
Height = 25
Top = 8
Width = 75
Caption = 'Button1'
OnClick = Button1Click
TabOrder = 0
  end
  object MySQL55Connection1: TMySQL55Connection
Connected = False
LoginPrompt = False
DatabaseName = 'test'
KeepConnection = False
Password = 'root'
Transaction = SQLTransaction1
UserName = 'root'
HostName = '127.0.0.1'
LogEvents = []
left = 40
top = 16
  end
  object SQLQuery1: TSQLQuery
FieldDefs = 
Database = MySQL55Connection1
Transaction = SQLTransaction1
Params = 
left = 88
top = 116
  end
  object SQLTransaction1: TSQLTransaction
Active = False
Database = MySQL55Connection1
left = 147
top = 45
  end
end

...

unit1.pas:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  SysUtils, mysql55conn, sqldb, Forms, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
Button1: TButton;
MySQL55Connection1: TMySQL55Connection;
SQLQuery1: TSQLQuery;
SQLTransaction1: TSQLTransaction;
procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  SQLQuery1.SQL.Text := 'insert into test (foo) values (:foo)';
  SQLQuery1.Params.ParamByName('foo').AsString := DateTimeToStr(Now);
  SQLQuery1.ExecSQL;
  ShowMessageFmt('%d', [MySQL55Connection1.GetInsertID]);
end;

end.

Result after three clicks:

[Window Title]
project1

[Content]
4

[OK]

SQL:

-- phpMyAdmin SQL Dump
-- version 4.2.11
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: 14-Nov-2014 às 17:09
-- Versão do servidor: 5.5.40
-- PHP Version: 5.3.21

SET SQL_MODE = NO_AUTO_VALUE_ON_ZERO;
SET time_zone = +00:00;

--
-- Database: `test`
--

-- 

--
-- Estrutura da tabela `test`
--

CREATE TABLE IF NOT EXISTS `test` (
`id` int(11) NOT NULL,
  `foo` varchar(20) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `test`
--
ALTER TABLE `test`
 ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `test`
--
ALTER TABLE `test`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5;

-- 
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Marco van de Voort
On Fri, Nov 14, 2014 at 03:11:30PM +0100, Michael Van Canneyt wrote:
 
 By the very nature of the problem: GetLastAutoIncValue simply cannot be 
 implemented in general.
 
 In firebird, postgres,

(and Oracle afaik)

 these values are generated using a generator/sequence.
 You don't know the name of the generator, and even if you did, it is 
 impossible 
 to retrieve the value that was used to fill your particular record because 
 the 
 sequence/generator may have been updated several thousands of times by the 
 time 
 your second statement arrives.

IIRC the currval from a sequence  is per session, so if you didn't insert
again in the same transaction that is ok too. 

Moverover there is lastval to avoid knowing the sequence name

from http://www.postgresql.org/docs/8.4/static/functions-sequence.html

lastval

Return the value most recently returned by nextval in the current
session. This function is identical to currval, except that instead of
taking the sequence name as an argument it fetches the value of the last
sequence used by nextval in the current session. It is an error to call
lastval if nextval has not yet been called in the current session.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread silvioprog
On Fri, Nov 14, 2014 at 8:32 PM, Marco van de Voort mar...@stack.nl wrote:

 On Fri, Nov 14, 2014 at 03:11:30PM +0100, Michael Van Canneyt wrote:
 
  By the very nature of the problem: GetLastAutoIncValue simply cannot be
 implemented in general.
 
  In firebird, postgres,

 (and Oracle afaik)

  these values are generated using a generator/sequence.
  You don't know the name of the generator, and even if you did, it is
 impossible
  to retrieve the value that was used to fill your particular record
 because the
  sequence/generator may have been updated several thousands of times by
 the time
  your second statement arrives.

 IIRC the currval from a sequence  is per session, so if you didn't insert
 again in the same transaction that is ok too.

 Moverover there is lastval to avoid knowing the sequence name

 from http://www.postgresql.org/docs/8.4/static/functions-sequence.html

 lastval

 Return the value most recently returned by nextval in the current
 session. This function is identical to currval, except that instead of
 taking the sequence name as an argument it fetches the value of the last
 sequence used by nextval in the current session. It is an error to call
 lastval if nextval has not yet been called in the current session.


And PostgreSQL provides the RETURNING feature too. =)

--
Silvio Clécio
My public projects - github.com/silvioprog
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)

2014-11-14 Thread Reimar Grabowski
On Fri, 14 Nov 2014 19:23:50 +0100 (CET)
Michael Van Canneyt mich...@freepascal.org wrote:

 a) Did you do an insert right before the call to GetInsertID ?
 b) Is the transaction active after the insert ? 
 c) The connection transaction should be the same as the transaction of the 
 insert.

Got it working.

MySQL55Connection1.Connected:=True;
SQLTransaction1.Active:=True;
SQLQuery.Active:=True;
SQLQuery.Insert;
SQLQuery.FieldByName(...);
...
SQLQuery.Post;
SQLQuery.ApplyUpdates;
writeln('ID1: ', MySQL55Connection1.GetInsertID);
SQLTransaction1.Commit;
writeln('ID2: ', MySQL55Connection1.GetInsertID);
SQLQuery1.Open;
writeln('ID3: ', SQLQuery1.FieldByName('LastInserID').AsLargeInt);

ID1 and ID3 are correct but ID2 = 0

So GetInsertID works only before the commit.

Thanks
R.





--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus