PQescapeStringConn

Поиск
Список
Период
Сортировка
От Scott Frankel
Тема PQescapeStringConn
Дата
Msg-id 76D0DBC1-AE15-452A-A614-5E5D2B4546D1@circlesfx.com
обсуждение исходный текст
Ответы Re: PQescapeStringConn  (Richard Huxton <dev@archonet.com>)
Список pgsql-general

Hi all,

What's the best way to insert long strings that contain numerous special characters into a PG database?  

I'm assuming that importing an SQL script with prepared statements is the way to go.  If so, how to escape all the special characters?

I've found documentation on PQescapeStringConn but haven't found any examples of it in use. 

I have a number of very long strings that each contain many instances of semi-colons, single quotes, forward and back slashes, etc.  I'm looking for an efficient and safe way to write them to my db using a prepared statement.

An example follows.

Thanks in advance!
Scott


CREATE TABLE foo (
foo_id SERIAL PRIMARY KEY,
name VARCHAR(32) UNIQUE NOT NULL,
description TEXT,
body TEXT DEFAULT NULL,
created timestamp DEFAULT CURRENT_TIMESTAMP,
UNIQUE (name));


PREPARE fooprep (VARCHAR(32), text, text) AS
    INSERT INTO foo (name, description, body) VALUES ($1, $2, $3);
EXECUTE fooprep('foo1', 'this is foo1', 

'#!()[]{};
qwe'poi'asdlkj"zxcmnb";
/\1\2\3\4\5\6\7\8\9/'

);



В списке pgsql-general по дате отправления:

Предыдущее
От: "A. Kretschmer"
Дата:
Сообщение: Re: How to improve: performance of query on postgresql 8.3 takes days
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: PQescapeStringConn