TZQuery opens a temporary table, all fields are read-only?

Forum related to MS SQL Server

Moderators: gto, cipto_kh, EgonHugeist

zhuyl
Junior Boarder
Junior Boarder
Posts: 26
Joined: 22.11.2021, 09:09

TZQuery opens a temporary table, all fields are read-only?

Post by zhuyl »

hello.
I use ZQuery to create a temporary table, and then open it, the fields are all read-only.
The database is mssql, zeos is 8.0
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZQuery opens a temporary table, all fields are read-only?

Post by marsupilami »

Hello,

yes - that might happen. I seem to rememeber something like this. The problem seems to be that we cannot get metadata for temporary tables - or at least we don't know how to get metadata for temporary tables.

Best regards,

Jan
zhuyl
Junior Boarder
Junior Boarder
Posts: 26
Joined: 22.11.2021, 09:09

Re: TZQuery opens a temporary table, all fields are read-only?

Post by zhuyl »

hello
Is there a way to solve this problem? Temporary tables are often used to read and write data.
Metadata can be obtained from tempdb. Before exec sp_columns, use tempdb to get no metadata.
MJFShark
Expert Boarder
Expert Boarder
Posts: 218
Joined: 04.06.2020, 13:59

Re: TZQuery opens a temporary table, all fields are read-only?

Post by MJFShark »

[Redacted thing I posted when I thought this was for MySQL and not SQLServer! Apologies!]

-Mark
Last edited by MJFShark on 18.12.2021, 15:27, edited 1 time in total.
zhuyl
Junior Boarder
Junior Boarder
Posts: 26
Joined: 22.11.2021, 09:09

Re: TZQuery opens a temporary table, all fields are read-only?

Post by zhuyl »

The database I use is MS SQL Server, and the temporary table created is in the database tempdb, from which the metadata of the table can be obtained.
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 796
Joined: 18.11.2018, 17:37
Location: Hungary

Re: TZQuery opens a temporary table, all fields are read-only?

Post by aehimself »

I have zero experience with temporary tables but I have a MSSQL server at home to test on.
If you can provide the queries to execute I can try to take a look at the issue.

P.s.: I'm using DBLib to connect, not ODBC or ADO.
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
zhuyl
Junior Boarder
Junior Boarder
Posts: 26
Joined: 22.11.2021, 09:09

Re: TZQuery opens a temporary table, all fields are read-only?

Post by zhuyl »

hello
I made a test example, you can test it, the database is ms sql server.
You do not have the required permissions to view the files attached to this post.
Last edited by zhuyl on 20.12.2021, 12:57, edited 1 time in total.
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 796
Joined: 18.11.2018, 17:37
Location: Hungary

Re: TZQuery opens a temporary table, all fields are read-only?

Post by aehimself »

...and where can I find it, exactly? :)
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
zhuyl
Junior Boarder
Junior Boarder
Posts: 26
Joined: 22.11.2021, 09:09

Re: TZQuery opens a temporary table, all fields are read-only?

Post by zhuyl »

hello
I forgot to upload, I am uploading now.
You do not have the required permissions to view the files attached to this post.
zhuyl
Junior Boarder
Junior Boarder
Posts: 26
Joined: 22.11.2021, 09:09

Re: TZQuery opens a temporary table, all fields are read-only?

Post by zhuyl »

Hello
Can the problem be solved?
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZQuery opens a temporary table, all fields are read-only?

Post by marsupilami »

Hello zhuyl,

I introduced some changes in Zeos 8.0 to allow writing top temporary tables. Please note that currently autoinc fields are not supported by the code. I don't plan to backport these changes to Zeos 7.2. So please upgrade to Zoes 8.0.

Best regards,

Jan
zhuyl
Junior Boarder
Junior Boarder
Posts: 26
Joined: 22.11.2021, 09:09

Re: TZQuery opens a temporary table, all fields are read-only?

Post by zhuyl »

Thanks
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 796
Joined: 18.11.2018, 17:37
Location: Hungary

Re: TZQuery opens a temporary table, all fields are read-only?

Post by aehimself »

Merry Christmas to everyone!

@ zhuyl,
I'm sorry; I promised myself that I'll spend every free minute of my vacation time with my daughter, therefore I had zero time to look into the issue deeply enough. I see Jan jumped on the topic too, so no worries.

@ Jan,
Taking the example from here, with your modifications included the fields are still read only.
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
miab3
Zeos Test Team
Zeos Test Team
Posts: 1310
Joined: 11.05.2012, 12:32
Location: Poland

Re: TZQuery opens a temporary table, all fields are read-only?

Post by miab3 »

Hi aehimself, All,

Merry Christmas to everyone!

1. It works for me (in conjunction with TZUpdateSQL).
I am enclosing an example:
22a.zip
2. What do you think about:
viewtopic.php?f=50&p=185826#p185826

Michał
You do not have the required permissions to view the files attached to this post.
zhuyl
Junior Boarder
Junior Boarder
Posts: 26
Joined: 22.11.2021, 09:09

Re: TZQuery opens a temporary table, all fields are read-only?

Post by zhuyl »

Merry Christmas to everyone!

test has the following problems:
1. There is a problem with the SQL statement without a table, such as ‘select getdate()’. Debugging to unit ZSybaseAnalyser.pas: TZSybaseStatementAnalyser.DefineSelectSchemaFromQuery error.
2. Using temporary tables under SQL 2000 will cause errors. Debugging to the unit ZDbcDbLibMetadata.pas: exec tempdb.sys.sp_columns has an error, can you change it to exec tempdb.dbo.sp_columns to be compatible with SQL2000?
3. When the data has non-English characters (such as Chinese), it will be wrong to save to the temporary table.

In addition, I found a problem that caused garbled characters, ZQuery1.FieldByName('CName').AsString:='程序abcd员', when garbled characters appeared when posting, debug to unit ZEncoding.pas: ZDetectUTF8Encoding function: if (EndPtr-Source > SizeOf(PCardinal)) and (PCardinal(Source)^ and $80808080 = 0) //Check quad block ASCII again
then inc(Source, SizeOf(PCardinal)) //SizeOf(PCardinal) here should be changed to: SizeOf(Cardinal)
else Inc(Source);
Post Reply