OLD | NEW |
1 Index: Makefile.linux-gcc | 1 Index: Makefile.linux-gcc |
2 =================================================================== | 2 =================================================================== |
3 --- Makefile.linux-gcc 2009-09-03 13:32:06.000000000 -0700 | 3 --- Makefile.linux-gcc 2009-09-03 13:32:06.000000000 -0700 |
4 +++ Makefile.linux-gcc 2009-07-01 12:08:39.000000000 -0700 | 4 +++ Makefile.linux-gcc 2009-07-01 12:08:39.000000000 -0700 |
5 @@ -14,7 +14,7 @@ | 5 @@ -14,7 +14,7 @@ |
6 #### The toplevel directory of the source tree. This is the directory | 6 #### The toplevel directory of the source tree. This is the directory |
7 # that contains this "Makefile.in" and the "configure.in" script. | 7 # that contains this "Makefile.in" and the "configure.in" script. |
8 # | 8 # |
9 -TOP = ../sqlite | 9 -TOP = ../sqlite |
10 +TOP = .. | 10 +TOP = .. |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 @@ -58,6 +58,9 @@ | 785 @@ -58,6 +58,9 @@ |
786 crash7.test | 786 crash7.test |
787 delete3.test | 787 delete3.test |
788 fts3.test | 788 fts3.test |
789 + fts.test | 789 + fts.test |
790 + fts1.test | 790 + fts1.test |
791 + fts2.test | 791 + fts2.test |
792 fuzz.test | 792 fuzz.test |
793 fuzz3.test | 793 fuzz3.test |
794 fuzz_malloc.test | 794 fuzz_malloc.test |
| 795 Index: src/os_symbian.cc |
| 796 =================================================================== |
| 797 --- src/os_symbian.cc 1969-12-31 16:00:00.000000000 -0800 |
| 798 +++ src/os_symbian.cc 2009-07-01 12:08:37.000000000 -0700 |
| 799 @@ -0,0 +1,579 @@ |
| 800 +// Copyright 2008, Google Inc. |
| 801 +// |
| 802 +// Redistribution and use in source and binary forms, with or without |
| 803 +// modification, are permitted provided that the following conditions are met: |
| 804 +// |
| 805 +// 1. Redistributions of source code must retain the above copyright notice, |
| 806 +// this list of conditions and the following disclaimer. |
| 807 +// 2. Redistributions in binary form must reproduce the above copyright notice
, |
| 808 +// this list of conditions and the following disclaimer in the documentatio
n |
| 809 +// and/or other materials provided with the distribution. |
| 810 +// 3. Neither the name of Google Inc. nor the names of its contributors may be |
| 811 +// used to endorse or promote products derived from this software without |
| 812 +// specific prior written permission. |
| 813 +// |
| 814 +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 815 +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 816 +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 817 +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 818 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 819 +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 820 +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 821 +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 822 +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 823 +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 824 + |
| 825 +// This file contains code that is specific to Symbian. |
| 826 +// Differently from the rest of SQLite, it is implemented in C++ as this is |
| 827 +// the native language of the OS and all interfaces we need to use are C++. |
| 828 +// |
| 829 +// This file follows the Gears code style guidelines. |
| 830 + |
| 831 +#ifdef OS_SYMBIAN |
| 832 +#include <coemain.h> |
| 833 +#include <e32math.h> |
| 834 +#include <f32file.h> |
| 835 +#include <utf.h> |
| 836 + |
| 837 +extern "C" { |
| 838 +#include "sqliteInt.h" |
| 839 +#include "os_common.h" |
| 840 +} |
| 841 + |
| 842 +const TInt kFileLockAttempts = 3; |
| 843 + |
| 844 +// The global file system session. |
| 845 +RFs g_fs_session; |
| 846 + |
| 847 +static TInt UTF8ToUTF16(const char *in, TDes *out16) { |
| 848 + assert(in); |
| 849 + TPtrC8 in_des(reinterpret_cast<const unsigned char*>(in)); |
| 850 + return CnvUtfConverter::ConvertToUnicodeFromUtf8(*out16, in_des); |
| 851 +} |
| 852 + |
| 853 +static TInt UTF16ToUTF8(const TDesC16& in16, TDes8 *out8) { |
| 854 + return CnvUtfConverter::ConvertFromUnicodeToUtf8(*out8, in16); |
| 855 +} |
| 856 + |
| 857 +// The SymbianFile structure is a subclass of sqlite3_file* specific to the |
| 858 +// Symbian portability layer. |
| 859 +struct SymbianFile { |
| 860 + const sqlite3_io_methods *methods; |
| 861 + RFile handle; // The file handle |
| 862 + TUint8 lock_type; // Type of lock currently held on this file |
| 863 + TUint16 shared_lock_byte; // Randomly chosen byte used as a shared lock |
| 864 +}; |
| 865 + |
| 866 +static SymbianFile* ConvertToSymbianFile(sqlite3_file* const id) { |
| 867 + assert(id); |
| 868 + return reinterpret_cast<SymbianFile*>(id); |
| 869 +} |
| 870 + |
| 871 +static int SymbianClose(sqlite3_file *id) { |
| 872 + SymbianFile *file_id = ConvertToSymbianFile(id); |
| 873 + file_id->handle.Close(); |
| 874 + OpenCounter(-1); |
| 875 + return SQLITE_OK; |
| 876 +} |
| 877 + |
| 878 +static int SymbianRead(sqlite3_file *id, |
| 879 + void *buffer, |
| 880 + int amount, |
| 881 + sqlite3_int64 offset) { |
| 882 + assert(buffer); |
| 883 + assert(amount >=0); |
| 884 + assert(offset >=0); |
| 885 + |
| 886 + SymbianFile* file_id = ConvertToSymbianFile(id); |
| 887 + TPtr8 dest(static_cast<unsigned char*>(buffer), amount); |
| 888 + |
| 889 + if (KErrNone == file_id->handle.Read(offset, dest, amount)) { |
| 890 + if (dest.Length() == amount) { |
| 891 + return SQLITE_OK; |
| 892 + } else { |
| 893 + return SQLITE_IOERR_SHORT_READ; |
| 894 + } |
| 895 + } else { |
| 896 + return SQLITE_IOERR; |
| 897 + } |
| 898 +} |
| 899 + |
| 900 +static int SymbianWrite(sqlite3_file *id, |
| 901 + const void *buffer, |
| 902 + int amount, |
| 903 + sqlite3_int64 offset) { |
| 904 + assert(buffer); |
| 905 + assert(amount >=0); |
| 906 + assert(offset >=0); |
| 907 + |
| 908 + SymbianFile *file_id = ConvertToSymbianFile(id); |
| 909 + TPtrC8 src(static_cast<const unsigned char*>(buffer), amount); |
| 910 + if (file_id->handle.Write(offset, src) != KErrNone) { |
| 911 + return SQLITE_IOERR_WRITE; |
| 912 + } |
| 913 + |
| 914 + return SQLITE_OK; |
| 915 +} |
| 916 + |
| 917 +static int SymbianTruncate(sqlite3_file *id, sqlite3_int64 bytes) { |
| 918 + assert(bytes >=0); |
| 919 + |
| 920 + SymbianFile *file_id = ConvertToSymbianFile(id); |
| 921 + if (file_id->handle.SetSize(bytes) != KErrNone) { |
| 922 + return SQLITE_IOERR; |
| 923 + } |
| 924 + return SQLITE_OK; |
| 925 +} |
| 926 + |
| 927 +static int SymbianSync(sqlite3_file *id, int /*flags*/) { |
| 928 + SymbianFile *file_id = ConvertToSymbianFile(id); |
| 929 + if (file_id->handle.Flush() != KErrNone) { |
| 930 + return SQLITE_IOERR; |
| 931 + } else { |
| 932 + return SQLITE_OK; |
| 933 + } |
| 934 +} |
| 935 + |
| 936 +static int SymbianFileSize(sqlite3_file *id, sqlite3_int64 *size) { |
| 937 + assert(size); |
| 938 + |
| 939 + SymbianFile *file_id = ConvertToSymbianFile(id); |
| 940 + TInt size_tmp; |
| 941 + if (file_id->handle.Size(size_tmp) != KErrNone) { |
| 942 + return SQLITE_IOERR; |
| 943 + } |
| 944 + *size = size_tmp; |
| 945 + return SQLITE_OK; |
| 946 +} |
| 947 + |
| 948 +// File lock/unlock functions; see os_win.c for a description |
| 949 +// of the algorithm used. |
| 950 +static int GetReadLock(SymbianFile *file) { |
| 951 + file->shared_lock_byte = Math::Random() % (SHARED_SIZE - 1); |
| 952 + return file->handle.Lock(SHARED_FIRST + file->shared_lock_byte, 1); |
| 953 +} |
| 954 + |
| 955 +static int UnlockReadLock(SymbianFile *file) { |
| 956 + return file->handle.UnLock(SHARED_FIRST + file->shared_lock_byte, 1); |
| 957 +} |
| 958 + |
| 959 +static int SymbianLock(sqlite3_file *id, int lock_type) { |
| 960 + SymbianFile *file = ConvertToSymbianFile(id); |
| 961 + if (file->lock_type >= lock_type) { |
| 962 + return SQLITE_OK; |
| 963 + } |
| 964 + |
| 965 + // Make sure the locking sequence is correct |
| 966 + assert(file->lock_type != NO_LOCK || lock_type == SHARED_LOCK); |
| 967 + assert(lock_type != PENDING_LOCK); |
| 968 + assert(lock_type != RESERVED_LOCK || file->lock_type == SHARED_LOCK); |
| 969 + |
| 970 + // Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or |
| 971 + // a SHARED lock. If we are acquiring a SHARED lock, the acquisition of |
| 972 + // the PENDING_LOCK byte is temporary. |
| 973 + int new_lock_type = file->lock_type; |
| 974 + int got_pending_lock = 0; |
| 975 + int res = KErrNone; |
| 976 + if (file->lock_type == NO_LOCK || |
| 977 + (lock_type == EXCLUSIVE_LOCK && file->lock_type == RESERVED_LOCK)) { |
| 978 + int count = kFileLockAttempts; |
| 979 + while (count-- > 0 && |
| 980 + (res = file->handle.Lock(PENDING_BYTE, 1)) != KErrNone ) { |
| 981 + // Try 3 times to get the pending lock. The pending lock might be |
| 982 + // held by another reader process who will release it momentarily. |
| 983 + OSTRACE2("could not get a PENDING lock. cnt=%d\n", cnt); |
| 984 + User::After(1000); |
| 985 + } |
| 986 + got_pending_lock = (res == KErrNone? 1 : 0); |
| 987 + } |
| 988 + |
| 989 + // Acquire a shared lock |
| 990 + if (lock_type == SHARED_LOCK && res == KErrNone) { |
| 991 + assert(file->lock_type == NO_LOCK); |
| 992 + res = GetReadLock(file); |
| 993 + if (res == KErrNone) { |
| 994 + new_lock_type = SHARED_LOCK; |
| 995 + } |
| 996 + } |
| 997 + |
| 998 + // Acquire a RESERVED lock |
| 999 + if (lock_type == RESERVED_LOCK && res == KErrNone) { |
| 1000 + assert(file->lock_type == SHARED_LOCK); |
| 1001 + res = file->handle.Lock(RESERVED_BYTE, 1); |
| 1002 + if (res == KErrNone) { |
| 1003 + new_lock_type = RESERVED_LOCK; |
| 1004 + } |
| 1005 + } |
| 1006 + |
| 1007 + // Acquire a PENDING lock |
| 1008 + if (lock_type == EXCLUSIVE_LOCK && res == KErrNone) { |
| 1009 + new_lock_type = PENDING_LOCK; |
| 1010 + got_pending_lock = 0; |
| 1011 + } |
| 1012 + |
| 1013 + // Acquire an EXCLUSIVE lock |
| 1014 + if (lock_type == EXCLUSIVE_LOCK && res == KErrNone) { |
| 1015 + assert(file->lock_type >= SHARED_LOCK); |
| 1016 + res = UnlockReadLock(file); |
| 1017 + OSTRACE2("unreadlock = %d\n", res); |
| 1018 + res = file->handle.Lock(SHARED_FIRST, SHARED_SIZE); |
| 1019 + if (res == KErrNone) { |
| 1020 + new_lock_type = EXCLUSIVE_LOCK; |
| 1021 + } else { |
| 1022 + OSTRACE2("error-code = %d\n", GetLastError()); |
| 1023 + GetReadLock(file); |
| 1024 + } |
| 1025 + } |
| 1026 + |
| 1027 + // If we are holding a PENDING lock that ought to be released, then |
| 1028 + // release it now. |
| 1029 + if (got_pending_lock && lock_type == SHARED_LOCK) { |
| 1030 + file->handle.UnLock(PENDING_BYTE, 1); |
| 1031 + } |
| 1032 + |
| 1033 + // Update the state of the lock held in the file descriptor, then |
| 1034 + // return the appropriate result code. |
| 1035 + file->lock_type = new_lock_type; |
| 1036 + if (res == KErrNone) { |
| 1037 + return SQLITE_OK; |
| 1038 + } else { |
| 1039 + OSTRACE4("LOCK FAILED %d trying for %d but got %d\n", file->handle, |
| 1040 + lock_type, new_lock_type); |
| 1041 + return SQLITE_BUSY; |
| 1042 + } |
| 1043 +} |
| 1044 + |
| 1045 +static int SymbianUnlock(sqlite3_file *id, int lock_type) { |
| 1046 + int type; |
| 1047 + int rc = SQLITE_OK; |
| 1048 + SymbianFile *file = ConvertToSymbianFile(id); |
| 1049 + assert(lock_type <= SHARED_LOCK); |
| 1050 + OSTRACE5("UNLOCK %d to %d was %d(%d)\n", file->handle, lock_type, |
| 1051 + file->lock_type, file->shared_lock_byte); |
| 1052 + type = file->lock_type; |
| 1053 + if (type >= EXCLUSIVE_LOCK) { |
| 1054 + file->handle.UnLock(SHARED_FIRST, SHARED_SIZE); |
| 1055 + if (lock_type == SHARED_LOCK && GetReadLock(file) != KErrNone) { |
| 1056 + // This should never happen. We should always be able to |
| 1057 + // reacquire the read lock |
| 1058 + rc = SQLITE_IOERR_UNLOCK; |
| 1059 + } |
| 1060 + } |
| 1061 + if (type >= RESERVED_LOCK) { |
| 1062 + file->handle.UnLock(RESERVED_BYTE, 1); |
| 1063 + } |
| 1064 + if (lock_type == NO_LOCK && type >= SHARED_LOCK) { |
| 1065 + UnlockReadLock(file); |
| 1066 + } |
| 1067 + if (type >= PENDING_LOCK) { |
| 1068 + file->handle.UnLock(PENDING_BYTE, 1); |
| 1069 + } |
| 1070 + file->lock_type = lock_type; |
| 1071 + return rc; |
| 1072 +} |
| 1073 + |
| 1074 +static int SymbianCheckReservedLock(sqlite3_file *id, int *result) { |
| 1075 + int rc; |
| 1076 + SymbianFile *file = ConvertToSymbianFile(id); |
| 1077 + if (file->lock_type >= RESERVED_LOCK) { |
| 1078 + rc = 1; |
| 1079 + OSTRACE3("TEST WR-LOCK %d %d (local)\n", pFile->h, rc); |
| 1080 + } else { |
| 1081 + rc = file->handle.Lock(RESERVED_BYTE, 1); |
| 1082 + if (rc == KErrNone) { |
| 1083 + file->handle.UnLock(RESERVED_BYTE, 1); |
| 1084 + } |
| 1085 + rc = !rc; |
| 1086 + OSTRACE3("TEST WR-LOCK %d %d (remote)\n", file->handle, rc); |
| 1087 + } |
| 1088 + *result = rc; |
| 1089 + return SQLITE_OK; |
| 1090 +} |
| 1091 + |
| 1092 +static int SymbianFileControl(sqlite3_file */*id*/, |
| 1093 + int /*op*/, |
| 1094 + void */*arg*/) { |
| 1095 + return SQLITE_OK; |
| 1096 +} |
| 1097 + |
| 1098 +static int SymbianSectorSize(sqlite3_file */*id*/) { |
| 1099 + return SQLITE_DEFAULT_SECTOR_SIZE; |
| 1100 +} |
| 1101 + |
| 1102 +static int SymbianDeviceCharacteristics(sqlite3_file */*id*/) { |
| 1103 + return 0; |
| 1104 +} |
| 1105 + |
| 1106 +/* |
| 1107 +** This vector defines all the methods that can operate on a |
| 1108 +** sqlite3_file for Symbian. |
| 1109 +*/ |
| 1110 +static const sqlite3_io_methods SymbianIoMethod = { |
| 1111 + 1, // iVersion |
| 1112 + SymbianClose, |
| 1113 + SymbianRead, |
| 1114 + SymbianWrite, |
| 1115 + SymbianTruncate, |
| 1116 + SymbianSync, |
| 1117 + SymbianFileSize, |
| 1118 + SymbianLock, |
| 1119 + SymbianUnlock, |
| 1120 + SymbianCheckReservedLock, |
| 1121 + SymbianFileControl, |
| 1122 + SymbianSectorSize, |
| 1123 + SymbianDeviceCharacteristics |
| 1124 +}; |
| 1125 + |
| 1126 +// ============================================================================ |
| 1127 +// vfs methods begin here |
| 1128 +// ============================================================================ |
| 1129 +static int SymbianOpen(sqlite3_vfs */*vfs*/, |
| 1130 + const char *name, |
| 1131 + sqlite3_file *id, |
| 1132 + int flags, |
| 1133 + int *out_flags) { |
| 1134 + TUint desired_access; |
| 1135 + TUint share_mode; |
| 1136 + TInt err = KErrNone; |
| 1137 + TFileName name_utf16; |
| 1138 + SymbianFile *file = ConvertToSymbianFile(id); |
| 1139 + |
| 1140 + if (out_flags) { |
| 1141 + *out_flags = flags; |
| 1142 + } |
| 1143 + |
| 1144 + // if the name is NULL we have to open a temporary file. |
| 1145 + if (!name) { |
| 1146 + TPath private_path; |
| 1147 + TFileName file_name; |
| 1148 + if (g_fs_session.PrivatePath(private_path) != KErrNone) { |
| 1149 + return SQLITE_CANTOPEN; |
| 1150 + } |
| 1151 + if (file->handle.Temp(g_fs_session, |
| 1152 + private_path, |
| 1153 + file_name, |
| 1154 + EFileWrite) != |
| 1155 + KErrNone) { |
| 1156 + return SQLITE_CANTOPEN; |
| 1157 + } |
| 1158 + file->methods = &SymbianIoMethod; |
| 1159 + file->lock_type = NO_LOCK; |
| 1160 + file->shared_lock_byte = 0; |
| 1161 + OpenCounter(+1); |
| 1162 + return SQLITE_OK; |
| 1163 + } |
| 1164 + |
| 1165 + if (UTF8ToUTF16(name, &name_utf16) != KErrNone) |
| 1166 + return SQLITE_CANTOPEN; |
| 1167 + |
| 1168 + if (flags & SQLITE_OPEN_READWRITE) { |
| 1169 + desired_access = EFileWrite; |
| 1170 + } else { |
| 1171 + desired_access = EFileRead; |
| 1172 + } |
| 1173 + if (flags & SQLITE_OPEN_MAIN_DB) { |
| 1174 + share_mode = EFileShareReadersOrWriters; |
| 1175 + } else { |
| 1176 + share_mode = 0; |
| 1177 + } |
| 1178 + |
| 1179 + if (flags & SQLITE_OPEN_CREATE) { |
| 1180 + err = file->handle.Create(g_fs_session, |
| 1181 + name_utf16, |
| 1182 + desired_access | share_mode); |
| 1183 + if (err != KErrNone && err != KErrAlreadyExists) { |
| 1184 + return SQLITE_CANTOPEN; |
| 1185 + } |
| 1186 + } |
| 1187 + |
| 1188 + if (err != KErrNone) { |
| 1189 + err = file->handle.Open(g_fs_session, |
| 1190 + name_utf16, |
| 1191 + desired_access | share_mode); |
| 1192 + if (err != KErrNone && flags & SQLITE_OPEN_READWRITE) { |
| 1193 + if (out_flags) { |
| 1194 + *out_flags = (flags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE; |
| 1195 + } |
| 1196 + desired_access = EFileRead; |
| 1197 + err = file->handle.Open(g_fs_session, |
| 1198 + name_utf16, |
| 1199 + desired_access | share_mode); |
| 1200 + } |
| 1201 + if (err != KErrNone) { |
| 1202 + return SQLITE_CANTOPEN; |
| 1203 + } |
| 1204 + } |
| 1205 + file->methods = &SymbianIoMethod; |
| 1206 + file->lock_type = NO_LOCK; |
| 1207 + file->shared_lock_byte = 0; |
| 1208 + OpenCounter(+1); |
| 1209 + return SQLITE_OK; |
| 1210 +} |
| 1211 + |
| 1212 +static int SymbianDelete(sqlite3_vfs */*vfs*/, |
| 1213 + const char *file_name, |
| 1214 + int /*sync_dir*/) { |
| 1215 + assert(file_name); |
| 1216 + TFileName file_name_utf16; |
| 1217 + |
| 1218 + if (UTF8ToUTF16(file_name, &file_name_utf16) != KErrNone) { |
| 1219 + return SQLITE_ERROR; |
| 1220 + } |
| 1221 + |
| 1222 + TInt result = g_fs_session.Delete(file_name_utf16); |
| 1223 + return (result == KErrNone || result == KErrPathNotFound)? |
| 1224 + SQLITE_OK : SQLITE_IOERR_DELETE; |
| 1225 +} |
| 1226 + |
| 1227 +static int SymbianAccess(sqlite3_vfs */*vfs*/, |
| 1228 + const char *file_name, |
| 1229 + int flags, |
| 1230 + int *result) { |
| 1231 + assert(file_name); |
| 1232 + TEntry entry; |
| 1233 + TFileName file_name_utf16; |
| 1234 + |
| 1235 + if (UTF8ToUTF16(file_name, &file_name_utf16) != KErrNone) { |
| 1236 + return SQLITE_ERROR; |
| 1237 + } |
| 1238 + |
| 1239 + if (g_fs_session.Entry(file_name_utf16, entry) != KErrNone) { |
| 1240 + *result = 0; |
| 1241 + return SQLITE_OK; |
| 1242 + } |
| 1243 + |
| 1244 + switch (flags) { |
| 1245 + case SQLITE_ACCESS_READ: |
| 1246 + case SQLITE_ACCESS_EXISTS: |
| 1247 + *result = !entry.IsDir(); |
| 1248 + break; |
| 1249 + case SQLITE_ACCESS_READWRITE: |
| 1250 + *result = !entry.IsDir() && !entry.IsReadOnly(); |
| 1251 + break; |
| 1252 + default: |
| 1253 + return SQLITE_ERROR; |
| 1254 + } |
| 1255 + |
| 1256 + return SQLITE_OK; |
| 1257 +} |
| 1258 + |
| 1259 +static int SymbianFullPathname(sqlite3_vfs */*vfs*/, |
| 1260 + const char *relative, |
| 1261 + int full_len, |
| 1262 + char *full) { |
| 1263 + assert(relative); |
| 1264 + assert(full); |
| 1265 + |
| 1266 + TParse parse; |
| 1267 + TPath relative_utf16; |
| 1268 + TPath base_path; |
| 1269 + TPtr8 full_utf8(reinterpret_cast<unsigned char*>(full), full_len); |
| 1270 + |
| 1271 + g_fs_session.PrivatePath(base_path); |
| 1272 + |
| 1273 + if (UTF8ToUTF16(relative, &relative_utf16) != KErrNone) { |
| 1274 + return SQLITE_ERROR; |
| 1275 + } |
| 1276 + |
| 1277 + if (parse.Set(relative_utf16, &base_path, NULL) != KErrNone) { |
| 1278 + return SQLITE_ERROR; |
| 1279 + } |
| 1280 + |
| 1281 + TDesC full_utf16(parse.FullName()); |
| 1282 + if (UTF16ToUTF8(relative_utf16, &full_utf8) != KErrNone) { |
| 1283 + return SQLITE_ERROR; |
| 1284 + } |
| 1285 + |
| 1286 + full_utf8.PtrZ(); |
| 1287 + return SQLITE_OK; |
| 1288 +} |
| 1289 + |
| 1290 +static int SymbianRandomness(sqlite3_vfs */*vfs*/, int buf_len, char *buffer) { |
| 1291 + assert(buffer); |
| 1292 + TInt64 seed = User::TickCount(); |
| 1293 + for (TInt i = 0; i < buf_len; i++) { |
| 1294 + buffer[i] = Math::Rand(seed) % 255; |
| 1295 + } |
| 1296 + return SQLITE_OK; |
| 1297 +} |
| 1298 + |
| 1299 +static int SymbianSleep(sqlite3_vfs */*vfs*/, int microsec) { |
| 1300 + User::After(microsec); |
| 1301 + return SQLITE_OK; |
| 1302 +} |
| 1303 + |
| 1304 +int SymbianCurrentTime(sqlite3_vfs */*vfs*/, double *now) { |
| 1305 + _LIT(kEpoch, "19700101:000000.000000"); |
| 1306 + assert(now); |
| 1307 + TTime time; |
| 1308 + TTime epoch_time(kEpoch); |
| 1309 + TTimeIntervalSeconds interval; |
| 1310 + |
| 1311 + time.HomeTime(); |
| 1312 + // calculate seconds elapsed since 1-1-1970 |
| 1313 + time.SecondsFrom(epoch_time, interval); |
| 1314 + |
| 1315 + // Julian date @ 1-1-1970 = 2440587.5 |
| 1316 + // seconds per day = 86400.0 |
| 1317 + *now = interval.Int()/86400.0 + 2440587.5; |
| 1318 + return SQLITE_OK; |
| 1319 +} |
| 1320 + |
| 1321 +static int SymbianGetLastError(sqlite3_vfs */*vfs*/, |
| 1322 + int /*buf_len*/, |
| 1323 + char */*buf*/) { |
| 1324 + assert(buf[0] == '\0'); |
| 1325 + return 0; |
| 1326 +} |
| 1327 + |
| 1328 +// Interfaces for opening a shared library, finding entry points |
| 1329 +// within the shared library, and closing the shared library. |
| 1330 +// TODO(marcogelmi): implement. |
| 1331 +#define SymbianDlOpen 0 |
| 1332 +#define SymbianDlError 0 |
| 1333 +#define SymbianDlSym 0 |
| 1334 +#define SymbianDlClose 0 |
| 1335 + |
| 1336 +// Initialize and deinitialize the operating system interface. |
| 1337 +int sqlite3_os_init(void) { |
| 1338 + static sqlite3_vfs symbian_vfs = { |
| 1339 + 1, // iVersion |
| 1340 + sizeof(SymbianFile), // szOsFile |
| 1341 + KMaxPath, // mxPathname |
| 1342 + 0, // pNext |
| 1343 + "symbian", // name |
| 1344 + 0, // pAppData |
| 1345 + |
| 1346 + SymbianOpen, // xOpen |
| 1347 + SymbianDelete, // xDelete |
| 1348 + SymbianAccess, // xAccess |
| 1349 + SymbianFullPathname, // xFullPathname |
| 1350 + SymbianDlOpen, // xDlOpen |
| 1351 + SymbianDlError, // xDlError |
| 1352 + SymbianDlSym, // xDlSym |
| 1353 + SymbianDlClose, // xDlClose |
| 1354 + SymbianRandomness, // xRandomness |
| 1355 + SymbianSleep, // xSleep |
| 1356 + SymbianCurrentTime, // xCurrentTime |
| 1357 + SymbianGetLastError // xGetLastError |
| 1358 + }; |
| 1359 + |
| 1360 + if (g_fs_session.Connect() != KErrNone) { |
| 1361 + return SQLITE_ERROR; |
| 1362 + } |
| 1363 + |
| 1364 + if (g_fs_session.ShareAuto() != KErrNone) { |
| 1365 + g_fs_session.Close(); |
| 1366 + return SQLITE_ERROR; |
| 1367 + } |
| 1368 + |
| 1369 + sqlite3_vfs_register(&symbian_vfs, 1); |
| 1370 + return SQLITE_OK; |
| 1371 +} |
| 1372 + |
| 1373 +int sqlite3_os_end(void) { |
| 1374 + g_fs_session.Close(); |
| 1375 + return SQLITE_OK; |
| 1376 +} |
| 1377 + |
| 1378 +#endif /* OS_SYMBIAN*/ |
| 1379 Index: src/shell_icu_linux.c |
| 1380 =================================================================== |
| 1381 --- src/shell_icu_linux.c 1969-12-31 16:00:00.000000000 -0800 |
| 1382 +++ src/shell_icu_linux.c 2009-09-17 13:48:49.000000000 -0700 |
| 1383 @@ -0,0 +1,26 @@ |
| 1384 +/* Copyright 2007 Google Inc. All Rights Reserved. |
| 1385 +**/ |
| 1386 + |
| 1387 +#include <limits.h> |
| 1388 +#include <unistd.h> |
| 1389 +#include "unicode/udata.h" |
| 1390 + |
| 1391 +/* |
| 1392 +** This function attempts to load the ICU data tables from a data file. |
| 1393 +** Returns 0 on failure, nonzero on success. |
| 1394 +** This a hack job of icu_utils.cc:Initialize(). It's Chrome-specific code. |
| 1395 +*/ |
| 1396 +int sqlite_shell_init_icu() { |
| 1397 + char bin_dir[PATH_MAX + 1]; |
| 1398 + int bin_dir_size = readlink("/proc/self/exe", bin_dir, PATH_MAX); |
| 1399 + if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) |
| 1400 + return 0; |
| 1401 + bin_dir[bin_dir_size] = 0;; |
| 1402 + |
| 1403 + u_setDataDirectory(bin_dir); |
| 1404 + // Only look for the packaged data file; |
| 1405 + // the default behavior is to look for individual files. |
| 1406 + UErrorCode err = U_ZERO_ERROR; |
| 1407 + udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); |
| 1408 + return err == U_ZERO_ERROR; |
| 1409 +} |
| 1410 Index: src/shell_icu_win.c |
| 1411 =================================================================== |
| 1412 --- src/shell_icu_win.c 1969-12-31 16:00:00.000000000 -0800 |
| 1413 +++ src/shell_icu_win.c 2009-09-09 12:29:11.000000000 -0700 |
| 1414 @@ -0,0 +1,34 @@ |
| 1415 +/* Copyright 2007 Google Inc. All Rights Reserved. |
| 1416 +**/ |
| 1417 + |
| 1418 +#include <windows.h> |
| 1419 +#include "unicode/udata.h" |
| 1420 + |
| 1421 +/* |
| 1422 +** This function attempts to load the ICU data tables from a DLL. |
| 1423 +** Returns 0 on failure, nonzero on success. |
| 1424 +** This a hack job of icu_utils.cc:Initialize(). It's Chrome-specific code. |
| 1425 +*/ |
| 1426 + |
| 1427 +#define ICU_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" |
| 1428 +int sqlite_shell_init_icu() { |
| 1429 + HMODULE module; |
| 1430 + FARPROC addr; |
| 1431 + UErrorCode err; |
| 1432 + |
| 1433 + wchar_t dll_name[12]; |
| 1434 + wsprintf(dll_name, L"icudt%2S.dll", U_ICU_VERSION_SHORT); |
| 1435 + dll_name[11] = L'\0'; |
| 1436 + module = LoadLibrary(dll_name); |
| 1437 + if (!module) |
| 1438 + return 0; |
| 1439 + |
| 1440 + addr = GetProcAddress(module, ICU_DATA_SYMBOL); |
| 1441 + if (!addr) |
| 1442 + return 0; |
| 1443 + |
| 1444 + err = U_ZERO_ERROR; |
| 1445 + udata_setCommonData(addr, &err); |
| 1446 + |
| 1447 + return 1; |
| 1448 +} |
| 1449 Index: test/fts.test |
| 1450 =================================================================== |
| 1451 --- test/fts.test 1969-12-31 16:00:00.000000000 -0800 |
| 1452 +++ test/fts.test 2009-07-01 12:08:39.000000000 -0700 |
| 1453 @@ -0,0 +1,61 @@ |
| 1454 +# |
| 1455 +# May you do good and not evil. |
| 1456 +# May you find forgiveness for yourself and forgive others. |
| 1457 +# May you share freely, never taking more than you give. |
| 1458 +# |
| 1459 +#*********************************************************************** |
| 1460 +# This file runs the fts tests. |
| 1461 +# |
| 1462 +# $Id$ |
| 1463 + |
| 1464 +proc lshift {lvar} { |
| 1465 + upvar $lvar l |
| 1466 + set ret [lindex $l 0] |
| 1467 + set l [lrange $l 1 end] |
| 1468 + return $ret |
| 1469 +} |
| 1470 +while {[set arg [lshift argv]] != ""} { |
| 1471 + switch -- $arg { |
| 1472 + -sharedpagercache { |
| 1473 + sqlite3_enable_shared_cache 1 |
| 1474 + } |
| 1475 + default { |
| 1476 + set argv [linsert $argv 0 $arg] |
| 1477 + break |
| 1478 + } |
| 1479 + } |
| 1480 +} |
| 1481 + |
| 1482 +set testdir [file dirname $argv0] |
| 1483 +source $testdir/tester.tcl |
| 1484 +rename finish_test really_finish_test |
| 1485 +proc finish_test {} {} |
| 1486 +set ISQUICK 1 |
| 1487 + |
| 1488 +set EXCLUDE { |
| 1489 + fts.test |
| 1490 + fts1.test |
| 1491 + fts2.test |
| 1492 +} |
| 1493 + |
| 1494 +if {[sqlite3 -has-codec]} { |
| 1495 + # lappend EXCLUDE \ |
| 1496 + # conflict.test |
| 1497 +} |
| 1498 + |
| 1499 +foreach testfile [lsort -dictionary [glob $testdir/fts*.test]] { |
| 1500 + set tail [file tail $testfile] |
| 1501 + puts "test: $tail" |
| 1502 + if {[lsearch -exact $EXCLUDE $tail]>=0} continue |
| 1503 + source $testfile |
| 1504 + catch {db close} |
| 1505 + if {$sqlite_open_file_count>0} { |
| 1506 + puts "$tail did not close all files: $sqlite_open_file_count" |
| 1507 + incr nErr |
| 1508 + lappend ::failList $tail |
| 1509 + } |
| 1510 +} |
| 1511 +source $testdir/misuse.test |
| 1512 + |
| 1513 +set sqlite_open_file_count 0 |
| 1514 +really_finish_test |
| 1515 Index: test/fts1.test |
| 1516 =================================================================== |
| 1517 --- test/fts1.test 1969-12-31 16:00:00.000000000 -0800 |
| 1518 +++ test/fts1.test 2009-07-01 12:08:39.000000000 -0700 |
| 1519 @@ -0,0 +1,61 @@ |
| 1520 +# |
| 1521 +# May you do good and not evil. |
| 1522 +# May you find forgiveness for yourself and forgive others. |
| 1523 +# May you share freely, never taking more than you give. |
| 1524 +# |
| 1525 +#*********************************************************************** |
| 1526 +# This file runs the fts tests. |
| 1527 +# |
| 1528 +# $Id$ |
| 1529 + |
| 1530 +proc lshift {lvar} { |
| 1531 + upvar $lvar l |
| 1532 + set ret [lindex $l 0] |
| 1533 + set l [lrange $l 1 end] |
| 1534 + return $ret |
| 1535 +} |
| 1536 +while {[set arg [lshift argv]] != ""} { |
| 1537 + switch -- $arg { |
| 1538 + -sharedpagercache { |
| 1539 + sqlite3_enable_shared_cache 1 |
| 1540 + } |
| 1541 + default { |
| 1542 + set argv [linsert $argv 0 $arg] |
| 1543 + break |
| 1544 + } |
| 1545 + } |
| 1546 +} |
| 1547 + |
| 1548 +set testdir [file dirname $argv0] |
| 1549 +source $testdir/tester.tcl |
| 1550 +rename finish_test really_finish_test |
| 1551 +proc finish_test {} {} |
| 1552 +set ISQUICK 1 |
| 1553 + |
| 1554 +set EXCLUDE { |
| 1555 + fts.test |
| 1556 + fts1.test |
| 1557 + fts2.test |
| 1558 +} |
| 1559 + |
| 1560 +if {[sqlite3 -has-codec]} { |
| 1561 + # lappend EXCLUDE \ |
| 1562 + # conflict.test |
| 1563 +} |
| 1564 + |
| 1565 +foreach testfile [lsort -dictionary [glob $testdir/fts1*.test]] { |
| 1566 + set tail [file tail $testfile] |
| 1567 + puts "test: $tail" |
| 1568 + if {[lsearch -exact $EXCLUDE $tail]>=0} continue |
| 1569 + source $testfile |
| 1570 + catch {db close} |
| 1571 + if {$sqlite_open_file_count>0} { |
| 1572 + puts "$tail did not close all files: $sqlite_open_file_count" |
| 1573 + incr nErr |
| 1574 + lappend ::failList $tail |
| 1575 + } |
| 1576 +} |
| 1577 +source $testdir/misuse.test |
| 1578 + |
| 1579 +set sqlite_open_file_count 0 |
| 1580 +really_finish_test |
OLD | NEW |