[MDEV-22780] CONNECT+ODBC - UPDATE and DELETE queries contains unwanted MariaDB database name Created: 2020-06-02  Updated: 2020-07-08  Resolved: 2020-07-08

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - Connect
Affects Version/s: 10.4.13
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Ján Regeš Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: ODBC, connect-engine
Environment:

Debian Buster



 Description   

Hi,

i have CONNECT table created table "company__contract" in MariaDB database "myproject", by command below. This table is connected to MSSQL schema "externaldatabase" on server "mydsn" (defined properly by FreeTDS + UnixODBC).

Select and insert into table works properly, but UPDATE or DELETE queries produced by CONNECT/ODBC engine generates unwanted "myproject" prefix into MSSQL queries. String "myproject" is name of MariaDB database, not MSSQL database. Proper name of MSSQL database/schema is "externaldatabase" defined by DATABASE in CONNECTION.

Here are queries recorded by tracing in FreeTDS/UnixODBC:

SELECT (OK): SELECT id, note FROM dbo.contract
INSERT (OK): INSERT INTO dbo.contract(id, note) VALUES (?,?)
UPDATE (ERROR): UPDATE myproject . dbo.contract SET note = 'abc' WHERE (id= 2)
DELETE (ERROR): DELETE FROM myproject . dbo.contract WHERE id = 217 AND note = 'xyz'

UPDATE or DELETE of course ends by an error Invalid object name 'myproject.dbo.contract'.

I tried any "hacks" with DBNAME, DATABASE, SCHEMA, CATALOG, but i don't know, how to remove unwanted "myproject" from MSSQL query. I read whole documentation about ODBC and CONNECT engine, but nothing helps.

Is there any option or workaround how to disable this invalid "prefixing", or override it to proper name "externaldatabase"?

Thank you.

CREATE TABLE `company__contract`
ENGINE=CONNECT
TABLE_TYPE=odbc
BLOCK_SIZE=100
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_czech_ci
CONNECTION='DSN=mydsn;UID=myuid;PWD=mypwd;DATABASE=externaldatabase'
DATA_CHARSET=utf8
TABNAME='dbo.contract'
;



 Comments   
Comment by Ján Regeš [ 2020-06-11 ]

Hi,

you can close this issue.

After i read again this documentation https://mariadb.com/kb/en/connect-odbc-table-type-accessing-tables-from-another-dbms/#update-and-delete-commands

Then I understood how the CONNECT engine would behave in the case of an UPDATE / DELETE query. CONNECT engine just simply replaces the table name and leaves the rest of the query in its original form. It makes sense.

Query from my database client contained also MariaDB database name in UPDATE/DELETE query. That was cause of this issue.

At least in the future, this ticket will respond to others who encounter a similar problem

Generated at Thu Feb 08 09:17:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.