Fossil SCM

Windows only: remove duplicate code from sqlite3.c in db.c

ron 2010-02-06 17:25 trunk
Commit 2f58d48cabfb675fd418da343c05b15ba6b6418e
1 file changed +3 -79
+3 -79
--- src/db.c
+++ src/db.c
@@ -512,86 +512,10 @@
512512
z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
513513
}
514514
db_finalize(&s);
515515
return z;
516516
}
517
-
518
-#ifdef __MINGW32__
519
-/*
520
-** These routines (copied out of the os_win.c driver for SQLite) convert
521
-** character strings in various microsoft multi-byte character formats
522
-** into UTF-8. Fossil and SQLite always use only UTF-8 internally. These
523
-** routines are needed in order to convert from the default character set
524
-** currently in use by windows into UTF-8 when strings are imported from
525
-** the outside world.
526
-*/
527
-/*
528
-** Convert microsoft unicode to UTF-8. Space to hold the returned string is
529
-** obtained from malloc().
530
-** Copied from sqlite3.c as is (petr)
531
-*/
532
-static char *unicodeToUtf8(const WCHAR *zWideFilename){
533
- int nByte;
534
- char *zFilename;
535
-
536
- nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
537
- zFilename = malloc( nByte );
538
- if( zFilename==0 ){
539
- return 0;
540
- }
541
- nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
542
- 0, 0);
543
- if( nByte == 0 ){
544
- free(zFilename);
545
- zFilename = 0;
546
- }
547
- return zFilename;
548
-}
549
-/*
550
-** Convert an ansi string to microsoft unicode, based on the
551
-** current codepage settings for file apis.
552
-**
553
-** Space to hold the returned string is obtained
554
-** from malloc.
555
-*/
556
-static WCHAR *mbcsToUnicode(const char *zFilename){
557
- int nByte;
558
- WCHAR *zMbcsFilename;
559
- int codepage = CP_ACP;
560
-
561
- nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
562
- zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) );
563
- if( zMbcsFilename==0 ){
564
- return 0;
565
- }
566
-
567
- nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
568
- if( nByte==0 ){
569
- free(zMbcsFilename);
570
- zMbcsFilename = 0;
571
- }
572
- return zMbcsFilename;
573
-}
574
-/*
575
-** Convert multibyte character string to UTF-8. Space to hold the
576
-** returned string is obtained from malloc().
577
-*/
578
-static char *mbcsToUtf8(const char *zFilename){
579
- char *zFilenameUtf8;
580
- WCHAR *zTmpWide;
581
-
582
- zTmpWide = mbcsToUnicode(zFilename);
583
- if( zTmpWide==0 ){
584
- return 0;
585
- }
586
-
587
- zFilenameUtf8 = unicodeToUtf8(zTmpWide);
588
- free(zTmpWide);
589
- return zFilenameUtf8;
590
-}
591
-#endif /* __MINGW32__ */
592
-
593517
594518
/*
595519
** Initialize a new database file with the given schema. If anything
596520
** goes wrong, call db_err() to exit.
597521
*/
@@ -604,11 +528,11 @@
604528
int rc;
605529
const char *zSql;
606530
va_list ap;
607531
608532
#ifdef __MINGW32__
609
- zFileName = mbcsToUtf8(zFileName);
533
+ zFileName = sqlite3_win32_mbcs_to_utf8(zFileName);
610534
#endif
611535
rc = sqlite3_open(zFileName, &db);
612536
if( rc!=SQLITE_OK ){
613537
db_err(sqlite3_errmsg(db));
614538
}
@@ -639,11 +563,11 @@
639563
const char *zVfs;
640564
sqlite3 *db;
641565
642566
zVfs = getenv("FOSSIL_VFS");
643567
#ifdef __MINGW32__
644
- zDbName = mbcsToUtf8(zDbName);
568
+ zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
645569
#endif
646570
rc = sqlite3_open_v2(
647571
zDbName, &db,
648572
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
649573
zVfs
@@ -665,11 +589,11 @@
665589
if( !g.db ){
666590
g.db = openDatabase(zDbName);
667591
db_connection_init();
668592
}else{
669593
#ifdef __MINGW32__
670
- zDbName = mbcsToUtf8(zDbName);
594
+ zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
671595
#endif
672596
db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
673597
}
674598
}
675599
676600
--- src/db.c
+++ src/db.c
@@ -512,86 +512,10 @@
512 z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
513 }
514 db_finalize(&s);
515 return z;
516 }
517
518 #ifdef __MINGW32__
519 /*
520 ** These routines (copied out of the os_win.c driver for SQLite) convert
521 ** character strings in various microsoft multi-byte character formats
522 ** into UTF-8. Fossil and SQLite always use only UTF-8 internally. These
523 ** routines are needed in order to convert from the default character set
524 ** currently in use by windows into UTF-8 when strings are imported from
525 ** the outside world.
526 */
527 /*
528 ** Convert microsoft unicode to UTF-8. Space to hold the returned string is
529 ** obtained from malloc().
530 ** Copied from sqlite3.c as is (petr)
531 */
532 static char *unicodeToUtf8(const WCHAR *zWideFilename){
533 int nByte;
534 char *zFilename;
535
536 nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
537 zFilename = malloc( nByte );
538 if( zFilename==0 ){
539 return 0;
540 }
541 nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
542 0, 0);
543 if( nByte == 0 ){
544 free(zFilename);
545 zFilename = 0;
546 }
547 return zFilename;
548 }
549 /*
550 ** Convert an ansi string to microsoft unicode, based on the
551 ** current codepage settings for file apis.
552 **
553 ** Space to hold the returned string is obtained
554 ** from malloc.
555 */
556 static WCHAR *mbcsToUnicode(const char *zFilename){
557 int nByte;
558 WCHAR *zMbcsFilename;
559 int codepage = CP_ACP;
560
561 nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
562 zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) );
563 if( zMbcsFilename==0 ){
564 return 0;
565 }
566
567 nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
568 if( nByte==0 ){
569 free(zMbcsFilename);
570 zMbcsFilename = 0;
571 }
572 return zMbcsFilename;
573 }
574 /*
575 ** Convert multibyte character string to UTF-8. Space to hold the
576 ** returned string is obtained from malloc().
577 */
578 static char *mbcsToUtf8(const char *zFilename){
579 char *zFilenameUtf8;
580 WCHAR *zTmpWide;
581
582 zTmpWide = mbcsToUnicode(zFilename);
583 if( zTmpWide==0 ){
584 return 0;
585 }
586
587 zFilenameUtf8 = unicodeToUtf8(zTmpWide);
588 free(zTmpWide);
589 return zFilenameUtf8;
590 }
591 #endif /* __MINGW32__ */
592
593
594 /*
595 ** Initialize a new database file with the given schema. If anything
596 ** goes wrong, call db_err() to exit.
597 */
@@ -604,11 +528,11 @@
604 int rc;
605 const char *zSql;
606 va_list ap;
607
608 #ifdef __MINGW32__
609 zFileName = mbcsToUtf8(zFileName);
610 #endif
611 rc = sqlite3_open(zFileName, &db);
612 if( rc!=SQLITE_OK ){
613 db_err(sqlite3_errmsg(db));
614 }
@@ -639,11 +563,11 @@
639 const char *zVfs;
640 sqlite3 *db;
641
642 zVfs = getenv("FOSSIL_VFS");
643 #ifdef __MINGW32__
644 zDbName = mbcsToUtf8(zDbName);
645 #endif
646 rc = sqlite3_open_v2(
647 zDbName, &db,
648 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
649 zVfs
@@ -665,11 +589,11 @@
665 if( !g.db ){
666 g.db = openDatabase(zDbName);
667 db_connection_init();
668 }else{
669 #ifdef __MINGW32__
670 zDbName = mbcsToUtf8(zDbName);
671 #endif
672 db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
673 }
674 }
675
676
--- src/db.c
+++ src/db.c
@@ -512,86 +512,10 @@
512 z = mprintf("%s", sqlite3_column_text(s.pStmt, 0));
513 }
514 db_finalize(&s);
515 return z;
516 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
517
518 /*
519 ** Initialize a new database file with the given schema. If anything
520 ** goes wrong, call db_err() to exit.
521 */
@@ -604,11 +528,11 @@
528 int rc;
529 const char *zSql;
530 va_list ap;
531
532 #ifdef __MINGW32__
533 zFileName = sqlite3_win32_mbcs_to_utf8(zFileName);
534 #endif
535 rc = sqlite3_open(zFileName, &db);
536 if( rc!=SQLITE_OK ){
537 db_err(sqlite3_errmsg(db));
538 }
@@ -639,11 +563,11 @@
563 const char *zVfs;
564 sqlite3 *db;
565
566 zVfs = getenv("FOSSIL_VFS");
567 #ifdef __MINGW32__
568 zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
569 #endif
570 rc = sqlite3_open_v2(
571 zDbName, &db,
572 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
573 zVfs
@@ -665,11 +589,11 @@
589 if( !g.db ){
590 g.db = openDatabase(zDbName);
591 db_connection_init();
592 }else{
593 #ifdef __MINGW32__
594 zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
595 #endif
596 db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
597 }
598 }
599
600

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button