Page 1 of 1

Export Browse to CSV issue

Posted: Tue Jun 04, 2024 6:37 am
by nc07
Hi,

I have used BrowseDownloadToCSV to export browse data to CSV. if the SQL is used in forms SQL then all works fine however when the sql is used in BB, and when export function is called it gives error saying that the base table does not exist.

Code: Select all

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ictfjcom_demo_bis.___nu1665e950dd3bbc___' doesn't exist
. I have created similar function with Jquery only and works fine but limitation only displayed browse data is exported. any idea why temp table id is not recognized in the procedure?.

Re: Export Browse to CSV issue

Posted: Tue Jun 04, 2024 6:46 am
by kev1n
Hi,

How do you call the function in BB?

Re: Export Browse to CSV issue

Posted: Tue Jun 04, 2024 6:54 am
by nc07
kev1n wrote: Tue Jun 04, 2024 6:46 am Hi,

How do you call the function in BB?
I dont, With BB i meant if the sql was run in BB

Code: Select all

$itmnolevel = "
   CREATE TABLE #TABLE_ID#
   SELECT * FROM borderb_app
   WHERE bdr_status = 'Pending'
  
  ORDER BY bdr_id DESC
";
then the problem occurs when exporting to CSV. if i use it in browse sql

Code: Select all

SELECT * FROM borderb_app
   WHERE bdr_status = 'Pending'
  
  ORDER BY bdr_id DESC
all works fine

Re: Export Browse to CSV issue

Posted: Tue Jun 04, 2024 8:38 am
by kev1n
Temporary tables are not supported by that function. Therefore, in the procedure, you would need to execute procedure BB to create the temporary table, and then run the browse SQL again. This process is more complex than it appears.

Re: Export Browse to CSV issue

Posted: Tue Jun 04, 2024 10:04 pm
by nc07
kev1n wrote: Tue Jun 04, 2024 8:38 am Temporary tables are not supported by that function. Therefore, in the procedure, you would need to execute procedure BB to create the temporary table, and then run the browse SQL again. This process is more complex than it appears.
Thanks Kevin

Re: Export Browse to CSV issue

Posted: Thu Jun 06, 2024 5:12 pm
by KEE
nc07 wrote: Tue Jun 04, 2024 6:37 am Hi,

I have used BrowseDownloadToCSV to export browse data to CSV. if the SQL is used in forms SQL then all works fine however when the sql is used in BB, and when export function is called it gives error saying that the base table does not exist.

Code: Select all

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ictfjcom_demo_bis.___nu1665e950dd3bbc___' doesn't exist
. I have created similar function with Jquery only and works fine but limitation only displayed browse data is exported. any idea why temp table id is not recognized in the procedure?.
I added these lines to BrowseDownloadToCSV.php:

Code: Select all

//Retrieve the Browse SQL from hash cookie
$sql  = json_decode(base64_decode("#browse_sql#"));
// added: if the temporary table
$tt = "";
if (strpos($sql, '___') !== false) {
    nuEval("#form_id#" . "_BB");
    $tt = $_POST['nuHash']['TABLE_ID'];
    $sql = preg_replace("#___[\s\S]+___#im", $tt, $sql);
}

Code: Select all

//Fetch all of the rows from our table
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
// added: drop the table if it exists 
if ($tt != "") {
    $statement = $pdo->prepare("DROP TABLE $tt");
    $statement->execute();
}
and the issue was solved.

Re: Export Browse to CSV issue

Posted: Fri Jun 07, 2024 7:08 am
by kev1n
Hi KEE,

Thanks for that! I'm updating the code snippet and optimise it at the same time.

Re: Export Browse to CSV issue

Posted: Sat Jun 08, 2024 7:47 am
by kev1n
Here's the updated download code, leveraging the latest nuBuilder functions and incorporating nuRunPHPWithParams() from the updated nuajax.js

Re: Export Browse to CSV issue

Posted: Tue Jun 18, 2024 9:57 pm
by nc07
kev1n wrote: Sat Jun 08, 2024 7:47 am Here's the updated download code, leveraging the latest nuBuilder functions and incorporating nuRunPHPWithParams() from the updated nuajax.js
Thanks kevin, apologies for late reply, have tested the code and works as expected.