Skip to content

Fix #4081: Quote DEFAULT values in TEXT fields when exporting SQL#4092

Open
Sohoocelery wants to merge 2 commits intosqlitebrowser:masterfrom
Sohoocelery:patch-2
Open

Fix #4081: Quote DEFAULT values in TEXT fields when exporting SQL#4092
Sohoocelery wants to merge 2 commits intosqlitebrowser:masterfrom
Sohoocelery:patch-2

Conversation

@Sohoocelery
Copy link

Fix Description

This PR fixes issue #4081 where DEFAULT values for TEXT fields were not being properly quoted when exporting to SQL.

Problem

When exporting a database table with a TEXT column that has a DEFAULT value to SQL, the generated SQL statement was invalid:

CREATE TABLE "content" (
  "WishlistedDate" TEXT DEFAULT 0000-00-00T00:00:00.000
);

This fails when re-importing because the unquoted value is interpreted as an invalid expression.

Solution

Modified DefaultConstraint::toSql() in src/sql/sqlitetypes.cpp to wrap DEFAULT values in single quotes:

CREATE TABLE "content" (
  "WishlistedDate" TEXT DEFAULT '0000-00-00T00:00:00.000'
);

Testing

The fix ensures that exported SQL files can be successfully re-imported without errors.

@FriedrichFroebel
Copy link
Contributor

Could you please indicate whether this would affect other data types as well?

@Sohoocelery
Copy link
Author

Could you please indicate whether this would affect other data types as well?

As far as I know this would only affect DEFAULT TEXT values as it was not wrapped with quotes in the sqlitetypes branch and the error only occurred when i tried to re-import a sql file containing this data type.

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.

2 participants