function amr_csvlines_to_csvbatch($lines) { // convert array to csv separated stuff $csvlines = array(); foreach ($lines as $k => $line) { $csvlines[]['csvcontent'] = amr_cells_to_csv($line); } $c = new adb_cache(); // $rptid = amr_rptid( (int) ($_REQUEST['ulist'])); // not working - wait till new query functionality // $headinglines = $c->get_column_headings($rptid); // array_unshift( $csvlines, $headinglines[1]); return $csvlines; }
function cache_batch_lines($reportid, $start, $lines) { // cache a batch global $wpdb; $wpdb->show_errors(); $sql = "INSERT INTO " . $this->table_name . " ( reportid, line, csvcontent ) " . "VALUES "; $sep = ','; $row = $start; $args = array(); foreach ($lines as $i => $line) { $csv = amr_cells_to_csv($line); if (!($row === $start)) { $sql .= $sep; } $sql .= "(%s,%d,%s)"; $args[] = $reportid; $args[] = $row; $args[] = $csv; // for any csv a doublequote must be represented by two double quotes *** // not ideal for other purposes, but until we redo the data 'warehouse' method this is it //$sql .= "('" . $reportid . "','" . $row. "','" . $csv . "')"; $row = $row + 1; } $sql = $wpdb->prepare($sql, $args); //esc_sql($sql); $results = $wpdb->query($sql); if (is_wp_error($results)) { echo __('Error inserting - maybe clashing with a background run?', 'amr-users') . $results->get_error_message(); die(__('Killing myself.. please check log and status and try again later.', 'amr-users')); } return $results; }