• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 512
  • Last Modified:

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

0
smj001
Asked:
smj001
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now