completetly different CSV export SQL?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 360
Joined: 2019-05-21 22:42
Contact:

completetly different CSV export SQL?

Post by onoehring » 2019-07-04 08:19

Hi,
I use the "auditor" for some (2) tables. When the user access the auditor table he sees the res_id. When the user exports the results as CSV, I want to use a query that is a UNION and adds another field to the CSV output.
This new field is not exported. ... Does the csv export actually outputs only the available fields only, ignoring additional fields that might have been added by the SQL in the tablename_CSV hook?

Olaf

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 295
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: completetly different CSV export SQL?

Post by jsetzer » 2019-07-04 08:43

Hi Olaf,

have a look at the Render() function in datalist.php. Find the line // hook: table_csv and study the code before and behind that line.

There you will see that you can slightly modify the CSV output, but you cannot completely rewrite the query, because certain variables like the fields will not be re-evaluated after the hook-call. That's a pity and already reported as a bug/feature-request. But that's the Status-Quo which we have to accept and to deal with for now.

From my experience, if you need a bullet-proof, customized solution, study that Render()-function and create your individual CSV-creation- and download-page by yourself as a custom page. Doing it on your own, you will also be able to use different field-delimiters (for example ";" instead of ","), quotation of strings, escaping of characters, formatting data (for example date-times) etc. to keep data-integrity and compatibility with other systems.

Regards,
Jan

onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 360
Joined: 2019-05-21 22:42
Contact:

Re: completetly different CSV export SQL?

Post by onoehring » 2019-07-04 09:13

Hi Jan,

thanks for the explanation. I will keep my thumbs pressed for future versions.
I case Ahmed is reading along, I also think the explanation in the docs (p. 54-55) is not good enough and actually suggests you can form a query sting like you want to.

Olaf

User avatar
a.gneady
Site Admin
Posts: 1041
Joined: 2012-09-27 14:46
Contact:

Re: completetly different CSV export SQL?

Post by a.gneady » 2019-07-06 10:36

@Olaf, try this temporary fix for now, till next release: In datalist.php, find this line:

Code: Select all

$result = sql($csvQuery, $eo);
And add this one after it:

Code: Select all

$FieldCountCSV = db_num_fields($result);
I hope that helps.
:idea: Learn all the tips and tricks of customizing AppGini apps through our online course.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 360
Joined: 2019-05-21 22:42
Contact:

Re: completetly different CSV export SQL?

Post by onoehring » 2019-07-06 15:05

Hi Ahmed,

thank you for the quick fix. I did try it - and it works perfectly. Now it seems you can any SQL query with any number (and any name) of columns - the CSV is that of that query.

Great!

For now I created another workaround (as datalist will be overwritten once the - developing - project gets updated). I created a view in the database that collects all information (as right now I do not have anything else than to display some data). I created a "table" in AG with that same name of the view. It that can be seen in the generated app and can be exported properly.

Olaf

Post Reply