pub struct TableIdentifier { /* private fields */ }Expand description
A SQL identifier with proper case handling per SQL:1999.
This type separates three concerns:
- Canonical form: Used for HashMap keys and equality comparison
- Display form: Preserves user’s original input for error messages
- Quoted flag: Whether the identifier was delimited (quoted)
§SQL:1999 Compliance
Per SQL:1999, identifier handling depends on whether the identifier was quoted:
| Input | Quoted | Canonical | Matches mytable? | Matches "MyTable"? |
|---|---|---|---|---|
MyTable | No | mytable | Yes | No |
"MyTable" | Yes | MyTable | No | Yes |
MYTABLE | No | mytable | Yes | No |
"mytable" | Yes | mytable | Yes (same canonical) | No |
§Compound Identifiers
TableIdentifier supports schema-qualified table names where each component (schema and table) can be independently quoted or unquoted:
| SQL | Schema Part | Table Part | Canonical Form |
|---|---|---|---|
myApp.users | unquoted | unquoted | myapp.users |
"myApp".users | quoted | unquoted | myApp.users |
myapp."Users" | unquoted | quoted | myapp.Users |
"myApp"."Users" | quoted | quoted | myApp.Users |
Implementations§
Source§impl TableIdentifier
impl TableIdentifier
Sourcepub fn new(name: &str, quoted: bool) -> Self
pub fn new(name: &str, quoted: bool) -> Self
Create a new table identifier.
§Arguments
name- The identifier name as written by the userquoted- Whether the identifier was quoted (delimited) in SQL
§SQL:1999 Behavior
-
If
quotedisfalse: The canonical form is lowercase-folded for case-insensitive comparison. -
If
quotedistrue: The canonical form preserves exact case for case-sensitive comparison. This matches SQL:1999 behavior for delimited identifiers.
§Example
use vibesql_ast::TableIdentifier;
// Unquoted: case-insensitive
let unquoted = TableIdentifier::new("MyTable", false);
assert_eq!(unquoted.canonical(), "mytable");
assert_eq!(unquoted.display(), "MyTable");
// Quoted: case-sensitive
let quoted = TableIdentifier::new("MyTable", true);
assert_eq!(quoted.canonical(), "MyTable");
assert_eq!(quoted.display(), "MyTable");Sourcepub fn from_canonical(canonical: String, quoted: bool) -> Self
pub fn from_canonical(canonical: String, quoted: bool) -> Self
Create an identifier from a canonical name (for internal use).
This is used when loading from persistence where we only have the canonical form. The display form is set to match canonical.
Sourcepub fn qualified(
schema_name: &str,
schema_quoted: bool,
table_name: &str,
table_quoted: bool,
) -> Self
pub fn qualified( schema_name: &str, schema_quoted: bool, table_name: &str, table_quoted: bool, ) -> Self
Create a qualified (schema.table) identifier.
Each component (schema and table) has independent quoted/unquoted semantics.
§Arguments
schema_name- The schema name as written by the userschema_quoted- Whether the schema was quoted in SQLtable_name- The table name as written by the usertable_quoted- Whether the table was quoted in SQL
§SQL:1999 Behavior
Each identifier component is independent:
- Unquoted: canonical form is lowercase (case-insensitive)
- Quoted: canonical form preserves case (case-sensitive)
§Example
use vibesql_ast::TableIdentifier;
// "myApp".users → myApp.users (schema case-sensitive, table case-insensitive)
let id = TableIdentifier::qualified("myApp", true, "users", false);
assert_eq!(id.canonical(), "myApp.users");
// myapp."Users" → myapp.Users (schema case-insensitive, table case-sensitive)
let id = TableIdentifier::qualified("myapp", false, "Users", true);
assert_eq!(id.canonical(), "myapp.Users");Sourcepub fn canonical(&self) -> &str
pub fn canonical(&self) -> &str
Get the canonical form of the identifier.
This is used for HashMap keys and equality comparison.
- Unquoted identifiers: lowercase
- Quoted identifiers: exact case preserved
Sourcepub fn display(&self) -> &str
pub fn display(&self) -> &str
Get the display form of the identifier.
This preserves the user’s original input and should be used in error messages and user-facing output.
Sourcepub fn is_quoted(&self) -> bool
pub fn is_quoted(&self) -> bool
Check if this identifier was quoted (delimited) in the original SQL.
Sourcepub fn into_canonical(self) -> String
pub fn into_canonical(self) -> String
Get the canonical form as an owned String.
Useful for HashMap operations that need owned keys.
Sourcepub fn is_qualified(&self) -> bool
pub fn is_qualified(&self) -> bool
Check if this is a qualified (schema.table) identifier.
Sourcepub fn schema_canonical(&self) -> Option<&str>
pub fn schema_canonical(&self) -> Option<&str>
Get the schema part canonical form (if this is a qualified identifier).
Sourcepub fn schema_display(&self) -> Option<&str>
pub fn schema_display(&self) -> Option<&str>
Get the schema part display form (if this is a qualified identifier).
Sourcepub fn is_schema_quoted(&self) -> bool
pub fn is_schema_quoted(&self) -> bool
Check if the schema part was quoted (if this is a qualified identifier).
Sourcepub fn table_canonical(&self) -> &str
pub fn table_canonical(&self) -> &str
Get the table part canonical form.
For simple identifiers, this is the same as canonical().
For qualified identifiers, this is just the table name portion.
Sourcepub fn table_display(&self) -> &str
pub fn table_display(&self) -> &str
Get the table part display form.
For simple identifiers, this is the same as display().
For qualified identifiers, this is just the table name portion.
Sourcepub fn is_table_quoted(&self) -> bool
pub fn is_table_quoted(&self) -> bool
Check if the table part was quoted.
For simple identifiers, this is the same as is_quoted().
For qualified identifiers, this indicates the quoting of the table part only.
Trait Implementations§
Source§impl Clone for TableIdentifier
impl Clone for TableIdentifier
Source§fn clone(&self) -> TableIdentifier
fn clone(&self) -> TableIdentifier
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more