Skip to content

Using qualified name fails unless table is under database specified under DB_NAME #275

@Nydauron

Description

@Nydauron

Expanding this out from #259: #259 (comment)

On the latest commit on main, (f6baee4, at the time of writing), on MySQL, assuming that database mydb and staff are created, and that given the following table created by:

CREATE TABLE IF NOT EXISTS staff.announcements (
    id INT PRIMARY KEY AUTO_INCREMENT,
    message VARCHAR(1000)
);

with the following config having db_mysql_mydb is defined as:

    "db_mysql_mydb": {
      "DB_TYPE": "mysql",
      "DB_HOST": "127.0.0.1",
      "DB_PORT": 33306,
      "DB_USER": "root",
      "DB_NAME": "anotherdb"
    }

The following SQL:

const mixedQualifiedNamesMySqlStaff = sql`
-- @name: mixed qualified names mine
-- @db: db_mysql_mydb
SELECT message FROM staff.announcements WHERE message = ?`;

Results in the following error:

[ERROR] Column \'message\' not found in table \'announcements\'. If \'announcements\' is a table-valued function, verify that the column is defined in its alias. Otherwise, the column may not exist in the table.
Error: [E016] Column \'message\' not found in table \'announcements\'. Available columns:

Location:
    src/ts_generator/generator.rs:142:5

Note that removing the parameter does not trigger the issue:

const mixedQualifiedNamesMySqlStaff = sql`
-- @name: mixed qualified names mine
-- @db: db_mysql_mydb
SELECT message FROM staff.announcements WHERE 1=1`;

Generates the following types (these is incorrect types, but is out-of-scope for this issue, please see #274 regarding that):

export type MixedQualifiedNamesMineParams = [];

export interface IMixedQualifiedNamesMineResult {
	
}

export interface IMixedQualifiedNamesMineQuery {
	params: MixedQualifiedNamesMineParams;
	result: IMixedQualifiedNamesMineResult;
}

It should also be noting that changing db_mysql_mydb to the following config:

     "db_mysql_mydb": {
       "DB_TYPE": "mysql",
       "DB_HOST": "127.0.0.1",
       "DB_PORT": 33306,
       "DB_USER": "root",
-      "DB_NAME": "anotherdb"
+      "DB_NAME": "staff"
     }

Generates the correct types:

export type MixedQualifiedNamesMineParams = [string | null];

export interface IMixedQualifiedNamesMineResult {
	message: string | null;
}

export interface IMixedQualifiedNamesMineQuery {
	params: MixedQualifiedNamesMineParams;
	result: IMixedQualifiedNamesMineResult;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions