Обсуждение: storing windows path strings

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

storing windows path strings

От
Scott Frankel
Дата:

Hi all,

What's the proper way to store directory path strings in a table, especially ones with backslashes like windows?

I'm currently using a prepared statement with bind value.  Do I need to pre-parse all user entries to identify any backslash characters before passing the string to my insert statement?

Searches through the documentation turned up references to escape_string_warning (boolean) and standard_conforming_strings (boolean).  I'm not sure I'll have access to server side config.  

Thanks in advance!
Scott


eg: 

CREATE TABLE foo (
foo_id SERIAL PRIMARY KEY,
name VARCHAR(32) UNIQUE NOT NULL,
dirpath text DEFAULT NULL);


INSERT INTO foo (name, dirpath) VALUES ('bar', 'c:\windows\path\to\bar');
--> WARNING:  nonstandard use of \\ in a string literal




Re: storing windows path strings

От
Cédric Villemain
Дата:
2010/1/29 Scott Frankel <leknarf@pacbell.net>:
>
> Hi all,
> What's the proper way to store directory path strings in a table, especially
> ones with backslashes like windows?
> I'm currently using a prepared statement with bind value.  Do I need to
> pre-parse all user entries to identify any backslash characters before
> passing the string to my insert statement?
> Searches through the documentation turned up references
> to escape_string_warning (boolean) and standard_conforming_strings
> (boolean).  I'm not sure I'll have access to server side config.
> Thanks in advance!
> Scott
>
> eg:
> CREATE TABLE foo (
> foo_id SERIAL PRIMARY KEY,
> name VARCHAR(32) UNIQUE NOT NULL,
> dirpath text DEFAULT NULL);
>
> INSERT INTO foo (name, dirpath) VALUES ('bar', 'c:\windows\path\to\bar');
> --> WARNING:  nonstandard use of \\ in a string literal

explicetely set ON the standard_conforming_string in the postgresql.conf
*but* take care it don't break your application.
INSERT INTO foo (name, dirpath) VALUES ('bar', 'c:\windows\path\to\bar');

>
>
>
>



--
Cédric Villemain

Re: storing windows path strings

От
Scott Frankel
Дата:
Excellent!  Mild testing so far, but it seems to work.  Thanks!
Scott




On Jan 29, 2010, at 3:00 PM, Cédric Villemain wrote:

> 2010/1/29 Scott Frankel <leknarf@pacbell.net>:
>>
>> Hi all,
>> What's the proper way to store directory path strings in a table,
>> especially
>> ones with backslashes like windows?
>> I'm currently using a prepared statement with bind value.  Do I
>> need to
>> pre-parse all user entries to identify any backslash characters
>> before
>> passing the string to my insert statement?
>> Searches through the documentation turned up references
>> to escape_string_warning (boolean) and standard_conforming_strings
>> (boolean).  I'm not sure I'll have access to server side config.
>> Thanks in advance!
>> Scott
>>
>> eg:
>> CREATE TABLE foo (
>> foo_id SERIAL PRIMARY KEY,
>> name VARCHAR(32) UNIQUE NOT NULL,
>> dirpath text DEFAULT NULL);
>>
>> INSERT INTO foo (name, dirpath) VALUES ('bar', 'c:\windows\path\to
>> \bar');
>> --> WARNING:  nonstandard use of \\ in a string literal
>
> explicetely set ON the standard_conforming_string in the
> postgresql.conf
> *but* take care it don't break your application.
> INSERT INTO foo (name, dirpath) VALUES ('bar', 'c:\windows\path\to
> \bar');
>
>>
>>
>>
>>
>
>
>
> --
> Cédric Villemain