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
User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
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: 1807
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
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
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: 1281
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: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
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

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: completetly different CSV export SQL?

Post by sacgtdev » 2023-04-07 09:20

I have a page xxx.com?ids=1,2,3 where 1,2,3 is the record id.
I able to filter the table by record ids but the save csv doesn't work as expected.

I have tried to amend the tablename_csv function in hooks by reconstructing the query.
I able to reconstruct the query by replacing part of the original query and adding hard-coded $variable = "1,2,3". And, the re-constructed query able to return csv with 3 records.

However, if I try to _REQUEST['ids'] from hooks, I couldn't get the ids specified in the the url. The same code to get the ids if placed in init function does work, but doesn't work in tablename_csv function. Making the variable global in init function also couldn't pass the same variable to the csv function.

Any other idea how to resolve it?

Post Reply