If two tables having the same name present in more than one
different schemas, then discovery does not work.
For example, Cache in its default installation has the following
tables with the name "Person" in multiple demo schemas:
+-----------------+-------------+------------+------------+-----------+
|
| Table_Qualifier | Table_Owner | Table_Name | Table_Type | Remark |
|
+-----------------+-------------+------------+------------+-----------+
|
| | BasTutorial | Person | TABLE | |
|
| | CosTutorial | Person | TABLE | |
|
| | SQLUser | Person | TABLE | |
|
| | Sample | Person | TABLE | This s... |
|
| | Wasabi_Data | Person | TABLE | |
|
| | ZENMVC | Person | TABLE | Simple .. |
|
+-----------------+-------------+------------+------------+-----------+
|
So this query:
create table t1 tabname='person' engine=CONNECT table_type=ODBC connection='DSN=Samplesunixodbc';
|
returns an error:
ERROR 1939 (HY000): Engine CONNECT failed to discover table `test`.`t1` with 'CREATE TABLE whatever (`ID` INT(10) NOT NULL COMMENT 'ID',`DOB` DATE COMMENT 'DOB',`FirstName` VARCHAR(50) COMMENT 'FirstName',`LastName` VARCHAR(50) COMMENT 'LastName',`Name` VARCHAR(50) COMMENT 'Name',`Phone` VARCHAR(12) COMMENT 'Phone',`ID` INT(10) NOT NULL COMMENT 'ID',`DOB` DATE COMMENT 'DOB',`FirstName` VARCHAR(50) COMMENT 'FirstName',`LastName` VARCHAR(50) COMMENT 'LastName',`Name` VARCHAR(50) COMMENT 'Name',`Phone` VARCHAR(12) COMMENT 'Phone
|
because the ODBC call for SQLColumns() returns columns for all tables
"Person" from all these six schemas, and some of them have duplicate names.
The same problem happens with Oracle DSN:
create table t1 tabname='COUNTRIES' engine=CONNECT table_type=ODBC connection='DSN=oraodbc;UID=system;PWD=manager';
|
ERROR 1939 (HY000): Engine CONNECT failed to discover table `test`.`t1` with 'CREATE TABLE whatever (`COUNTRY_ID` CHAR(2) NOT NULL,`COUNTRY_NAME` VARCHAR(40),`REGION_ID` DOUBLE(40,0),`COUNTRY_ID` VARCHAR(10)) TABLE_TYPE='ODBC' TABNAME='COUNTRIES' CONNECTION='DSN=oraodbc;UID=system;PWD=manager''
|
if table "COUNTRIES" present in two schemas. Notice REGION_ID specified twice in the above error message.
The above error message is confusing. We need to solve this somehow.
Possible ways:
1. Detect the default schema name.
If schema name is not specified by the user,
then we can try to get to know the default schema
name before doing SQLColumn().
Unfortunately, it seems there are no ways to fetch current schema in the ODBC API.
Neither are portable SQL ways to get current schema.
It's very different between databases:
- MySQL:
- PostgreSQL supports the SQL standard way:
- Oracle:
SELECT SYS_CONTEXT('userenv','current_schema') x FROM dual;
|
- Cache assumes "SQLUser" schema by default when schema is not
specified explicitly.
We can try to check the database type and run one
of the above SQL queries to know the default schema name.
But this, probably, sounds too complex.
2. Or just print a better error message.
The discovery code could make sure that schema
name in the result of SQLColumns() is the same for all columns.
In case if schema name is not the same, then print an error like this:
ERROR 1939 (HY0000): Table name "Person" presents in more than one schemas ('SAMPLE' and 'SQLUSer'). Use a qualified table name (e.g. 'Sample.Person' to disambiguate.
|
- is duplicated by
-
MDEV-5341
ConnectSE: discovery for ODBC tables does not work if tables with the same names present in multiple schemas
-
-
Closed
{"report":{"fcp":1156.4000000953674,"ttfb":364.80000019073486,"pageVisibility":"visible","entityId":26516,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"a36ec69f-f9a5-4aab-b1b7-4fcd808a0b88","navigationType":0,"readyForUser":1271.5,"redirectCount":0,"resourceLoadedEnd":1694.6000003814697,"resourceLoadedStart":381.7000002861023,"resourceTiming":[{"duration":210.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":381.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":381.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":591.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":210.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":381.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":381.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":592.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":219.39999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":382.1000003814697,"connectEnd":382.1000003814697,"connectStart":382.1000003814697,"domainLookupEnd":382.1000003814697,"domainLookupStart":382.1000003814697,"fetchStart":382.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":382.1000003814697,"responseEnd":601.5,"responseStart":601.5,"secureConnectionStart":382.1000003814697},{"duration":274.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":382.30000019073486,"connectEnd":382.30000019073486,"connectStart":382.30000019073486,"domainLookupEnd":382.30000019073486,"domainLookupStart":382.30000019073486,"fetchStart":382.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":382.30000019073486,"responseEnd":657,"responseStart":657,"secureConnectionStart":382.30000019073486},{"duration":278.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":382.40000009536743,"connectEnd":382.40000009536743,"connectStart":382.40000009536743,"domainLookupEnd":382.40000009536743,"domainLookupStart":382.40000009536743,"fetchStart":382.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":382.40000009536743,"responseEnd":660.8000001907349,"responseStart":660.8000001907349,"secureConnectionStart":382.40000009536743},{"duration":290.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":382.6000003814697,"connectEnd":382.6000003814697,"connectStart":382.6000003814697,"domainLookupEnd":382.6000003814697,"domainLookupStart":382.6000003814697,"fetchStart":382.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":382.6000003814697,"responseEnd":672.7000002861023,"responseStart":672.7000002861023,"secureConnectionStart":382.6000003814697},{"duration":321.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":382.80000019073486,"connectEnd":382.80000019073486,"connectStart":382.80000019073486,"domainLookupEnd":382.80000019073486,"domainLookupStart":382.80000019073486,"fetchStart":382.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":382.80000019073486,"responseEnd":704.1000003814697,"responseStart":704.1000003814697,"secureConnectionStart":382.80000019073486},{"duration":397.1000003814697,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":383,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":383,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":780.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":333.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":383.2000002861023,"connectEnd":383.2000002861023,"connectStart":383.2000002861023,"domainLookupEnd":383.2000002861023,"domainLookupStart":383.2000002861023,"fetchStart":383.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":383.2000002861023,"responseEnd":717,"responseStart":717,"secureConnectionStart":383.2000002861023},{"duration":397,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":383.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":383.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":780.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":334.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":383.5,"connectEnd":383.5,"connectStart":383.5,"domainLookupEnd":383.5,"domainLookupStart":383.5,"fetchStart":383.5,"redirectEnd":0,"redirectStart":0,"requestStart":383.5,"responseEnd":717.9000000953674,"responseStart":717.9000000953674,"secureConnectionStart":383.5},{"duration":587.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":384.30000019073486,"connectEnd":384.30000019073486,"connectStart":384.30000019073486,"domainLookupEnd":384.30000019073486,"domainLookupStart":384.30000019073486,"fetchStart":384.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":384.30000019073486,"responseEnd":972.2000002861023,"responseStart":972.2000002861023,"secureConnectionStart":384.30000019073486},{"duration":1296.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":384.5,"connectEnd":384.5,"connectStart":384.5,"domainLookupEnd":384.5,"domainLookupStart":384.5,"fetchStart":384.5,"redirectEnd":0,"redirectStart":0,"requestStart":384.5,"responseEnd":1681.1000003814697,"responseStart":1681.1000003814697,"secureConnectionStart":384.5},{"duration":170.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":803.1000003814697,"connectEnd":803.1000003814697,"connectStart":803.1000003814697,"domainLookupEnd":803.1000003814697,"domainLookupStart":803.1000003814697,"fetchStart":803.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":803.1000003814697,"responseEnd":973.2000002861023,"responseStart":973.2000002861023,"secureConnectionStart":803.1000003814697},{"duration":581.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":1100.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1100.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1682.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":583.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":1101.9000000953674,"connectEnd":1101.9000000953674,"connectStart":1101.9000000953674,"domainLookupEnd":1101.9000000953674,"domainLookupStart":1101.9000000953674,"fetchStart":1101.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1101.9000000953674,"responseEnd":1685.1000003814697,"responseStart":1685.1000003814697,"secureConnectionStart":1101.9000000953674},{"duration":592.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":1102.3000001907349,"connectEnd":1102.3000001907349,"connectStart":1102.3000001907349,"domainLookupEnd":1102.3000001907349,"domainLookupStart":1102.3000001907349,"fetchStart":1102.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1102.3000001907349,"responseEnd":1694.6000003814697,"responseStart":1694.5,"secureConnectionStart":1102.3000001907349},{"duration":616.0999999046326,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1148.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1148.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1764.9000000953674,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":63,"responseStart":365,"responseEnd":368,"domLoading":371,"domInteractive":1769,"domContentLoadedEventStart":1769,"domContentLoadedEventEnd":1814,"domComplete":2115,"loadEventStart":2115,"loadEventEnd":2116,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1689.6000003814697},{"name":"bigPipe.sidebar-id.end","time":1690.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1690.7000002861023},{"name":"bigPipe.activity-panel-pipe-id.end","time":1692.3000001907349},{"name":"activityTabFullyLoaded","time":1838.3000001907349}],"measures":[],"correlationId":"9fda4f1d50d246","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":109,"dbReadsTimeInMs":10,"dbConnsTimeInMs":17,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I don't know whether you have access to the proper CONNECT documentation I update regularly in DOC, PDF, and HTML format or just use the on-line version of the MariaDB site. The problem is that this version is often outdated or incomplete.
In the file version, this issue is addressed page 49 in the section called "ODBC Catalog Information" and says in particular:
<<<<<<<<<<<<<
Depending on the version of the used ODBC driver, some additional information on the tables are existing, such as table QUALIFIER or OWNER for old versions, now named CATALOG or SCHEMA since version 3.
CATALOG is apparently rarely used by most data sources, but SCHEMA (formerly OWNER) is and corresponds to the DATABASE information of MySQL.
The issue is that if no schema name is specified, some data sources return information for all schemas while some others only return the information of the “default” schema. In addition, the used “schema” or “database” is sometimes implied by the connection string and sometimes is not. Sometimes, it also can be included in a data source definition.
CONNECT offers two ways to specify this information:
1. When specified, the DBNAME create table option is regarded by ODBC tables as the SCHEMA name.
2. Table names can be specified as “cat.sch.tab” allowing to set the catalog and schema info.
When both are used, the qualified table name has precedence over DBNAME.
When creating a standard ODBC table, you should make sure only one source table is specified. Specifying more than one source table must be done only for CONNECT catalog tables (with CATFUNC=tables or columns)
>>>>>>>>>>>>>
If this does not seem explicit enough for you, I am open to any suggestion concerning what should be said.
About the inappropriate error message, it is difficult to address this for CONNECT because it is made by MariaDB when the constructed create statement is sent to the MariaDB "init_from_sql_statement_string" function. What can be done is simply to test for duplicate column names before sending it but there will be no mean to discover the cause of it.