> Le 11 f?vr. 2016 ? 17:33, Olivier Mascia <om at integral.be> a ?crit :
> 
> In between if any of you want to experiment with the path I followed, up to 
> now, here is a quick and dirty patch made on the amalgamation code from 
> https://www.sqlite.org/snapshot/sqlite-snapshot-201602101910.tar.gz

Inline patch here:

Index: shell.c
===================================================================
--- shell.c     (revision 13558)
+++ shell.c     (working copy)
@@ -486,8 +486,8 @@
   /* For interactive input on Windows systems, translate the
   ** multi-byte characterset characters into UTF-8. */
   if( stdin_is_interactive ){
-    extern char *sqlite3_win32_mbcs_to_utf8(const char*);
-    char *zTrans = sqlite3_win32_mbcs_to_utf8(zLine);
+    extern char *sqlite3_win32_oem_to_utf8(const char*);
+    char *zTrans = sqlite3_win32_oem_to_utf8(zLine);
     if( zTrans ){
       int nTrans = strlen30(zTrans)+1;
       if( nTrans>nLine ){
@@ -549,9 +549,9 @@
   va_list ap;
   va_start(ap, zFormat);
   if( stdout_is_console && (out==stdout || out==stderr) ){
-    extern char *sqlite3_win32_utf8_to_mbcs(const char*);
+    extern char *sqlite3_win32_utf8_to_oem(const char*);
     char *z1 = sqlite3_vmprintf(zFormat, ap);
-    char *z2 = sqlite3_win32_utf8_to_mbcs(z1);
+    char *z2 = sqlite3_win32_utf8_to_oem(z1);
     sqlite3_free(z1);
     fputs(z2, out);
     sqlite3_free(z2);
@@ -2043,7 +2043,6 @@
 */
 static void open_db(ShellState *p, int keepAlive){
   if( p->db==0 ){
-    sqlite3_initialize();
     sqlite3_open(p->zDbFilename, &p->db);
     globalDb = p->db;
     if( p->db && sqlite3_errcode(p->db)==SQLITE_OK ){
@@ -4538,7 +4537,6 @@
                       " cannot read ~/.sqliterc\n");
       return;
     }
-    sqlite3_initialize();
     zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
     sqliterc = zBuf;
   }
@@ -4666,6 +4664,8 @@
   int nCmd = 0;
   char **azCmd = 0;

+  sqlite3_initialize();        // Required early for sqlite3_malloc
+
 #if USE_SYSTEM_SQLITE+0!=1
   if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
     utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
@@ -4709,7 +4709,8 @@
     z = argv[i];
     if( z[0]!='-' ){
       if( data.zDbFilename==0 ){
-        data.zDbFilename = z;
+                 extern char *sqlite3_win32_mbcs_to_utf8(const char*);
+                 data.zDbFilename = sqlite3_win32_mbcs_to_utf8(z);
       }else{
         /* Excesss arguments are interpreted as SQL (or dot-commands) and
         ** mean that nothing is read from stdin */
Index: sqlite3.c
===================================================================
--- sqlite3.c   (revision 13558)
+++ sqlite3.c   (working copy)
@@ -36710,7 +36710,7 @@
 }

 /*
-** Convert an ANSI string to Microsoft Unicode, based on the
+** Convert an MBCS filename string to Microsoft Unicode, based on the
 ** current codepage settings for file apis.
 **
 ** Space to hold the returned string is obtained
@@ -36740,6 +36740,34 @@
 }

 /*
+** Convert an OEM string to Microsoft Unicode.
+**
+** Space to hold the returned string is obtained
+** from sqlite3_malloc.
+*/
+static LPWSTR winOemToUnicode(const char *zText) {
+       int nByte;
+       LPWSTR zWideText;
+
+       nByte = osMultiByteToWideChar(CP_OEMCP, 0, zText, -1, NULL,
+               0)*sizeof(WCHAR);
+       if (nByte == 0) {
+               return 0;
+       }
+       zWideText = sqlite3MallocZero(nByte*sizeof(WCHAR));
+       if (zWideText == 0) {
+               return 0;
+       }
+       nByte = osMultiByteToWideChar(CP_OEMCP, 0, zText, -1, zWideText,
+               nByte);
+       if (nByte == 0) {
+               sqlite3_free(zWideText);
+               zWideText = 0;
+       }
+       return zWideText;
+}
+
+/*
 ** Convert Microsoft Unicode to multi-byte character string, based on the
 ** user's ANSI codepage.
 **
@@ -36769,6 +36797,33 @@
 }

 /*
+** Convert Microsoft Unicode to OEM character string.
+**
+** Space to hold the returned string is obtained from
+** sqlite3_malloc().
+*/
+static char *winUnicodeToOem(LPCWSTR zWideText) {
+       int nByte;
+       char *zText;
+
+       nByte = osWideCharToMultiByte(CP_OEMCP, 0, zWideText, -1, 0, 0, 0, 0);
+       if (nByte == 0) {
+               return 0;
+       }
+       zText = sqlite3MallocZero(nByte);
+       if (zText == 0) {
+               return 0;
+       }
+       nByte = osWideCharToMultiByte(CP_OEMCP, 0, zWideText, -1, zText,
+               nByte, 0, 0);
+       if (nByte == 0) {
+               sqlite3_free(zText);
+               zText = 0;
+       }
+       return zText;
+}
+
+/*
 ** Convert multibyte character string to UTF-8.  Space to hold the
 ** returned string is obtained from sqlite3_malloc().
 */
@@ -36786,6 +36841,23 @@
 }

 /*
+** Convert OEM character string to UTF-8.  Space to hold the
+** returned string is obtained from sqlite3_malloc().
+*/
+SQLITE_API char *SQLITE_STDCALL sqlite3_win32_oem_to_utf8(const char *zText) {
+       char *zTextUtf8;
+       LPWSTR zTmpWide;
+
+       zTmpWide = winOemToUnicode(zText);
+       if (zTmpWide == 0) {
+               return 0;
+       }
+       zTextUtf8 = winUnicodeToUtf8(zTmpWide);
+       sqlite3_free(zTmpWide);
+       return zTextUtf8;
+}
+
+/*
 ** Convert UTF-8 to multibyte character string.  Space to hold the
 ** returned string is obtained from sqlite3_malloc().
 */
@@ -36803,6 +36875,23 @@
 }

 /*
+** Convert UTF-8 to OEM character string.  Space to hold the
+** returned string is obtained from sqlite3_malloc().
+*/
+SQLITE_API char *SQLITE_STDCALL sqlite3_win32_utf8_to_oem(const char *zText) {
+       char *zTextOem;
+       LPWSTR zTmpWide;
+
+       zTmpWide = winUtf8ToUnicode(zText);
+       if (zTmpWide == 0) {
+               return 0;
+       }
+       zTextOem = winUnicodeToOem(zTmpWide);
+       sqlite3_free(zTmpWide);
+       return zTextOem;
+}
+
+/*
 ** This function sets the data directory or the temporary directory based on
 ** the provided arguments.  The type argument must be 1 in order to set the
 ** data directory or 2 in order to set the temporary directory.  The zValue
@@ -171600,7 +171689,7 @@
   const char *zEnum,
   int *peVal
 ){
-  int nEnum = strlen(zEnum);
+  int nEnum = (int)strlen(zEnum);
   int i;
   int iVal = -1;

@@ -174752,7 +174841,7 @@
     Fts5ExprTerm *pTerm;
     if( p->aPopulator[i].bOk==0 ) continue;
     for(pTerm=&pExpr->apExprPhrase[i]->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
-      int nTerm = strlen(pTerm->zTerm);
+      int nTerm = (int)strlen(pTerm->zTerm);
       if( (nTerm==nToken || (nTerm<nToken && pTerm->bPrefix))
        && memcmp(pTerm->zTerm, pToken, nTerm)==0
       ){


--
Meilleures salutations, Met vriendelijke groeten, Best Regards,
Olivier Mascia, integral.be/om


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: 
<http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-users/attachments/20160211/f15ade0d/attachment.pgp>

Reply via email to