-
Notifications
You must be signed in to change notification settings - Fork 689
Fix INSERT INTO SELECT FROM parameter overwriting data with defaults #2210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
efe76d6
Initial plan
Copilot e39269b
Add test to reproduce INSERT SELECT FROM ? issue with empty values
Copilot 718c191
Fix INSERT SELECT FROM ? inserting empty values by reversing extend o…
Copilot a1ccb86
Format code and remove test artifact file
Copilot 6b6ddc0
Use assert.deepEqual for complete object comparison in tests
Copilot 36db816
Remove unnecessary done() callbacks from synchronous tests
Copilot 1dc5642
Merge branch 'develop' into copilot/fix-insert-empty-records
mathiasrw 121c5c9
Merge branch 'develop' into copilot/fix-insert-empty-records
mathiasrw 59c237c
Remove console.log statements from test output
Copilot c2554ec
Merge branch 'develop' into copilot/fix-insert-empty-records
mathiasrw cff9610
Merge branch 'develop' into copilot/fix-insert-empty-records
mathiasrw 8b331c0
Rename test file from test_insert_from_param.js to test1484.js
Copilot 3059cfa
Merge branch 'develop' into copilot/fix-insert-empty-records
mathiasrw 032ae22
Fix default value application to only set missing properties
Copilot 553f5ec
Add comprehensive edge case tests for INSERT with defaults
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| if (typeof exports === 'object') { | ||
| var assert = require('assert'); | ||
| var alasql = require('..'); | ||
| } | ||
|
|
||
| describe('Test INSERT FROM parameter issue', function () { | ||
| it('INSERT INTO table SELECT * FROM ? with data array', function (done) { | ||
| // Create a new database like in the issue | ||
| var inmemDB = new alasql.Database('test_insert_db'); | ||
|
|
||
| // Create table | ||
| var query = | ||
| "CREATE TABLE IF NOT EXISTS [BCPartners] (RecordNum INTEGER PRIMARY KEY AUTOINCREMENT, [TABLE_NAME] TEXT DEFAULT '', [BC] TEXT DEFAULT '')"; | ||
| inmemDB.exec(query); | ||
|
|
||
| // Prepare test data | ||
| var data = [ | ||
| {TABLE_NAME: 'Table1', BC: 'BC1'}, | ||
| {TABLE_NAME: 'Table2', BC: 'BC2'}, | ||
| {TABLE_NAME: 'Table3', BC: 'BC3'}, | ||
| ]; | ||
|
|
||
| // Insert data | ||
| inmemDB.exec('INSERT INTO [BCPartners] SELECT * FROM ?', [data]); | ||
|
|
||
| // Verify data was inserted correctly | ||
| var result = inmemDB.exec('SELECT * FROM [BCPartners]'); | ||
|
|
||
| console.log('Result:', JSON.stringify(result, null, 2)); | ||
|
|
||
| assert.equal(result.length, 3, 'Should have 3 records'); | ||
| assert.equal(result[0].TABLE_NAME, 'Table1', 'First record TABLE_NAME should be Table1'); | ||
| assert.equal(result[0].BC, 'BC1', 'First record BC should be BC1'); | ||
| assert.equal(result[1].TABLE_NAME, 'Table2', 'Second record TABLE_NAME should be Table2'); | ||
| assert.equal(result[1].BC, 'BC2', 'Second record BC should be BC2'); | ||
| assert.equal(result[2].TABLE_NAME, 'Table3', 'Third record TABLE_NAME should be Table3'); | ||
| assert.equal(result[2].BC, 'BC3', 'Third record BC should be BC3'); | ||
|
|
||
| // Clean up | ||
| alasql('DROP DATABASE test_insert_db'); | ||
| done(); | ||
| }); | ||
|
|
||
| it('INSERT INTO table SELECT * FROM ? using default database', function (done) { | ||
| // Test with default database (alasql) | ||
| alasql('DROP TABLE IF EXISTS BCPartners'); | ||
| alasql( | ||
| "CREATE TABLE BCPartners (RecordNum INTEGER PRIMARY KEY AUTOINCREMENT, TABLE_NAME TEXT DEFAULT '', BC TEXT DEFAULT '')" | ||
| ); | ||
|
|
||
| // Prepare test data | ||
| var data = [ | ||
| {TABLE_NAME: 'Table1', BC: 'BC1'}, | ||
| {TABLE_NAME: 'Table2', BC: 'BC2'}, | ||
| ]; | ||
|
|
||
| // Insert data | ||
| alasql('INSERT INTO BCPartners SELECT * FROM ?', [data]); | ||
|
|
||
| // Verify data was inserted correctly | ||
| var result = alasql('SELECT * FROM BCPartners'); | ||
|
|
||
| console.log('Default DB Result:', JSON.stringify(result, null, 2)); | ||
|
|
||
| assert.equal(result.length, 2, 'Should have 2 records'); | ||
| assert.equal(result[0].TABLE_NAME, 'Table1', 'First record TABLE_NAME should be Table1'); | ||
| assert.equal(result[0].BC, 'BC1', 'First record BC should be BC1'); | ||
| assert.equal(result[1].TABLE_NAME, 'Table2', 'Second record TABLE_NAME should be Table2'); | ||
| assert.equal(result[1].BC, 'BC2', 'Second record BC should be BC2'); | ||
|
|
||
| // Clean up | ||
| alasql('DROP TABLE BCPartners'); | ||
| done(); | ||
mathiasrw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.