2

I'm working on library which allows me to create connections, commands, readers etc for 3 db types: oracle, postgresql and sql server. I need to pass parameters into query but it seems like postgres and oracle supports : sign as parameter indicator, but sqlserver needs @ sign. I am wondering if there is any way to change this indicator into : or maybe register new one?

I thought about creating my own parser but here is the thing: In postgresql I can do simple cast like "Description"::text, so my parser will fail on this expression. In the other hand i can get @ sign in query f.e. "Description" ILIKE '%@%' and don't know how to resolve this.

Is this possible to achieve?

Adam Mrozek
  • 1,410
  • 4
  • 26
  • 49
  • T-SQL requires `@`; there's no way to change this whatsoever. However, the .NET `SqlParameter` allows you to specify the parameter name without an `@` (it will prepend it on transmission). If you need to parse query texts you will run into difficulties no matter what: even T-SQL allows things like `[:columnName]` and `[@columnName]`, permitting "special" characters by escaping them. A parser would need to know not just about how parameters are used, but also the escaping rules of each dialect if you wanted full support. – Jeroen Mostert Jul 19 '19 at 10:43
  • "Most correct" is to specify parameters (and their types) independently from the query text, and then you're free to choose whatever way you like to represent them. This not only skips any problems with trying to parse parameters from query text (and not confusing them with escapes, or with variable names) but also prevents problems with [bad type inference](https://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/). – Jeroen Mostert Jul 19 '19 at 10:47

0 Answers0