SQLite

Check-in [761396f8cb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:For Windows VFS, modified xGetLastError() to call FormatMessage() with the FORMAT_MESSAGE_IGNORE_INSERTS option. Additionally updated to ensure strings are returned as UTF8. Ticket [39c85e8a4e].
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 761396f8cb79be34853ba698a65af54874c3c10e
User & Date: shane 2009-10-21 02:00:48.000
Original Comment: For Windows VFS, modified xGetLastError() to call FormatMessage() with the FORMAT_MESSAGE_IGNORE_INSERTS option. Additionally updated to ensure strings are returned as UTF8. Ticket 39c85e8a4e.
References
2009-10-21
01:59 Fixed ticket [39c85e8a4e]: FormatMessage incorrectly used (Windows VFS) plus 3 other changes (artifact: 4d0dea8d69 user: shane)
Context
2009-10-21
03:42
For Windows version of shell, add support for .timer command using the GetProcessTimes() API if available (in the same way getrusage() is used on UNIX.) Ticket [89668ca167]. (check-in: 83216fbe90 user: shane tags: trunk)
02:00
For Windows VFS, modified xGetLastError() to call FormatMessage() with the FORMAT_MESSAGE_IGNORE_INSERTS option. Additionally updated to ensure strings are returned as UTF8. Ticket [39c85e8a4e]. (check-in: 761396f8cb user: shane tags: trunk)
2009-10-20
15:27
Clarify the use of sqlite3_shutdown(). Ticket [f9af981dd2a2]. Comment changes only - no changes to code. (check-in: b2aa48b52f user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
configure became a regular file.
install-sh became a regular file.
Changes to src/os_win.c.
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

/*
** Determine if we are dealing with WindowsCE - which has a much
** reduced API.
*/
#if SQLITE_OS_WINCE
# define AreFileApisANSI() 1
# define GetDiskFreeSpaceW() 0
#endif

/*
** WinCE lacks native support for file locking so we have to fake it
** with some code of our own.
*/
#if SQLITE_OS_WINCE







|







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

/*
** Determine if we are dealing with WindowsCE - which has a much
** reduced API.
*/
#if SQLITE_OS_WINCE
# define AreFileApisANSI() 1
# define FormatMessageW(a,b,c,d,e,f,g) 0
#endif

/*
** WinCE lacks native support for file locking so we have to fake it
** with some code of our own.
*/
#if SQLITE_OS_WINCE
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259


























1260
1261
1262
1263
1264
1265

1266
1267


1268


1269
1270
1271








1272
1273
1274
1275
1276
1277
1278

/*
** The return value of getLastErrorMsg
** is zero if the error message fits in the buffer, or non-zero
** otherwise (if the message was truncated).
*/
static int getLastErrorMsg(int nBuf, char *zBuf){
  DWORD error = GetLastError();

#if SQLITE_OS_WINCE
  sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error);
#else
  /* FormatMessage returns 0 on failure.  Otherwise it
  ** returns the number of TCHARs written to the output
  ** buffer, excluding the terminating null char.
  */


























  if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
                      NULL,
                      error,
                      0,
                      zBuf,
                      nBuf-1,

                      0))
  {


    sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error);


  }
#endif









  return 0;
}

/*
** Open a file.
*/
static int winOpen(







<
<
<
<
<




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
<
>
|
<
>
>
|
>
>
|

|
>
>
>
>
>
>
>
>







1244
1245
1246
1247
1248
1249
1250





1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285

1286
1287

1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310

/*
** The return value of getLastErrorMsg
** is zero if the error message fits in the buffer, or non-zero
** otherwise (if the message was truncated).
*/
static int getLastErrorMsg(int nBuf, char *zBuf){





  /* FormatMessage returns 0 on failure.  Otherwise it
  ** returns the number of TCHARs written to the output
  ** buffer, excluding the terminating null char.
  */
  DWORD error = GetLastError();
  DWORD dwLen = 0;
  char *zOut;

  if( isNT() ){
    WCHAR *zTempWide = NULL;
    dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                           NULL,
                           error,
                           0,
                           (LPWSTR) &zTempWide,
                           0,
                           0);
    if( dwLen > 0 ){
      /* allocate a buffer and convert to UTF8 */
      zOut = unicodeToUtf8(zTempWide);
      /* free the system buffer allocated by FormatMessage */
      LocalFree(zTempWide);
    }
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
** Since the ASCII version of these Windows API do not exist for WINCE,
** it's important to not reference them for WINCE builds.
*/
#if SQLITE_OS_WINCE==0
  }else{
    char *zTemp = NULL;
    dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                           NULL,
                           error,
                           0,
                           (LPSTR) &zTemp,

                           0,
                           0);

    if( dwLen > 0 ){
      /* allocate a buffer and convert to UTF8 */
      zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
      /* free the system buffer allocated by FormatMessage */
      LocalFree(zTemp);
    }
#endif
  }
  if( 0 == dwLen ){
    sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error);
  }else{
    /* copy a maximum of nBuf chars to output buffer */
    sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
    /* free the UTF8 buffer */
    free(zOut);
  }
  return 0;
}

/*
** Open a file.
*/
static int winOpen(
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
        dwRet = GetDiskFreeSpaceW((WCHAR*)zConverted,
                                  &dwDummy,
                                  &bytesPerSector,
                                  &dwDummy,
                                  &dwDummy);
      }else{
        /* trim path to just drive reference */
        CHAR *p = (CHAR *)zConverted;
        for(;*p;p++){
          if( *p == '\\' ){
            *p = '\0';
            break;
          }
        }
        dwRet = GetDiskFreeSpaceA((CHAR*)zConverted,
                                  &dwDummy,
                                  &bytesPerSector,
                                  &dwDummy,
                                  &dwDummy);
      }
      free(zConverted);
    }







|






|







1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
        dwRet = GetDiskFreeSpaceW((WCHAR*)zConverted,
                                  &dwDummy,
                                  &bytesPerSector,
                                  &dwDummy,
                                  &dwDummy);
      }else{
        /* trim path to just drive reference */
        char *p = (char *)zConverted;
        for(;*p;p++){
          if( *p == '\\' ){
            *p = '\0';
            break;
          }
        }
        dwRet = GetDiskFreeSpaceA((char*)zConverted,
                                  &dwDummy,
                                  &bytesPerSector,
                                  &dwDummy,
                                  &dwDummy);
      }
      free(zConverted);
    }
tool/fragck.tcl became a regular file.
tool/mkopts.tcl became a regular file.
tool/mkspeedsql.tcl became a regular file.
tool/mksqlite3c.tcl became a regular file.
tool/mksqlite3h.tcl became a regular file.
tool/mksqlite3internalh.tcl became a regular file.
tool/omittest.tcl became a regular file.
tool/soak1.tcl became a regular file.
tool/space_used.tcl became a regular file.
tool/spaceanal.tcl became a regular file.
tool/speedtest.tcl became a regular file.
tool/speedtest2.tcl became a regular file.
tool/vdbe-compress.tcl became a regular file.