Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor field name quoting #745

Open
dregad opened this issue Aug 14, 2021 · 0 comments · May be fixed by #864
Open

Refactor field name quoting #745

dregad opened this issue Aug 14, 2021 · 0 comments · May be fixed by #864

Comments

@dregad
Copy link
Member

dregad commented Aug 14, 2021

This is a follow-up on the discussion in #721, to track changes targeted at 5.22.0.

  • get rid of global $ADODB_QUOTE_FIELDNAMES constant
  • Replace use of hardcoded strings by constants in _adodb_quote_fieldname()
  • Introduce new ADOConnection method setQuoteStyle()
  • Rely on ADODB_ASSOC_CASE to control casing

From #721 (comment)

I believe the following should be sufficient, along with the existing $nameQuote property and a setQuoteStyle() method accepting one of the constants.

QUOTE_NONE = 0
QUOTE_SINGLE = 1 // $nameQuote . $field . $nameQuote
QUOTE_BRACKETS = 2 // $nameQuote[0] . $field . $nameQuote[1]

From #721 (comment)

Considering $nameQuote is a public property, for BC I think we should keep supporting $nameQuote as string.

Moreover, supporting both single and bracket quote styles (for DBs allowing that) would require a separate, extra operation to set the quoting tokens (e.g. $db->nameQuote = ['[', ']']; or $db->setQuoteStyle('[', ']');) which is a low-level thing that IMO should be abstracted away.

My proposed approach simplifies that by hiding the low-level logic within the driver-specific method, e.g.

// MySQL
function setQuoteStyle(int $style) {
 $this->nameQuote = $style ? '`' : '';
}

// MSSQL
function setQuoteStyle(int $style) {
 switch ($style) {
     case QUOTE_NONE: 
       $this->nameQuote = ''; // or ['"', '"']
       break;
     case QUOTE_BRACKETS: 
       $this->nameQuote = ['[', ']']; 
       break;
     case QUOTE_SINGLE: 
     default:
       $this->nameQuote = '"';  // or  ['', '']
       break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant