Re: [Lazarus] Treeview Question

2020-06-30 Thread zeljko via lazarus

On 6/30/20 1:10 AM, Martin via lazarus wrote:

Hi,

I'm porting an application I started (but never finished) in Pyside to 
Lazarus. This question is only about cosmetics as Treeview works as I 
want it to.


In Pyside I could set a space between nodes by setting the node text as 
"" and disabling that node so it never gets selection, e.g.


     self.tvSpace001 = QTreeWidgetItem(self.leftTreeWidget)
     self.tvSpace001.setText(0, "")
     self.tvSpace001.setDisabled(True)

In Lazarus there seems to be no disabled property for nodes, so when 
transversing a node with text "" with the keyboard, it will move onto 
that empty node but not highlight it, when I would prefer it instead 
moved onto the next or previous node and highlight it.


I could write a workaround, storing the last node index, working out if 
the user has moved up or down, checking if the text is "" and 
highlighting the previous or next node as required, BUT I just wondered 
if anyone has a more simple, more elegant solution please?


It's only to show visual definition between groups of parents and childs 
and doesn't actually affect how the application works.


Lazarus uses it's own implementation of TTreeView, so you have to create 
your own LCL wrapper for QTreeWidget.


zeljko

--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Treeview Question

2020-06-30 Thread Martin Collins via lazarus
Thank you. I didn't particularly want to use QT in Lazarus but Pyside is QT 
only.


I'll get my application up and working first I think and then maybe have a 
look at the treeview source for cosmetic tweaks. Writing my own wrapper for 
a QT widget set is beyond my capabilities but thank you anyway.


Best regards,

Martin

On 30 June 2020 08:09:39 zeljko  wrote:


On 6/30/20 1:10 AM, Martin via lazarus wrote:

Hi,

I'm porting an application I started (but never finished) in Pyside to
Lazarus. This question is only about cosmetics as Treeview works as I
want it to.

In Pyside I could set a space between nodes by setting the node text as
"" and disabling that node so it never gets selection, e.g.

   self.tvSpace001 = QTreeWidgetItem(self.leftTreeWidget)
   self.tvSpace001.setText(0, "")
   self.tvSpace001.setDisabled(True)

In Lazarus there seems to be no disabled property for nodes, so when
transversing a node with text "" with the keyboard, it will move onto
that empty node but not highlight it, when I would prefer it instead
moved onto the next or previous node and highlight it.

I could write a workaround, storing the last node index, working out if
the user has moved up or down, checking if the text is "" and
highlighting the previous or next node as required, BUT I just wondered
if anyone has a more simple, more elegant solution please?

It's only to show visual definition between groups of parents and childs
and doesn't actually affect how the application works.


Lazarus uses it's own implementation of TTreeView, so you have to create
your own LCL wrapper for QTreeWidget.

zeljko


-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] SQLdb: Pseudo Transaction?

2020-06-30 Thread Special via lazarus

Am 30.06.2020 um 01:55 schrieb R.Smith via lazarus:
Just remove all the transaction bits of your code, and it should work 
fine.


Ryan,

your answer helps a lot; thank you.

Another (maybe stupid) question: What exactly is the purpose of a 
'transaction'? Do I need it for each SQL statement to be executed?


Thanx --  Joe
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Treeview Question

2020-06-30 Thread Juha Manninen via lazarus
On Tue, Jun 30, 2020 at 2:10 AM Martin via lazarus
 wrote:
> In Lazarus there seems to be no disabled property for nodes, ...

It could be implemented in TreeNode.
However property "Enabled" instead of "Disabled" would be more
consistent with other controls.

Juha
-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] Treeview Question

2020-06-30 Thread Mattias Gaertner via lazarus
On Tue, 30 Jun 2020 11:20:58 +0300
Juha Manninen via lazarus  wrote:

> On Tue, Jun 30, 2020 at 2:10 AM Martin via lazarus
>  wrote:
> > In Lazarus there seems to be no disabled property for nodes, ...  
> 
> It could be implemented in TreeNode.
> However property "Enabled" instead of "Disabled" would be more
> consistent with other controls.

Or you can write a descendant of TTreeView with your descendant of
TTreeNode.

Mattias
-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] SQLdb: Pseudo Transaction?

2020-06-30 Thread R.Smith via lazarus


Ryan,

your answer helps a lot; thank you.

Another (maybe stupid) question: What exactly is the purpose of a 
'transaction'? Do I need it for each SQL statement to be executed?



That's an excellent question in fact - lots of confusion out there.

Two main reasons, which I will quickly show - 1 - ACID guarantees 
(especially Isolation and Consistency, the others [Atomicity and 
Durability] you get anyway), and 2 - Speed.

(https://en.wikipedia.org/wiki/ACID)

In most DB engines (SQLite definitely) most executed commands gets their 
own little wrapped transaction if you did not start one explicitly - 
just to make the nuts and bolts of the engine function correctly. This 
might be a "lesser" form of transaction, but it has to at a minimum 
prepare the table, lock tables/rows/whatever, do the reading/writing, 
and then release those locks.


This also means that if you issue four commands, let's use an example 
(based loosely on a contacts-list table), say you execute these three in 
order:


SELECT MAX(ID) FROM contacts;
(The result of the previous statement is put into a variable, say: X)
INSERT INTO contacts(ID, FirstName, LastName, TimeAdded, ) VALUES 
(X+1, 'Joe', 'Soap', Now, ...);
INSERT INTO contacts(ID, FirstName, LastName, TimeAdded, ) VALUES 
(X+2, 'Joe', 'Jones', Now, ...);
INSERT INTO contacts(ID, FirstName, LastName, TimeAdded, ) VALUES 
(X+3, 'Joe', 'Smith', Now, ...);


Now inside the DB Engine, it is wrapped in pseudo-code like this 
(Obviously there is more going on, but I'm just mentioning the 
interesting bits to our example):


tt = Start_Transaction;
    qq = prepare query( SELECT MAX(ID) FROM contacts; ) :
        if (qq is READ Query)
        obtain_read_lock(tt, qq); // Executed
        ELSE
            obtain_write_lock(tt, qq);// Skipped
        run_query(qq);
        output_results;
        drop_locks(tt, qq);
    release_prepared_resources(qq);
    IF ERRORS > 0
        roll_back(tt);
    ELSE
    commit(tt);
release_transaction(tt);
tt = Start_Transaction;
    qq = prepare query( INSERT INTO contacts(ID, FirstName, LastName, 
TimeAdded, ...) VALUES (X+1, 'Joe', 'Soap', Now, ...); ) :

        if (qq is READ Query)
        obtain_read_lock(tt, qq);// Skipped
        ELSE
            obtain_write_lock(tt, qq); // Executed
        run_query(qq);
        output_results;
        drop_locks(tt, qq);
    release_prepared_resources(qq);
    IF ERRORS > 0
        roll_back(tt);
    ELSE
    commit(tt);
release_transaction(tt);
tt = Start_Transaction;
    qq = prepare query(INSERT INTO contacts(ID, FirstName, LastName, 
TimeAdded, ...) VALUES (X+2, 'Joe', 'Jones', Now, ...); ) :

        if (qq is READ Query)
        obtain_read_lock(tt, qq); // Skipped
        ELSE
            obtain_write_lock(tt, qq); // Executed
        run_query(qq);
        output_results;
        drop_locks(tt, qq);
    release_prepared_resources(qq);
    IF ERRORS > 0
        roll_back(tt);
    ELSE
    commit(tt);
release_transaction(tt);
tt = Start_Transaction;
    qq = prepare query(INSERT INTO contacts(ID, FirstName, LastName, 
TimeAdded, ...) VALUES (X+3, 'Joe', 'Smith', Now, ...); ) :

        if (qq is READ Query)
        obtain_read_lock(tt, qq);   // Skipped
        ELSE
            obtain_write_lock(tt, qq); // Executed
        run_query(qq);
        output_results;
        drop_locks(tt, qq);
    release_prepared_resources(qq);
    IF ERRORS > 0
        roll_back(tt);
    ELSE
    commit(tt);
release_transaction(tt);

The "output_results;" command might be a no-op for INSERT queries, 
though some DBs do return values.


Now note some things:
Towards Point 1 above:  If someone else also were trying to insert to 
this database at the same time, they might get an X that is in-between 
your inserts, and indeed insert values in between. This is called a 
concurrancy problem and is fixed by the "isolation" in an ACID transaction.
  (I know that behaviour can well be fixed by declaring the ID column 
with AUTO_INCREMENT, but let's imagine it wasn't in this example, you 
may well have other columns that must be Unique).


Note also that the inserted values for "Now()" would be slightly 
different every time since it's just a littlebit later when the next 
INSERT happens.  Inside a transaction, the TimeAdded values will all be 
the same.
Basically, while the transaction is in progress, and for the duration of 
it, no other connection to the same database can mess with those values, 
plus those values will remain consistent for the duration of the 
transaction. This is a very important property to many people.
There are a few other considerations to get technical with, like 
Serializability modes etc, allowing Dirty-reads, Read-uncommitted data 
(they don't fall in the scope of this discussion, but you can look them 
up if interested) - i'll only say here that not everyone wants their 
transactions to be closed off completely so Database Engines have 
switches/ways 

Re: [Lazarus] SQLdb: Pseudo Transaction?

2020-06-30 Thread Special via lazarus

Hi, Ryan,

I followed your advice and removed XTransaction and all references to it 
from TestButtonClick. But now I get an exception with the message 
"Transaction not set". Any hint?

Regards --  Joe
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] SQLdb: Pseudo Transaction?

2020-06-30 Thread Michael Van Canneyt via lazarus



On Tue, 30 Jun 2020, Special via lazarus wrote:


Hi, Ryan,

I followed your advice and removed XTransaction and all references to it 
from TestButtonClick. But now I get an exception with the message 
"Transaction not set". Any hint?


With SQLDB you always need a transaction component.

What you can do is set stoUseImplicit in the Transaction.Options:

https://www.freepascal.org/docs-html/current/fcl/sqldb/tsqltransaction.options.html

In that case the implicit transaction handling of the DB engine (SQLite in
this case) will be used, no explicit transaction statements will be emitted.

Michael.
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] SQLdb: Pseudo Transaction?

2020-06-30 Thread R.Smith via lazarus

On 2020/06/30 22:52, Special via lazarus wrote:

Hi, Ryan,

I followed your advice and removed XTransaction and all references to 
it from TestButtonClick. But now I get an exception with the message 
"Transaction not set". Any hint?

Regards --  Joe


I'm sorry, the previous problem was SQLite-related, which I'm 
initimately familiar with, but this one seems to be a Lazarus DB 
component requirement which I'm not so much familiar with, but probably 
has an easy solution someone here might know about.


The question becomes:  How to execute a query, without a transaction 
being set, using SQLdb in Lazarus?



PS: In case you wonder, we're in the process of porting an existing 
SQLite management tool (https://sqlitespeed.com) to open-source 
multi-platform from Delphi to FPC and Lazarus - It's been quite a job 
but going well, and I love the Lazarus/FPC environment more and more, 
will never go back to Delphi/VS. I do however access SQLite through the 
API rather than the SQLdb provided components, which is why I can tell 
you lots about SQL and SQLite but not so much about SQLdb... So 
apologies for that - hope someone can answer this with some more 
pertinent knowledge.




--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus