Forum > Databases

TDBTreeView not usable with TDataSource and TJSONDataSet?

(1/2) > >>

indydev:
Datasets, DataSources, and DBControls are new to me. I am trying to understand how these work.

This came about because of a large and complicated JSON file (at least for me) I am working with. I found this JSONDataset control and wondered if I could get the file contents displayed in a DBTreeView to make it easier for me to Examine the JSON file.

I placed Datasource, JSONDataset and DBTreeview controls on my form. When trying to connect them DBTreeView complains that it needs TSQLQuery for the Dataset. A DBGrid does not make this complaint.

This is as far as I got, but if this use of DBTreeView is not possible, then I will need to find a different process.

rvk:
It seems to be because TDBTreeView needs to manipulate the WHEN clause of the SQL statement.

https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/38336

--- Quote ---The only requirement for DBTreeView TSQLQuery object is to save a line with "Where"clause in the SQL Query.
--- End quote ---

indydev:
Ok. I see this statement:

"To generalize applicability of the DBTreeView, you could introduce a Mode property: TDBTreeViewMode = (tvmSimple, tvmFilter, tvmSQL). tvmSimple should work for all datasets: when the tree seeks the child nodes of a given node the dataset iterates through all records and picks those which have a matching ParentID. tvmFilter works for all datasets supporting the Filter/OnFilter mechanism to select the records having the requested ParentID. And tvmSQL, finally, does this by sending SQL queries; but in order to be indpendent of the dataset type there should be an event in which the user can cast to the TDataset descendant required in order be able to apply the correct SQL syntax. I could also imagine that there is an "adapter" component for each SQLQuery type (TSQLQueryTreeViewAdapter, TIBQueryTreeViewAdapter, TZeosTreeViewAdapter) which executes the query and returns the found records; this would have the advantage that the treeview could show data already at designtime, but the disadvantage that the component authors must provide this adapter class and that the component palette would be filled even more."

But I guess it never happened.   :'(

tonyw:

--- Quote from: rvk on February 10, 2024, 08:08:57 pm ---It seems to be because TDBTreeView needs to manipulate the WHEN clause of the SQL statement.

https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/38336

--- Quote ---The only requirement for DBTreeView TSQLQuery object is to save a line with "Where"clause in the SQL Query.
--- End quote ---

--- End quote ---

TDBTreeView was adapted for TSQLQuery from the original TIBTreeView that I wrote for IBX. That was possible, because the underlying requirement was for a query based dataset. The control repeatedly queries the dataset, each time selecting the required tree level. It will not work with any TDataset descendent. E.g. Tmemdataset is not query based. I assume that TJSONDataset is not query based, in which case, it would not be possible to adapt the control for use with it.

wp:

--- Quote from: indydev on February 10, 2024, 08:02:36 pm ---I found this JSONDataset control and wondered if I could get the file contents displayed in a DBTreeView to make it easier for me to Examine the JSON file.

--- End quote ---
I could tell you that maybe the TJvDBTreeView might be an alternative because it does not use SQL to filter the tree nodes. But really - looking at the JSONDataset for the first time was not very motivating. It has no property indicating that a file can be loaded into it. You will have a steep learning curve I'm afraid.

On the other hand, just to learn about a json structure, why don't you use one of the json viewers out there? For example the nice laz-json-viewer (https://github.com/gcarreno/laz-JSON-Viewer), written in Lazarus by forum user Gustavo 'Gus' Carreno. Compile the code that you can download from that site, run the application and drag the file(s) of interest on the application form. There are both tree and raw json views.

Navigation

[0] Message Index

[#] Next page

Go to full version