mail-archives/mono-bugs/2005-June/030517.html

159 строки
6.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Mono-bugs] [Bug 75288][Maj] New - Mono.Data.SqliteClient does not
marshal UTF-8 properly
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:mono-bugs%40lists.ximian.com?Subject=%5BMono-bugs%5D%20%5BBug%2075288%5D%5BMaj%5D%20New%20-%20Mono.Data.SqliteClient%20does%20not%0A%09marshal%20UTF-8%20properly&In-Reply-To=bug-75288%40chernobyl.ximian.com">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="030516.html">
<LINK REL="Next" HREF="030518.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Mono-bugs] [Bug 75288][Maj] New - Mono.Data.SqliteClient does not
marshal UTF-8 properly</H1>
<B>bugzilla-daemon at bugzilla.ximian.com</B>
<A HREF="mailto:mono-bugs%40lists.ximian.com?Subject=%5BMono-bugs%5D%20%5BBug%2075288%5D%5BMaj%5D%20New%20-%20Mono.Data.SqliteClient%20does%20not%0A%09marshal%20UTF-8%20properly&In-Reply-To=bug-75288%40chernobyl.ximian.com"
TITLE="[Mono-bugs] [Bug 75288][Maj] New - Mono.Data.SqliteClient does not
marshal UTF-8 properly">bugzilla-daemon at bugzilla.ximian.com
</A><BR>
<I>Thu Jun 16 19:43:54 EDT 2005</I>
<P><UL>
<LI>Previous message: <A HREF="030516.html">[Mono-bugs] [Bug 75287][Nor] Changed - mono-shlib-cop does not work
because sysconfigdir wasn't correctly set
</A></li>
<LI>Next message: <A HREF="030518.html">[Mono-bugs] [Bug 75287][Nor] Changed - mono-shlib-cop does not work
because sysconfigdir wasn't correctly set
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#30517">[ date ]</a>
<a href="thread.html#30517">[ thread ]</a>
<a href="subject.html#30517">[ subject ]</a>
<a href="author.html#30517">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">edd at usefulinc.com.</A>
<A HREF="http://bugzilla.ximian.com/show_bug.cgi?id=75288">http://bugzilla.ximian.com/show_bug.cgi?id=75288</A>
--- shadow/75288 2005-06-16 19:43:54.000000000 -0400
+++ shadow/75288.tmp.4101 2005-06-16 19:43:54.000000000 -0400
@@ -0,0 +1,85 @@
+Bug#: 75288
+Product: Mono: Class Libraries
+Version: 1.1
+OS:
+OS Details: Ubuntu Hoary, using tseng's packages
+Status: NEW
+Resolution:
+Severity:
+Priority: Major
+Component: Sys.Data
+AssignedTo: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">mono-bugs at ximian.com</A>
+ReportedBy: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">edd at usefulinc.com</A>
+QAContact: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">mono-bugs at ximian.com</A>
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Mono.Data.SqliteClient does not marshal UTF-8 properly
+
+I have a UTF-8 query that works fine from the sqlite command line tool, but
+not from when executed from a Mono program.
+
+Here's the query:
+
+INSERT INTO channel (url, title, description, imageurl, homepage,
+subscribed, category, fetched) VALUES
+('<A HREF="http://podcast.blogchina.com/podcast.xml',">http://podcast.blogchina.com/podcast.xml',</A> '&amp;#21338;&amp;#23458;&amp;#20013;&amp;#22269;-&amp;#21160;&amp;#21548;&amp;#25773;&amp;#23458;', '&amp;#21338;&amp;#23458;&amp;#20013;&amp;#22269;
+&#147;&amp;#21160;&amp;#21548;&amp;#25773;&amp;#23458;&#148;&amp;#26381;&amp;#21153;&amp;#28779;&amp;#28909;&amp;#27979;&amp;#35797;&amp;#20013;', '', '<A HREF="http://podcast.blogchina.com/',">http://podcast.blogchina.com/',</A> 0, '',
+632545581774313840);
+
+Here's the error from Mono:
+
+System.ApplicationException: Sqlite error near &quot;00&quot;: syntax error
+in [0x0017d] (at
+/home/brandon/work/debian/mono-1.1.7/mcs/class/Mono.Data.SqliteClient/Mono.Data.SqliteClient/SqliteCommand.cs:256)
+Mono.Data.SqliteClient.SqliteCommand:ExecuteReader (CommandBehavior
+behavior, Boolean want_results, System.Int32 rows_affected)
+in [0x00005] (at
+/home/brandon/work/debian/mono-1.1.7/mcs/class/Mono.Data.SqliteClient/Mono.Data.SqliteClient/SqliteCommand.cs:178)
+
+
+The reason this happens is because the UTF-8 strings aren't being
+marshalled properly. Mono's strings are UTF-16 inside.
+
+For Redland# we got around this by marshalling the UTF8 explicitly, I can
+provide pointers if required.
+
+I guess you need to detect whether the database is UTF8, UTF16 or what
+and do the Right Thing.
+
+Here are the two functions we made for Redland#. We then didn't use
+'string', but IntPtr in our P/invoked declarations, and used these two
+functions to marshall data in and out.
+
+ public static IntPtr StringToHGlobalUTF8 (String s)
+ {
+ if (s == null)
+ return IntPtr.Zero;
+
+ int len = System.Text.Encoding.UTF8.GetByteCount (s);
+ byte [] bytes = new byte [len + 1];
+ System.Text.Encoding.UTF8.GetBytes (s, 0, s.Length,
+bytes, 0);
+ // set up 0 terminator
+ bytes [len] = 0;
+
+ IntPtr n = Marshal.AllocHGlobal (len + 1);
+ Marshal.Copy (bytes, 0, n, len + 1);
+
+ return n;
+ }
+
+ [DllImport (&quot;libc&quot;, EntryPoint=&quot;strlen&quot;)]
+ static extern int strlen (IntPtr s);
+
+ public static String UTF8PtrToString (IntPtr p)
+ {
+ if (p == IntPtr.Zero)
+ return &quot;&quot;;
+
+ int len = strlen (p);
+ byte [] bytes = new byte [len];
+ Marshal.Copy (p, bytes, 0, len);
+ return new String
+(System.Text.Encoding.UTF8.GetChars (bytes));
+ }
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="030516.html">[Mono-bugs] [Bug 75287][Nor] Changed - mono-shlib-cop does not work
because sysconfigdir wasn't correctly set
</A></li>
<LI>Next message: <A HREF="030518.html">[Mono-bugs] [Bug 75287][Nor] Changed - mono-shlib-cop does not work
because sysconfigdir wasn't correctly set
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#30517">[ date ]</a>
<a href="thread.html#30517">[ thread ]</a>
<a href="subject.html#30517">[ subject ]</a>
<a href="author.html#30517">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/mono-bugs">More information about the mono-bugs
mailing list</a><br>
</body></html>