"resources/views/components/navbar.blade.php" did not exist on "72fb721a3b83cbf142b320c98eff5388983294a6"
Commit 9885e03c authored by Sarun Mungthanya's avatar Sarun Mungthanya
Browse files

issue data value twice

parent a2dc6ebe
......@@ -574,12 +574,10 @@ class SmartUpdateController extends Controller
public static function generateInsertSQLWithCount($sourceTable, $destinationTable, $conditionColumn, $conditionValue, $additionalColumns)
{
// Fetch data from the source table based on the condition
$rows = DB::table($sourceTable)
->where($conditionColumn, 'like', $conditionValue)
->get();
// Check if rows exist
if ($rows->isEmpty()) {
return [
'total' => 0,
......@@ -587,7 +585,6 @@ class SmartUpdateController extends Controller
];
}
// Detect the database type
$dbType = config('database.default');
$quoteL = $dbType === 'sqlsrv' ? '[' : '`';
$quoteR = $dbType === 'sqlsrv' ? ']' : '`';
......@@ -597,12 +594,9 @@ class SmartUpdateController extends Controller
foreach ($rows as $row) {
$values = [];
// Include all columns from the row dynamically
foreach ((array)$row as $column => $value) {
// Escape single quotes for MSSQL and MySQL
$escapedValue = str_replace("'", "''", $value);
// Handle special MSSQL cases, e.g., default datetime
if ($escapedValue === '0000-00-00 00:00:00') {
$escapedValue = '2000-01-01 00:00:00';
}
......@@ -610,21 +604,12 @@ class SmartUpdateController extends Controller
$values[] = "'$escapedValue'";
}
// Append additional columns (e.g., `amenddate`) dynamically
foreach ($additionalColumns as $key => $value) {
$escapedValue = str_replace("'", "''", $value);
$values[] = "'$escapedValue'";
}
// Create the INSERT statement
$columns = array_keys((array)$row);
// $columns = array_merge($columns, array_keys($additionalColumns));
$quotedColumns = array_map(fn($col) => $quoteL . $col . $quoteR, $columns);
$insertStatements[] = "INSERT INTO $quoteL$destinationTable$quoteR (" . implode(', ', $quotedColumns) . ") VALUES (" . implode(', ', $values) . ");";
}
// Combine all statements into a single string
return [
'total' => $rows->count(),
'sql' => implode("\n", $insertStatements)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment