SCM

[#1010370] Beta3 - COPY error on encoding UTF8

View Trackers | Bugs | Download .csv | Monitor

Date:
2008-04-08 08:55
Priority:
3
State:
Open
Submitted by:
harry do (harrydo)
Assigned to:
Nobody (None)
Npgsql Version:
2.0beta3
Category:
Group:
Resolution:
None
Summary:
Beta3 - COPY error on encoding UTF8

Detailed description
Hi,

I have a test program which works fine with Beta2. Beta3 seems to have broken it.

The program copy a tab delimited file to a table. The file contains binary image fields, sample attached. The following code generates exeption at cin.Start()


Encoding inEncoding = System.Text.Encoding.Default;
Encoding serverEncoding = System.Text.Encoding.UTF8;

inStream = new FileStream(outputPathname, FileMode.Open);
NpgsqlCommand command = new NpgsqlCommand("COPY " + targetTableName + " FROM STDIN DELIMITER '\t' ", conn);
NpgsqlCopyIn cin = new NpgsqlCopyIn(command, conn, inStream);

try
{
cin.Start();
Stream copyInStream = cin.CopyStream;
byte[] buf = new byte[4096];
int i;
while ((i = inStream.Read(buf, 0, buf.Length)) > 0)
{
buf = Encoding.Convert(inEncoding, serverEncoding, buf, 0, i);
copyInStream.Write(buf, 0, i);
}
copyInStream.Close(); // or cin.End(), if you wish
}
catch (Exception e)
{
try
{
cin.Cancel("Undo copy"); // Sends CopyFail to server
cin.End();
}
}




e.Message
ERROR: 22021: invalid byte sequence for encoding \"UTF8\": 0x00


e.StackTrace
at Npgsql.NpgsqlState.<ProcessBackendResponses_Ver_3>d__a.MoveNext() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlState.cs:line 812
at Npgsql.NpgsqlState.IterateThroughAllResponses(IEnumerable`1 ienum) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlState.cs:line 317
at Npgsql.NpgsqlState.ProcessBackendResponses(NpgsqlConnector context) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlState.cs:line 312
at Npgsql.NpgsqlCopyInState.SendCopyDone(NpgsqlConnector context) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlCopyInState.cs:line 104
at Npgsql.NpgsqlCopyInState.StartCopy(NpgsqlConnector context, NpgsqlCopyFormat copyFormat) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlCopyInState.cs:line 79
at Npgsql.NpgsqlState.<ProcessBackendResponses_Ver_3>d__a.MoveNext() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlState.cs:line 901
at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:line 1115
at Npgsql.ForwardsOnlyDataReader.GetNextRowDescription() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:line 1133
at Npgsql.ForwardsOnlyDataReader.NextResult() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:line 1309
at Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable`1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean synchOnReadError) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:line 982
at Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb) in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlCommand.cs:line 552
at Npgsql.NpgsqlCommand.ExecuteBlind() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlCommand.cs:line 458
at Npgsql.NpgsqlCopyIn.Start() in C:\Npgsql\Npgsql2\src\Npgsql\NpgsqlCopyIn.cs:line 144
at PostgreSQL.BulkCopy(IDataReader sourceTable, String targetTable) in C:\Test\PostgreSQL.cs:line 103

Followup

Message
Date: 2008-04-09 20:04
Sender: Kalle Hallivuori

Hi!

I'll try to inspect this soonest, in a couple of days. Thank you a lot for your report!

Kalle Hallivuori
Date: 2008-04-08 12:24
Sender: harry do

Additional Info - Target table schema:

CREATE TABLE product_photo
(
productphotoid integer,
thumbnailphoto bytea,
thumbnailphotofilename character varying(50),
largephoto bytea,
largephotofilename character varying(50),
modifieddate timestamp without time zone
)
WITH (OIDS=FALSE);
ALTER TABLE product_photo OWNER TO dbo;

Attached Files:

Attachments:
imagedata.zip

Changes:

Field Old Value Date By
File Added333: imagedata.zip2008-04-08 08:55harrydo
Powered By FusionForge