Extended placeholders for SQL, e.g. WHERE id IN (??)

bousernamee5

New Member
Bounty update: Already got a very good answer from Mark. Adapted := into :, below. However, I'm still looking for similar schemes besides DBIx. I'm just interested in being compatible to anything.I need advise on the syntax I've picked for "extended" placeholders in parameterized SQL statements. Because building some constructs (IN clauses) was bugging me, I decided on a few syntax shortcuts that automatically expand into ordinary ? placeholders.
I like them. But I want to package it up for distribution, and am asking myself if they are easily understandable.Basically my new placeholders are \[code\]??\[/code\] and \[code\]:?\[/code\] (enumerated params) and \[code\]:&\[/code\] and \[code\]:,\[/code\] and \[code\]:|\[/code\] and \[code\]::\[/code\] (for named placeholders) with following use cases:\[code\]-> db(" SELECT * FROM all WHERE id IN (??) ", [$a, $b, $c, $d, $e])\[/code\]The \[code\]??\[/code\] expands into \[code\]?,?,?,?,?,...\[/code\] depending on the number of $args to my db() func. This one is pretty clear, and its syntax is already sort of standardized. Perls DBIx::Simple uses it too. So I'm pretty certain this is an acceptable idea.\[code\]-> db(" SELECT :? FROM any WHERE id>0 ", ["title", "frog", "id"]);// Note: not actually parameterized attr, needs cleanup regex\[/code\]Admit it. I just liked the smiley. Basically this \[code\]:?\[/code\] placeholder expands an associative $args into plain column names. It throws away any $args values in fact. It's actually useful for INSERTs in conjunction with ??, and sometimes for IN clauses. But here I'm already wondering if this new syntax is sensible, or not just a misnomer because it mixes : and ? characters. But somehow it seems to match the syntax scheme well.\[code\]-> db(" UPDATE some SET :, WHERE :& AND (:|) ", $row, $keys, $or);\[/code\]Here the mnemonic \[code\]:,\[/code\] expands into a list of \[code\]name=:name\[/code\] pairs separated by \[code\],\[/code\] commas. Whereas the \[code\]:&\[/code\] is a column=:column list joined by \[code\]AND\[/code\]s. For parity I've added \[code\]:|\[/code\]. The :& has other use cases out of UPDATE commands, though.
But my question is not about the usefulness, but if :, and :& appear to be rememberable?\[code\] -> db(" SELECT * FROM all WHERE name IN (::) ", $assoc);\[/code\]After some though I also added \[code\]::\[/code\] to interpolate a \[code\]:named,:value,:list\[/code\] very much like \[code\]??\[/code\] expands to \[code\]?,?,?\[/code\]. Similar use cases, and sensible to have for uniformness.Anyway, has anybody else implemented a scheme like that? Different placeholders? Or which would you recommend for simplicity? Update: I know that the PHP Oracle OCI interface can also bind array parameters, but doesn't use specific placeholders for it. And I'm looking for comparable placeholder syntaxes.
 
Back
Top