Issue getColumns(): Nonstandard use of \\ in a string literal

Поиск
Список
Период
Сортировка
Искать

Issue getColumns(): Nonstandard use of \\ in a string literal

От:
"ml-tb" <ml-tb@emagixx.de>
Дата:
DB-Version: 9.0.2
Driver: 9.0-801

The metadata area of this driver seems to be a litte bit out of the 
development or test focus (see also: Double quoted column name from 
DatabaseMetaData.getIndexInfo).

I got the the warning message "nonstandard use of \\ in a string 
literal" in the logfile from my postgresql server if i use the method 
getColumns(...) from the DatabaseMetaData of a java.sql.Connection.

Following a example to reproduce this message:

SQL statemant to create a table.

CREATE TABLE "TEST_TABLE" ("COLUMN_A" VARCHAR(30), "COLUMN_B" 
VARCHAR(30));


The Java code:

String tableName = "TEST_TABLE";
Connection con = this.getConnection();
String escape = con.getMetaData().getSearchStringEscape();

tableName = tableName.replace("_", escape + "_");
tableName = tableName.replace("%", escape + "%");

ResultSet rs = con.getMetaData().getColumns(catalog, schema, tableName, 
null);

while (rs.next()) {
                System.out.println("Column: " + 
rs.getString("COLUMN_NAME"));
            }
			
con.close();			


After getting the Columns via the DatabaseMetaData the postgresql 
database server log the following informations:

WARNING:  nonstandard use of \\ in a string literal at character 912
HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.
STATEMENT:  SELECT * FROM (SELECT 
n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,row_number() 
OVER (PARTITION BY a.attrelid ORDER BY a.attnum) AS attnum, 
pg_catalog.pg_get_expr(def.adbin, def.adrelid) AS 
adsrc,dsc.description,t.typbasetype,t.typtype  FROM 
pg_catalog.pg_namespace n  JOIN pg_catalog.pg_class c ON (c.relnamespace 
= n.oid)  JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid)  JOIN 
pg_catalog.pg_type t ON (a.atttypid = t.oid)  LEFT JOIN 
pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = 
def.adnum)  LEFT JOIN pg_catalog.pg_description dsc ON (c.oid=dsc.objoid 
AND a.attnum = dsc.objsubid)  LEFT JOIN pg_catalog.pg_class dc ON 
(dc.oid=dsc.classoid AND dc.relname='pg_class')  LEFT JOIN 
pg_catalog.pg_namespace dn ON (dc.relnamespace=dn.oid AND 
dn.nspname='pg_catalog')  WHERE a.attnum > 0 AND NOT a.attisdropped  AND 
n.nspname LIKE 'public'  AND c.relname LIKE 'test\\_table' ) c WHERE 
true  ORDER BY nspname,c.relname,attnum

The result of the ReslutSet is correct but I'm wondering about the 
message.

Bye Thomas

Re: Issue getColumns(): Nonstandard use of \\ in a string literal

От:
Kris Jurka <books@ejurka.com>
Дата:


On Tue, 15 Feb 2011, ml-tb wrote:

> DB-Version: 9.0.2
> Driver: 9.0-801
>
> The metadata area of this driver seems to be a litte bit out of the
> development or test focus (see also: Double quoted column name from
> DatabaseMetaData.getIndexInfo).
>
> I got the the warning message "nonstandard use of \\ in a string
> literal" in the logfile from my postgresql server if i use the method
> getColumns(...) from the DatabaseMetaData of a java.sql.Connection.

The warning can be safely ignored.  The warning is to tell you that the 
backslashes can mean different things depending on the setting of 
standard_conforming_strings.  But since the backslashes are generated 
based upon the setting of standard_conforming_strings, it's OK.  I have 
committed a fix to CVS to avoid that warning in the future.

Kris Jurka

Re: Issue getColumns(): Nonstandard use of \\ in a string literal

От:
dv <dzenmassta@gmail.com>
Дата:
As of postgresql 9.1 defaulted to 
standard_conforming_strings = on

These warnings are turned to the errors, so they cannot be ignored any more: 

2011-09-09 14:41:06 MSD ERROR:  invalid escape string
2011-09-09 14:41:06 MSD HINT:  Escape string must be empty or one character.
2011-09-09 14:41:06 MSD STATEMENT:  SELECT COUNT(a0.id) FROM country a0
WHERE a0."name" LIKE '%%' ESCAPE '\\'

--
Dmitry

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Issue-getColumns-Nonstandard-use-of-in-a-string-literal-tp3386298p4785925.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.

Re: Issue getColumns(): Nonstandard use of \\ in a string literal

От:
Kris Jurka <books@ejurka.com>
Дата:


On Fri, 9 Sep 2011, dv wrote:

> As of postgresql 9.1 defaulted to 
> standard_conforming_strings = on
> 
> These warnings are turned to the errors, so they cannot be ignored any more: 
> 
> 2011-09-09 14:41:06 MSD ERROR:  invalid escape string
> 2011-09-09 14:41:06 MSD HINT:  Escape string must be empty or one character.
> 2011-09-09 14:41:06 MSD STATEMENT:  SELECT COUNT(a0.id) FROM country a0
> WHERE a0."name" LIKE '%%' ESCAPE '\\'
> 

This certainly doesn't look like any JDBC driver generated SQL, so I'm not 
sure what your specific complaint here is.  It looks to me like you are 
using a hardcoded and incorrect escape string.  If you show the Java code 
associated with this, perhaps some more concrete advice could be offered.

Kris Jurka
FAQ