Heidisql: Heidi SQL does not properly update records using a field with datatype bit

Created on 15 May 2018  ·  5Comments  ·  Source: HeidiSQL/HeidiSQL

Steps to reproduce this issue

  1. Step 1; Create a simple table with "ID" (int); "text(varchar50)"; "bit type" (bit)
  2. Step 2; Fill the table with 2 records according their data types.
  3. Step N; Update the text with another text and press the "post" button
  4. Then I get...the error "SQL Error (102): Incorrect syntax near '0'

Current behavior

the problem is the generated SQL does not conform with the SQL standards therefor the error appears.
Sample
UPDATE TOP(1) "Checkmarx"."dbo"."bit test table"
SET "text"='test5'
WHERE "ID"=4
AND "text"='test4'
AND "bity type"=b'0';
/* SQL Error (102): Incorrect syntax near '0'. */
the reason is because the "bity type"=b'0' is incorrect. the "b" should not be there!

Expected behavior

UPDATE TOP(1) "Checkmarx"."dbo"."bit test table"
SET "text"='test5'
WHERE "ID"=4
AND "text"='test4'
AND "bity type"='0';
This is the manually corrected syntax without the "b". this can be run normally in the "query" option and the text is updated correctly to 'test5'

Possible solution

change the tool so it does create the correct SQL syntax for Microsoft SQL server so this error disappears. I might look into the code later on to provide more details if needed.

Environment

  • HeidiSQL version:

    version 9.5.0.5278 latest built

  • Database system and version:

    I am not sure but it looks like the syntax might be right for another Database than Microsoft SQL therefore it's relevant to mention the DB.

latest built of MSSQL server 2012 built 11.0.7469.6

  • Operating system:

not relevant

Most helpful comment

Hi,
I looked into the code it appears the issue in the file dbconnections.pas , there are 3 lines where 'b' is used. it appears that in line 7290 is MYSQL specific, the generic function seems to be in line 6628. most likely the issue is there. 'b' should not be added in case of MSSQL. this is my recommendation. I cannot test is as I don not have the environment to build a new version. I hope this helps!

All 5 comments

Hi,
I looked into the code it appears the issue in the file dbconnections.pas , there are 3 lines where 'b' is used. it appears that in line 7290 is MYSQL specific, the generic function seems to be in line 6628. most likely the issue is there. 'b' should not be added in case of MSSQL. this is my recommendation. I cannot test is as I don not have the environment to build a new version. I hope this helps!

I also have this problem, it always happens when editing a field in a MSSQL table which does not have a Primary Key.

I have the same problem on MSSQL, but I do have a primary key.
When I change the UserName the all bit fields change to "T,rue" or "F,alse"
But when I refresh I becomes 1's and 0's.

CREATE TABLE "UsersFile" (
"UserId" INT NOT NULL,
"UserActive" BIT NULL DEFAULT NULL,
"userrealname" VARCHAR(100) NULL DEFAULT NULL,
"UserName" VARCHAR(15) NOT NULL,
"Password" VARCHAR(32) NULL DEFAULT NULL,
"ViewRight" BIT NULL DEFAULT NULL,
"AddRight" BIT NULL DEFAULT NULL,
"EditRight" BIT NULL DEFAULT NULL,
"DeleteRight" BIT NULL DEFAULT NULL,
"UserActivityRight" BIT NULL DEFAULT NULL,
"ManagmentRight" BIT NULL DEFAULT NULL,
PRIMARY KEY ("UserName"),
UNIQUE INDEX "UNIQUE" ("UserId")
)
;

This is still a problem in HeidiSQL Version 11.0.0.6049 (64 Bit) with MSSQL 13.0 (SQL Server 2016).

Per the documentation, bare numbers 0 and 1 should be enough:
https://docs.microsoft.com/en-us/sql/t-sql/data-types/constants-transact-sql?view=sql-server-2016#bit-constants

Alternatively, they are sometimes wrapped in parentheses, as in (0) and (1).

@ansgarbecker up? 🙂

Was this page helpful?
0 / 5 - 0 ratings