Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Fix DELETE statement issue - Test and Verification

  • Understand the issue: User reported DELETE without WHERE not working
  • Explore the codebase (src/72delete.js and alasqlparser.jison)
  • Create test file test856.js to verify the issue
  • Run test and confirm DELETE without WHERE actually works correctly
  • Verify with manual testing
  • Address code review feedback:
    • Use before/after hooks instead of separate test cases
    • Remove done callbacks from synchronous tests
    • Format code with prettier

Findings

The issue reported in #856 appears to have been already fixed in the current codebase:

  1. The grammar in alasqlparser.jison (lines 1775-1776) supports DELETE FROM Table without WHERE clause
  2. The implementation in src/72delete.js (lines 108-136) handles the no-WHERE case correctly
  3. All tests pass with improved test structure using before/after hooks

The workaround mentioned (DELETE FROM table WHERE 1=1) is no longer necessary.

Original prompt

This section details on the original issue you should resolve

<issue_title>DELETE not working without WHERE xxx</issue_title>
<issue_description>delete from statement dont work if i dont add where.
so I had to do work around like 'delete from SomeKindOfTable where 1=1'</issue_description>

<agent_instructions>Please make a test file called test856.js verifying if this issue is still a problem.

If it is a problem try to solve it.

If you need to update the grammar of alasql, then please do small precice changes to alasqlparser.jison and then run yarn jison && yarn test</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@mathiasrw Thanks for letting us know. Its really good that you check things like this so the library can get better! @mathiasrw For sure!

The code base is the beast here... not SQL or JS.

Lets work on it together.

As a start I suggest that you follow the first steps in https://github.com/agershun/alasql/blob/develop/CONTRIBUTING.md until you have a new test that fails and then make a PR so we can have a good place to talk about things.

Future input: I have a feeling we have to find out if https://github.com/agershun/alasql/blob/7c528a44b9f01b170f764a95d338576bf894ae99/src/72delete.js#L25 is true even if no WHERE was set...

@mathiasrw Hmmmmm

Strange. The test should always pass before pushing to develop. (last push did not fail on travis)

What version of node are you using? WIndows? mac? Linux? Lets get this sorted...</comment_new>
<comment_new>@mathiasrw
It works on my computer right now.

I have a feeling its related to timezone. (dates are given in UTC but methods on it works on local time)

Can you try to change 7. Create table with default conversion Date test function to the following and let me know if this works out for you

		delete alasql.fn.Date;
		alasql('CREATE TABLE four (d Date)');

		alasql('INSERT INTO four VALUES ("2014-06-02"), ("2015-06-03")');

		var res = alasql("SELECT COLUMN YEAR(d) FROM four");
		assert.deepEqual(res,[2014,2015]);

		var res = alasql("SELECT COLUMN MONTH(d) FROM four");
		assert.deepEqual(res,[6,6]);

		var res = alasql("SELECT COLUMN DAY(d) FROM four");
		assert.deepEqual(res,[2,3]);

//		console.log(res);
		var res = alasql("SELECT COLUMN d FROM four");
		assert.deepEqual(res,["2014-06-02","2015-06-03"]);

(date changes from first and second day to second and 3rd day of june)</comment_new>
<comment_new>@mathiasrw
Hmm. I see. It is the timezone.

Try using this updated version of the test

https://github.com/agershun/alasql/blob/develop/test/test140.js#L107-L108</comment_new>
<comment_new>@mathiasrw
Could this is be a INDEXEDDB related problem?

@peon501 As a side note I recommend using the lazy promise notation for async calls:

alasql([    'CREATE INDEXEDDB DATABASE IF NOT EXISTS testdb; ATTACH INDEXEDDB DATABASE testdb;USE testdb;',
	    "CREATE TABLE IF NOT EXISTS Something (id,text);",
	    'delete  from `Something` ',
	    'insert into `Something`  ( id,text) values (1,"test")'
	]).then(function(){
	    console.log('ok');
	});
```</body></comment_new>
<comment_new><author>@mathiasrw</author><body>
> This problem coud occur for someone if they have to do some stuff in between deleting.

@peon501 Can you explain this in a code example?

Please give me a hint to any wiki things that should be fixed. 

Im working on getting the documentation into https://github.com/AlaSQL/alasql-docs so a simple PR could do it, but until its done just post it here or in a new issue. </body></comment_new>
<comment_new><author>@mathiasrw</author><body>
Can you send PR to a wiki on github? Sure - bring it ON!</body></comment_new>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix DELETE statement issue without WHERE clause Add regression test for DELETE without WHERE clause (issue #856) Nov 19, 2025
Copilot AI requested a review from mathiasrw November 19, 2025 10:03
Copilot finished work on behalf of mathiasrw November 19, 2025 10:03
@mathiasrw
Copy link
Member

@copilot

Run yarn test-format-all
yarn run v1.22.22
$ prettier --list-different '{.,src,test}/*.{js,ts,json}' || (echo 'Please correct file formatting using yarn format-all and try again.' && exit 1)
test/test856.js
Please correct file formatting using yarn format-all and try again.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@copilot

Run yarn test-format-all
...

Formatted test856.js with prettier. File now passes yarn test-format-all check. Changes in commit c7f65f4.

Copilot AI requested a review from mathiasrw November 19, 2025 12:48
Copilot finished work on behalf of mathiasrw November 19, 2025 12:48
@mathiasrw mathiasrw marked this pull request as ready for review November 19, 2025 12:54
Copy link
Member

@mathiasrw mathiasrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@mathiasrw mathiasrw merged commit f9f6e75 into develop Nov 19, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DELETE not working without WHERE xxx

2 participants