dbTalk Databases Forums  

how to insert accent words

comp.databases.postgresql comp.databases.postgresql


Discuss how to insert accent words in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
aaaawwww
 
Posts: n/a

Default how to insert accent words - 07-01-2010 , 09:41 AM






My DB is UTF8 and I cannot change it.
When I try to insert accent letters like è ò ... I get
Query failed: ERROR: invalid byte sequence for encoding "UTF8":
0xe82729 HINT: This error can also happen if the byte sequence does
not match the encoding expected by the server, which is controlled by
"client_encoding"

How Can I insert into fields of tables accents?

Reply With Quote
  #2  
Old   
Anselmo Canfora
 
Posts: n/a

Default Re: how to insert accent words - 07-01-2010 , 10:01 AM






Il 01/07/2010 16.41, aaaawwww ha scritto:
Quote:
My DB is UTF8 and I cannot change it.
When I try to insert accent letters like è ò ... I get
Query failed: ERROR: invalid byte sequence for encoding "UTF8":
0xe82729 HINT: This error can also happen if the byte sequence does
not match the encoding expected by the server, which is controlled by
"client_encoding"

How Can I insert into fields of tables accents?
take a look here:
http://www.postgresql.org/docs/8.3/s...ns-string.html

Reply With Quote
  #3  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: how to insert accent words - 07-01-2010 , 02:22 PM



On Thu, 01 Jul 2010 07:41:35 -0700, aaaawwww wrote:

Quote:
My DB is UTF8 and I cannot change it. When I try to insert accent
letters like è ò ... I get Query failed: ERROR: invalid byte sequence
for encoding "UTF8": 0xe82729 HINT: This error can also happen if the
byte sequence does not match the encoding expected by the server, which
is controlled by "client_encoding"

How Can I insert into fields of tables accents?
Something like this would probably help:

scott=# update emp set ename=E'KI\`NG' where empno=7839;
UPDATE 1
Time: 11.654 ms
scott=# select ename,empno from emp where empno=7839;
ename | empno
-------+-------
KI`NG | 7839

That's even documented but I am lazy and I don't feel like browsing
through the documentation right now. The documentation is available right
here: http://www.postgresql.org/docs/8.4/i...ive/index.html
Look for the "escape".

--
http://mgogala.byethost5.com

Reply With Quote
  #4  
Old   
aaaawwww
 
Posts: n/a

Default Re: how to insert accent words - 07-01-2010 , 04:26 PM



Sorry I forgot to say I am running an Italian php website with a
postgresql DB. Users can write messages eachothers.
This is my code:
$connessione_db = pg_connect("dbname=xxxxx user=yyyyy
password=zzzzzz");
$sql_insert_messaggio="insert into messaggio (text) values ('àèì');";
pg_exec ($connessione_db,$sql_insert_messaggio);

and I get that error. If I do not write messages with accents
everything works.

If it possible I would avoid to use conversion strings, because if one
day I have to move to another hosting I have to change my sciprts with
the encode I will find.
Is there a way to insert accents with any kind of encoding?

Reply With Quote
  #5  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: how to insert accent words - 07-01-2010 , 08:09 PM



On Thu, 01 Jul 2010 14:26:30 -0700, aaaawwww wrote:

Quote:
Sorry I forgot to say I am running an Italian php website with a
postgresql DB. Users can write messages eachothers. This is my code:
$connessione_db = pg_connect("dbname=xxxxx user=yyyyy password=zzzzzz");
$sql_insert_messaggio="insert into messaggio (text) values ('Ã*èì');";
pg_exec ($connessione_db,$sql_insert_messaggio);

Try with a bind variable. That will solve your problem. From what I see,
the language is PHP or Perl? My guess is based on the dollar signs. If
you're using PHP, look at ADOdb, a great library which allows you to do
simple things in a simple way. The only confusing thing is the fact that
you're calling pg_exec, not pg_execute.

http://us.php.net/manual/en/function.pg-execute.php

So, with ADOdb (my favorite DB library in PHP), the statement should look
like this:
sql_insert_messaggio="insert into messaggio (text) values (:MSG)";

$rs=$pgdb->Execute($sql_insert_messaggio, array('MSG' => 'Ã*èì'));

Also, with ADOdb and PHP5 (hopefully, you're no longer using PHP4) you
can use exceptions, like this:


try {
$db->Connect($DSN['database'], $DSN['username'], $DSN['password']);
if (!empty($action) and !empty($module) and !empty($service) ) {
$args = array('SERVICE' => $service,
'MODULE' => $module,
'ACTION' => $action,
'BINDS' => $binds);
if ($opcode == 'Start') {
$db->execute($START_TRC, $args);
} elseif ($opcode == 'Stop') {
$db->execute($STOP_TRC, $args);
}
$db->close();
header('Location: sessions.php');
} else {
$rs = $db->Execute($ACTS);
while ($row = $rs->FetchRow()) {
$acts[$row[0]] = $row[0];
}
$rs = $db->Execute($MODS);
while ($row = $rs->FetchRow()) {
$mods[$row[0]] = $row[0];
}
$rs = $db->Execute($SERVS);
while ($row = $rs->FetchRow()) {
$servs[$row[0]] = $row[0];
}
$db->close();
$form = new HTML_Form($_SERVER['PHP_SELF'], "POST");
$form->addBlank(3);
$form->addSelect("action", 'Action:', $acts);
$form->addSelect("module", 'Module:', $mods);
$form->addSelect("service", 'Service:', $servs);
$form->addCheckBox("binds", 'Binds in trace:', FALSE);
$form->addSubmit("opcode", "Start");
$form->addSubmit("opcode", "Stop");
$form->addBlank(2);
$form->display();
}
}
catch(Exception $e) {
die($e->getTraceAsString());
}
?>
</center>
</body>

Anything goes wrong in there and you will get an error message.

Quote:
and I get that error. If I do not write messages with accents everything
works.
Have you tried with umlauts?

Quote:
If it possible I would avoid to use conversion strings, because if one
day I have to move to another hosting I have to change my sciprts with
the encode I will find.
Is there a way to insert accents with any kind of encoding?
This is actually a front end problem. You should use bind variables
anyway. Bondage with the variables will also help your Postgres do less
parsing and be a bit faster.

BTW, the code above is not used to connect to Postgres but to another DB,
made in Redwood Shores, CA, where the shadows lie.




--
http://mgogala.byethost5.com

Reply With Quote
  #6  
Old   
Anselmo Canfora
 
Posts: n/a

Default Re: how to insert accent words - 07-02-2010 , 06:32 AM



Il 01/07/2010 23.26, aaaawwww ha scritto:
Quote:
Sorry I forgot to say I am running an Italian php website with a
postgresql DB. Users can write messages eachothers.
This is my code:
$connessione_db = pg_connect("dbname=xxxxx user=yyyyy
password=zzzzzz");
$sql_insert_messaggio="insert into messaggio (text) values ('àèì');";
pg_exec ($connessione_db,$sql_insert_messaggio);

and I get that error. If I do not write messages with accents
everything works.

If it possible I would avoid to use conversion strings, because if one
day I have to move to another hosting I have to change my sciprts with
the encode I will find.
Is there a way to insert accents with any kind of encoding?
On the page to which I addressed you there is the answer to your problem:

convert_from(string bytea, src_encoding name)

"Convert string to the database encoding. The original encoding is
specified by src_encoding. The string must be valid in this encoding."

I suppose that your original encoding is always latin1 because of your
use of PHP, I think your pages are latin1 too (ISO 8859-15)

Is seems that PG has also a feature to make this conversion implicit by
default, but I never used it (my stuff is all utf8) so I don't know
related details.

Reply With Quote
  #7  
Old   
Graham Murray
 
Posts: n/a

Default Re: how to insert accent words - 07-02-2010 , 03:06 PM



aaaawwww <aaaawwww (AT) libero (DOT) it> writes:

Quote:
My DB is UTF8 and I cannot change it.
When I try to insert accent letters like è ò ... I get
Query failed: ERROR: invalid byte sequence for encoding "UTF8":
0xe82729 HINT: This error can also happen if the byte sequence does
not match the encoding expected by the server, which is controlled by
"client_encoding"

How Can I insert into fields of tables accents?
Use UTF8 character encoding in the terminal used to enter the accented
characters. Or change the encoding by running the command "\set ENCODING
ISO-8859-1" at the psql prompt before entering your data.

Reply With Quote
  #8  
Old   
aaaawwww
 
Posts: n/a

Default Re: how to insert accent words - 07-03-2010 , 08:46 AM



On Jul 2, 10:06*pm, Graham Murray <newsp... (AT) gmurray (DOT) org.uk> wrote:
Quote:
aaaawwww <aaaaw... (AT) libero (DOT) it> writes:
My DB is UTF8 and I cannot change it.
When I try to insert accent letters like è ò ... I get
Query failed: ERROR: invalid byte sequence for encoding "UTF8":
0xe82729 HINT: This error can also happen if the byte sequence does
not match the encoding expected by the server, which is controlled by
"client_encoding"

How Can I insert into fields of tables accents?

Use UTF8 character encoding in the terminal used to enter the accented
characters. Or change the encoding by running the command "\set ENCODING
ISO-8859-1" at the psql prompt before entering your data.
I solved it without change scripts and postgresql code. That was the
simple solution:
http://groups.google.com/group/pgsql...6408bbff?hl=en

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.