Thread: Import SVG file

Import SVG file

From
Miguel Angel Tribaldos Hervas
Date:
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

Re: Import SVG file

From
Richard Huxton
Date:
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

Re: Import SVG file

From
Miguel Angel Tribaldos Hervas
Date:
I want to do the import from the psql client. ... Something like that:



--


Re: Import SVG file

From
Miguel Angel Tribaldos Hervas
Date:
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


>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?


Re: Import SVG file

From
Richard Huxton
Date:
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

Re: Import SVG file

From
Phil Endecott
Date:
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.


Re: Import SVG file

From
Alvaro Herrera
Date:
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)