Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Export Browse to CSV issue

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
nc07
Posts: 118
Joined: Tue Jun 04, 2019 4:05 am
Has thanked: 5 times
Been thanked: 22 times

Export Browse to CSV issue

Unread post 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?.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Export Browse to CSV issue

Unread post by kev1n »

Hi,

How do you call the function in BB?
nc07
Posts: 118
Joined: Tue Jun 04, 2019 4:05 am
Has thanked: 5 times
Been thanked: 22 times

Re: Export Browse to CSV issue

Unread post 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
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Export Browse to CSV issue

Unread post 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.
nc07
Posts: 118
Joined: Tue Jun 04, 2019 4:05 am
Has thanked: 5 times
Been thanked: 22 times

Re: Export Browse to CSV issue

Unread post 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
KEE
Posts: 14
Joined: Sat Feb 24, 2018 1:17 pm
Been thanked: 2 times

Re: Export Browse to CSV issue

Unread post 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.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Export Browse to CSV issue

Unread post by kev1n »

Hi KEE,

Thanks for that! I'm updating the code snippet and optimise it at the same time.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Export Browse to CSV issue

Unread post by kev1n »

Here's the updated download code, leveraging the latest nuBuilder functions and incorporating nuRunPHPWithParams() from the updated nuajax.js
nc07
Posts: 118
Joined: Tue Jun 04, 2019 4:05 am
Has thanked: 5 times
Been thanked: 22 times

Re: Export Browse to CSV issue

Unread post 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.
Post Reply