Postgre Compliant ODBC Query - Make MSSQL Compatible

Hi Everyone,

I'm using a DLZ build of Bind. This allows a Bind DNS server to read DNS records from an database using in this case an ODBC connector. Most of the queries work sucessfully but one of the more complex ones fails, it seems the Microft SQL 2005 native client does not like | ("Bar"). The ODBC example queries I worked from were written for Postgre using ODBC and are shown here:

http://bind-dlz.sourceforge.net/odbc_driver.html

Three of the four queries work fine, it is only the longest one with a "|" in it that fails. This means my ODBC connector and general system setup seem to be fine.

 Here is an excerpt from the Bind log showing the actual failed query:
10-Nov-2008 14:54:50.781 Odbc driver unable to return result set for lookup quer y
10-Nov-2008 14:54:50.781
Query String: select ttl, type, mx_priority, data, ownerid, serial, refresh, ret ry, expire, minimum
        from DNS_DnsRecords where zone = 'domain.net' and (type = 'SOA'
or type='NS')
10-Nov-2008 14:54:50.781 dns_sdlz_putrr returned error. Error code was: failure

In the code box is an odbc capture showing one of the failed queries. Any ideas on how this query can be rewritten to work with MsSQL?

named -f        d88-d48	ENTER SQLExecDirect 
		HSTMT               00A81FA8
		UCHAR *             0x0053C010 [     219] "select ttl, type, mx_priority, case when lower(type)='txt' then '"' || data || '"'\ a        else data end from DNS_DnsRecords where zone = 'domain.net' and host = '@'\ a        and not (type = 'SOA' or type = 'NS')"
		SDWORD                   219
 
named -f        d88-d48	EXIT  SQLExecDirect  with return code -1 (SQL_ERROR)
		HSTMT               00A81FA8
		UCHAR *             0x0053C010 [     219] "select ttl, type, mx_priority, case when lower(type)='txt' then '"' || data || '"'\ a        else data end from DNS_DnsRecords where zone = 'domain.net' and host = '@'\ a        and not (type = 'SOA' or type = 'NS')"
		SDWORD                   219
 
		DIAG [42000] [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near '|'. (102)

Open in new window

smj001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

earth man2Commented:
use "plus" operator

ie

select string1 + string2 as string_joined from table_x;
0
earth man2Commented:
You can make PostgreSQL MS SQLServer compliant by creating an operator + to concatenate two text values eg.

testdb=> select 'hello' + ' World!';
ERROR:  operator is not unique: unknown + unknown at character 16
HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.
STATEMENT:  select 'hello' + ' World!';
ERROR:  operator is not unique: unknown + unknown
LINE 1: select 'hello' + ' World!';
                       ^
HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.

testdb=> create operator +( leftarg=text, rightarg=text, procedure = textcat );
CREATE OPERATOR
testdb=> select 'hello' + ' World!';
   ?column?  
--------------
 hello World!
(1 row)

testdb=> drop operator +(text, text);
DROP OPERATOR
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smj001Author Commented:
Thanks earthman2,

I have used the + operator to get this query nearly working but it seems one last problem remains. The program often uses * as a wildcard when it want to match all records on a field (eg "name=*") but MSSQL does not seem to like this.

Does MSSQL use a different wild card or is some sort of tweak needed to make this work with the SQL05 Native client?
0
smj001Author Commented:
Thanks, I had to use cast and ltrim but it works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PostgreSQL

From novice to tech pro — start learning today.