Import SVG file

Started by Miguel Angel Tribaldos Hervasabout 21 years ago7 messagesgeneral
Jump to latest
#1Miguel Angel Tribaldos Hervas
mitriher@teleco.upv.es

Hi,

how can I import a SVG file to a row?? The main problem is that it has many
postgres scape symbols. Can I utilize the
'text' type for that?
Have I to do some byte-stuffing before the import?

Thanks
--

Miguel A. Tribaldos

#2Richard Huxton
dev@archonet.com
In reply to: Miguel Angel Tribaldos Hervas (#1)
Re: Import SVG file

Miguel Angel Tribaldos Hervas wrote:

Hi,

how can I import a SVG file to a row?? The main problem is that it has many
postgres scape symbols. Can I utilize the
'text' type for that?
Have I to do some byte-stuffing before the import?

If you want to create a text-file with a COPY or INSERT statement and
then use psql -f ... you'll need to perform the usual escaping. If
you're going via Perl's DBI or similar you can let it handle those
details for you. Do you have a client system in mind?

--
Richard Huxton
Archonet Ltd

#3Miguel Angel Tribaldos Hervas
mitriher@teleco.upv.es
In reply to: Richard Huxton (#2)
Re: Import SVG file

I want to do the import from the psql client. ... Something like that:

--

#4Miguel Angel Tribaldos Hervas
mitriher@teleco.upv.es
In reply to: Miguel Angel Tribaldos Hervas (#3)
Re: Import SVG file

I want to do the import from the psql client. I try to find something like that:

INSERT INTO "controller" (notes, enabled, diagram, ...)
VALUES ('Example controller', TRUE, load_svg('controller.svg'), ...)

with diagram of type TEXT, and diagram field correctly escaped.

Best regards.
--
Miguel A. Tribaldos

Show quoted text

Miguel Angel Tribaldos Hervas wrote:

Hi,

how can I import a SVG file to a row?? The main problem is that it has many
postgres scape symbols. Can I utilize the
'text' type for that?
Have I to do some byte-stuffing before the import?

If you want to create a text-file with a COPY or INSERT statement and
then use psql -f ... you'll need to perform the usual escaping. If
you're going via Perl's DBI or similar you can let it handle those
details for you. Do you have a client system in mind?

#5Richard Huxton
dev@archonet.com
In reply to: Miguel Angel Tribaldos Hervas (#4)
Re: Import SVG file

Miguel Angel Tribaldos Hervas wrote:

I want to do the import from the psql client. I try to find something like that:

INSERT INTO "controller" (notes, enabled, diagram, ...)
VALUES ('Example controller', TRUE, load_svg('controller.svg'), ...)

with diagram of type TEXT, and diagram field correctly escaped.

Hmm - I don't know of anything which can do this for you. It'd be
difficult since by the time load_svg() is parsed and executed the
statement is server-side not client-side.

Ten lines of Perl/Python should do it just fine though. IIRC svg is just
xml, so the only thing you should need to escape is the single-quote

--
Richard Huxton
Archonet Ltd

#6Phil Endecott
spam_from_postgresql_general@chezphil.org
In reply to: Richard Huxton (#5)
Re: Import SVG file

Hi Miguel,

how can I import a SVG file to a row?? The main problem is
that it has many postgres scape symbols. Can I use the
'text' type for that?

I would probably choose to use 'bytea' rather than 'text' because of the
character set issues. The SVG, being XML, describes its own character
set in its header. If you have an 8859-1 database and then import a
UTF-8 SVG file into a text field you will have unnecessary problems.
bytea is just a sequence of bytes.

The main disadvantage of bytea is that you can't do regular expression
searches on them.

Have I to do some byte-stuffing before the import?

Yes, you will have to do the necessary escaping. I think that the
postgres C library has code to do this, and others have mentioned the
possibilities with other languages. You cannot do it with anything
quite as simple as the one line of psql that you posted.

Regards,

--Phil Endecott.

#7Alvaro Herrera
alvherre@dcc.uchile.cl
In reply to: Phil Endecott (#6)
Re: Import SVG file

On Tue, Feb 01, 2005 at 04:48:10PM +0000, Phil Endecott wrote:

Hi,

Have I to do some byte-stuffing before the import?

Yes, you will have to do the necessary escaping. I think that the
postgres C library has code to do this, and others have mentioned the
possibilities with other languages. You cannot do it with anything
quite as simple as the one line of psql that you posted.

If you are using C then you may as well use PQexecParams() and pass the
datum as a pointer. Then you don't need to escape anything.

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"World domination is proceeding according to plan" (Andrew Morton)