rhodes 2.3.2 → 2.4.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (623) hide show
  1. data/CHANGELOG +18 -0
  2. data/CREDITS +38 -0
  3. data/README.md +2 -2
  4. data/Rakefile +60 -2
  5. data/bin/set-rhodes-sdk.bat +1 -0
  6. data/doc/application.txt +11 -0
  7. data/doc/build.txt +156 -39
  8. data/doc/configuration.txt +1 -10
  9. data/doc/connect-to-web-services.txt +6 -6
  10. data/doc/device-caps.txt +48 -5
  11. data/doc/extensions.txt +8 -1
  12. data/doc/rhom.txt +16 -0
  13. data/doc/synchronization.txt +56 -14
  14. data/doc/ui.txt +23 -2
  15. data/installer/instant-rhodes.nsi +6 -6
  16. data/lib/extensions/barcode/ext/barcode/platform/iphone/Barcode.xcodeproj/project.pbxproj +4 -2
  17. data/lib/extensions/barcode/ext/barcode/platform/wm/Rakefile +1 -1
  18. data/lib/extensions/digest-md5/ext/Rakefile +3 -3
  19. data/lib/extensions/digest-md5/ext/build +0 -1
  20. data/lib/extensions/digest-sha1/ext/Rakefile +1 -1
  21. data/lib/extensions/digest-sha1/ext/build +0 -1
  22. data/lib/extensions/digest/ext/Rakefile +3 -3
  23. data/lib/extensions/digest/ext/build +0 -1
  24. data/lib/extensions/fcntl/ext/Rakefile +1 -1
  25. data/lib/extensions/mspec/mspec/guards/guard.rb +4 -0
  26. data/lib/extensions/mspec/mspec/helpers/environment.rb +4 -0
  27. data/lib/extensions/nfc/ext.yml +2 -0
  28. data/lib/extensions/nfc/ext/build +12 -0
  29. data/lib/extensions/nfc/ext/build.bat +8 -0
  30. data/lib/extensions/nfc/ext/nfc/platform/android/AndroidManifest.xml +25 -0
  31. data/lib/extensions/nfc/ext/nfc/platform/android/Rakefile +94 -0
  32. data/lib/extensions/nfc/ext/nfc/platform/android/ext_build.files +4 -0
  33. data/lib/extensions/nfc/ext/nfc/platform/android/jni/src/nfc.cpp +404 -0
  34. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/nfc/Nfc.java +138 -0
  35. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/nfc/NfcMessage.java +34 -0
  36. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/nfc/NfcMessagePack.java +33 -0
  37. data/lib/extensions/nfc/ext/nfc/platform/android/src/com/nfc/NfcRecord.java +149 -0
  38. data/lib/extensions/nfc/ext/nfc/shared/ruby/nfc.i +22 -0
  39. data/lib/extensions/nfc/ext/nfc/shared/ruby/nfc_wrap.c +2034 -0
  40. data/lib/extensions/nfc/nfc.rb +120 -0
  41. data/lib/extensions/rholang/{lang_ca.rb → rholang/lang_ca.rb} +0 -0
  42. data/lib/extensions/rholang/{lang_cf.rb → rholang/lang_cf.rb} +0 -0
  43. data/lib/extensions/rholang/{lang_chef.rb → rholang/lang_chef.rb} +0 -0
  44. data/lib/extensions/rholang/{lang_cs.rb → rholang/lang_cs.rb} +0 -0
  45. data/lib/extensions/rholang/{lang_da.rb → rholang/lang_da.rb} +0 -0
  46. data/lib/extensions/rholang/{lang_de.rb → rholang/lang_de.rb} +0 -0
  47. data/lib/extensions/rholang/{lang_es.rb → rholang/lang_es.rb} +0 -0
  48. data/lib/extensions/rholang/{lang_es_ar.rb → rholang/lang_es_ar.rb} +0 -0
  49. data/lib/extensions/rholang/{lang_fi.rb → rholang/lang_fi.rb} +0 -0
  50. data/lib/extensions/rholang/{lang_fr.rb → rholang/lang_fr.rb} +0 -0
  51. data/lib/extensions/rholang/{lang_it.rb → rholang/lang_it.rb} +0 -0
  52. data/lib/extensions/rholang/{lang_ko.rb → rholang/lang_ko.rb} +0 -0
  53. data/lib/extensions/rholang/{lang_nl.rb → rholang/lang_nl.rb} +0 -0
  54. data/lib/extensions/rholang/{lang_no.rb → rholang/lang_no.rb} +0 -0
  55. data/lib/extensions/rholang/{lang_pt.rb → rholang/lang_pt.rb} +0 -0
  56. data/lib/extensions/rholang/{lang_pt_br.rb → rholang/lang_pt_br.rb} +0 -0
  57. data/lib/extensions/rholang/{lang_ru.rb → rholang/lang_ru.rb} +0 -0
  58. data/lib/extensions/rholang/{lang_se.rb → rholang/lang_se.rb} +0 -0
  59. data/lib/extensions/rholang/{lang_sr.rb → rholang/lang_sr.rb} +0 -0
  60. data/lib/extensions/rholang/{rhoerror_ru.rb → rholang/rhoerror_ru.rb} +0 -0
  61. data/lib/extensions/rholang/{rhomsg_ru.rb → rholang/rhomsg_ru.rb} +0 -0
  62. data/lib/framework/date/format.rb +2 -0
  63. data/lib/framework/dateOrig.rb +17 -8
  64. data/lib/framework/rational18.rb +532 -0
  65. data/lib/framework/res/back_btn.wp7.png +0 -0
  66. data/lib/framework/res/blue_pushpin.wp7.png +0 -0
  67. data/lib/framework/res/blue_pushpin_small.wp7.png +0 -0
  68. data/lib/framework/res/callout.wp7.png +0 -0
  69. data/lib/framework/res/callout_link.wp7.png +0 -0
  70. data/lib/framework/res/esri.wp7.png +0 -0
  71. data/lib/framework/res/forward_btn.wp7.png +0 -0
  72. data/lib/framework/res/home_btn.wp7.png +0 -0
  73. data/lib/framework/res/options_btn.wp7.png +0 -0
  74. data/lib/framework/res/refresh_btn.wp7.png +0 -0
  75. data/lib/framework/rho/render.rb +8 -1
  76. data/lib/framework/rho/rho.rb +30 -7
  77. data/lib/framework/rho/rhoapplication.rb +9 -4
  78. data/lib/framework/rho/rhofsconnector.rb +5 -1
  79. data/lib/framework/rho/rhotabbar.rb +8 -0
  80. data/lib/framework/rho/rhotoolbar.rb +1 -1
  81. data/lib/framework/rho/rhoviewhelpers.rb +18 -1
  82. data/lib/framework/rhodes.rb +1 -1
  83. data/lib/framework/rhoframework.rb +46 -1
  84. data/lib/framework/rholang/localization_simplified.rb +17 -16
  85. data/lib/framework/rhom/rhom_db_adapter.rb +2 -2
  86. data/lib/framework/rhom/rhom_object_factory.rb +115 -12
  87. data/lib/framework/rhosystem.rb +135 -0
  88. data/lib/framework/version.rb +1 -1
  89. data/lib/rhodes.rb +1 -1
  90. data/lib/test/apps/rhoconfig.txt +23 -23
  91. data/platform/android/Rhodes/AndroidManifest.full.xml +101 -0
  92. data/platform/android/Rhodes/AndroidManifest.xml +10 -15
  93. data/platform/android/Rhodes/default.properties +11 -0
  94. data/platform/android/Rhodes/gen/com/rhomobile/rhodes/R.java +59 -53
  95. data/platform/android/Rhodes/jni/include/rhodes.h +1 -0
  96. data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_RhodesApplication.h +21 -0
  97. data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_alert_PopupActivity.h +21 -0
  98. data/platform/android/Rhodes/jni/include/rhodes/jni/com_rhomobile_rhodes_file_RhoFileApi.h +10 -2
  99. data/platform/android/Rhodes/jni/src/alert.cpp +2 -1
  100. data/platform/android/Rhodes/jni/src/datetimepicker.cpp +2 -0
  101. data/platform/android/Rhodes/jni/src/fileapi.cpp +671 -84
  102. data/platform/android/Rhodes/jni/src/nativebar.cpp +18 -0
  103. data/platform/android/Rhodes/jni/src/rhodes.cpp +92 -1
  104. data/platform/android/Rhodes/res/values/styles.xml +7 -0
  105. data/platform/android/Rhodes/src/com/rhomobile/rhodes/BaseActivity.java +35 -2
  106. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Capabilities.java +12 -13
  107. data/platform/android/Rhodes/src/com/rhomobile/rhodes/LocalFileProvider.java +130 -0
  108. data/platform/android/Rhodes/src/com/rhomobile/rhodes/NativeBar.java +6 -0
  109. data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushReceiver.java +5 -1
  110. data/platform/android/Rhodes/src/com/rhomobile/rhodes/PushService.java +6 -2
  111. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhoMenu.java +7 -36
  112. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesActivity.java +43 -20
  113. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesApplication.java +2 -0
  114. data/platform/android/Rhodes/src/com/rhomobile/rhodes/RhodesService.java +63 -28
  115. data/platform/android/Rhodes/src/com/rhomobile/rhodes/Utils.java +2 -2
  116. data/platform/android/Rhodes/src/com/rhomobile/rhodes/WebView.java +6 -2
  117. data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/Alert.java +19 -282
  118. data/platform/android/Rhodes/src/com/rhomobile/rhodes/alert/PopupActivity.java +354 -0
  119. data/platform/android/Rhodes/src/com/rhomobile/rhodes/datetime/DateTimePickerScreen.java +4 -0
  120. data/platform/android/Rhodes/src/com/rhomobile/rhodes/event/EventStore.java +1 -2
  121. data/platform/android/Rhodes/src/com/rhomobile/rhodes/file/RhoFileApi.java +71 -5
  122. data/platform/android/Rhodes/src/com/rhomobile/rhodes/geolocation/GeoLocationImpl.java +107 -37
  123. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/SimpleMainView.java +10 -7
  124. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mainview/TabbedMainView.java +156 -56
  125. data/platform/android/Rhodes/src/com/rhomobile/rhodes/mapview/MapView.java +0 -1
  126. data/platform/android/Rhodes/src/com/rhomobile/rhodes/phonebook/ContactAccessorNew.java +40 -32
  127. data/platform/android/Rhodes/src/com/rhomobile/rhodes/signature/SignatureView.java +1 -0
  128. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/ExternalHttpHandler.java +14 -6
  129. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/LocalFileHandler.java +46 -0
  130. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/MailUriHandler.java +4 -24
  131. data/platform/android/Rhodes/src/com/rhomobile/rhodes/uri/UriHandler.java +3 -1
  132. data/platform/android/build/RhodesSRC_build.files +28 -25
  133. data/platform/android/build/android.rake +230 -54
  134. data/platform/android/build/androidcommon.rb +1 -1
  135. data/platform/android/build/librhocommon_build.files +1 -0
  136. data/platform/bb/Hsqldb/BlackBerry_App_Descriptor.xml +20 -0
  137. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBResult.java +1 -5
  138. data/platform/bb/Hsqldb/src/com/rho/db/HsqlDBStorage.java +6 -1
  139. data/platform/bb/Hsqldb/src/org/hsqldb/rowio/RowOutputBase.java +1 -1
  140. data/platform/bb/Hsqldb/src/org/hsqldb/rowio/RowOutputBinary.java +1 -1
  141. data/platform/bb/RubyVM/BlackBerry_App_Descriptor.xml +20 -0
  142. data/platform/bb/RubyVM/src/com/rho/IRhoRubyHelper.java +2 -0
  143. data/platform/bb/RubyVM/src/com/rho/RhoLogOutputSink.java +0 -1
  144. data/platform/bb/RubyVM/src/com/rho/RhoLogger.java +12 -10
  145. data/platform/bb/RubyVM/src/com/rho/RhoThread.java +16 -0
  146. data/platform/bb/RubyVM/src/com/rho/RhoTimer.java +89 -0
  147. data/platform/bb/RubyVM/src/com/rho/RhodesApp.java +20 -13
  148. data/platform/bb/RubyVM/src/com/rho/SplashScreen.java +1 -2
  149. data/platform/bb/RubyVM/src/com/rho/ThreadQueue.java +2 -2
  150. data/platform/bb/RubyVM/src/com/rho/TimeInterval.java +5 -0
  151. data/platform/bb/RubyVM/src/com/rho/db/DBAdapter.java +54 -48
  152. data/platform/bb/RubyVM/src/com/rho/db/IDBResult.java +0 -1
  153. data/platform/bb/RubyVM/src/com/rho/db/IDBStorage.java +1 -0
  154. data/platform/bb/RubyVM/src/com/rho/net/AsyncHttp.java +1 -1
  155. data/platform/bb/RubyVM/src/com/rho/sync/ClientRegister.java +1 -1
  156. data/platform/bb/RubyVM/src/com/rho/sync/JSONStructIterator.java +1 -1
  157. data/platform/bb/RubyVM/src/com/rho/sync/SyncEngine.java +16 -8
  158. data/platform/bb/RubyVM/src/com/rho/sync/SyncNotify.java +2 -2
  159. data/platform/bb/RubyVM/src/com/rho/sync/SyncSource.java +52 -29
  160. data/platform/bb/RubyVM/src/com/rho/sync/SyncThread.java +1 -3
  161. data/platform/bb/build/RubyVM_build.files +1 -0
  162. data/platform/bb/build/bb.rake +29 -9
  163. data/platform/bb/rhodes/BlackBerry_App_Descriptor.xml +23 -0
  164. data/platform/bb/rhodes/platform/5.0/com/rho/RhodesApplicationPlatform.java +1 -1
  165. data/platform/bb/rhodes/platform/5.0/com/rho/db/SqliteCopyResult.java +0 -4
  166. data/platform/bb/rhodes/platform/5.0/com/rho/db/SqliteResult.java +13 -20
  167. data/platform/bb/rhodes/platform/5.0/com/rho/db/SqliteStorage.java +183 -157
  168. data/platform/bb/rhodes/src/com/rho/RhoRubyHelper.java +22 -0
  169. data/platform/bb/rhodes/src/com/rho/RhodesApplicationPlatform.java +1 -1
  170. data/platform/bb/rhodes/src/com/rho/db/SqliteCopyResult.java +0 -4
  171. data/platform/bb/rhodes/src/com/rho/db/SqliteResult.java +13 -20
  172. data/platform/bb/rhodes/src/com/rho/db/SqliteStorage.java +183 -157
  173. data/platform/bb/rhodes/src/com/rho/rubyext/System.java +46 -1
  174. data/platform/bb/rhodes/src/rhomobile/RhodesApplication.java +8 -1
  175. data/platform/bb/rhodes/src/rhomobile/camera/CameraFilesListener.java +13 -3
  176. data/platform/iphone/Classes/AppManager/AppManager.h +5 -1
  177. data/platform/iphone/Classes/AppManager/AppManager.m +170 -7
  178. data/platform/iphone/Classes/DateTimePicker.m +14 -1
  179. data/platform/iphone/Classes/DateTimePickerDelegate.h +2 -0
  180. data/platform/iphone/Classes/DateTimePickerDelegate.m +36 -2
  181. data/platform/iphone/Classes/NativeBar.h +1 -0
  182. data/platform/iphone/Classes/NativeBar.m +15 -3
  183. data/platform/iphone/Classes/Phonebook/phonebook.m +8 -9
  184. data/platform/iphone/Classes/Rhodes.m +50 -6
  185. data/platform/iphone/Classes/SimpleMainView.m +7 -6
  186. data/platform/iphone/Classes/SplitView/RightViewController.h +3 -1
  187. data/platform/iphone/Classes/SplitView/RightViewController.m +14 -1
  188. data/platform/iphone/Classes/TabbedMainView.h +4 -0
  189. data/platform/iphone/Classes/TabbedMainView.m +43 -26
  190. data/platform/iphone/Info.plist +1 -1
  191. data/platform/iphone/RhoLib/RhoLib.xcodeproj/project.pbxproj +4 -0
  192. data/platform/iphone/curl/curl.xcodeproj/project.pbxproj +3 -3
  193. data/platform/iphone/rbuild/iphone.rake +168 -119
  194. data/platform/iphone/rhoextlib/rhoextlib.xcodeproj/project.pbxproj +4 -2
  195. data/platform/iphone/rhorubylib/rhorubylib.xcodeproj/project.pbxproj +3 -3
  196. data/platform/iphone/rhorunner.xcodeproj/project.pbxproj +2 -2
  197. data/platform/iphone/rhosynclib/rhosynclib.xcodeproj/project.pbxproj +3 -3
  198. data/platform/shared/SyncClient/SyncClient.cpp +20 -8
  199. data/platform/shared/SyncClient/SyncClient.h +2 -1
  200. data/platform/shared/common/RhoDefs.h +4 -0
  201. data/platform/shared/common/RhoPort.h +22 -0
  202. data/platform/shared/common/RhoStd.h +5 -0
  203. data/platform/shared/common/RhoTime.cpp +73 -0
  204. data/platform/shared/common/RhoTime.h +26 -53
  205. data/platform/shared/common/RhodesApp.cpp +29 -28
  206. data/platform/shared/common/RhodesApp.h +4 -1
  207. data/platform/shared/common/StringConverter.h +37 -10
  208. data/platform/shared/common/app_build_capabilities.h +2 -0
  209. data/platform/shared/common/rhoparams.cpp +25 -12
  210. data/platform/shared/common/rhoparams.h +10 -8
  211. data/platform/shared/db/DBAdapter.cpp +0 -22
  212. data/platform/shared/json/RJSONTokener.c +15 -23
  213. data/platform/shared/net/AsyncHttp.cpp +9 -8
  214. data/platform/shared/net/HttpServer.cpp +61 -19
  215. data/platform/shared/net/HttpServer.h +2 -0
  216. data/platform/shared/ruby/ext/datetimepicker/datetimepicker.i +3 -0
  217. data/platform/shared/ruby/ext/datetimepicker/datetimepicker_wrap.c +151 -402
  218. data/platform/shared/ruby/ext/nativebar/nativebar.i +3 -0
  219. data/platform/shared/ruby/ext/nativebar/nativebar_wrap.c +154 -403
  220. data/platform/shared/ruby/ext/rho/rhoruby.c +4 -0
  221. data/platform/shared/ruby/ext/rho/rhoruby.h +2 -0
  222. data/platform/shared/ruby/ext/system/system.i +8 -0
  223. data/platform/shared/ruby/ext/system/system_wrap.c +80 -5
  224. data/platform/shared/ruby/file.c +6 -4
  225. data/platform/shared/ruby/gc.c +1 -1
  226. data/platform/shared/ruby/linux/ruby/config.h +7 -2
  227. data/platform/shared/ruby/missing/acosh.c +3 -3
  228. data/platform/shared/ruby/wince/_time.h +1 -1
  229. data/platform/shared/ruby/wince/stdlib.c +1 -1
  230. data/platform/shared/ruby/wince/string_wce.c +2 -2
  231. data/platform/shared/ruby/wince/sys/timeb.c +1 -0
  232. data/platform/shared/ruby/wince/time_wce.c +8 -0
  233. data/platform/shared/ruby/wince/wince.c +7 -7
  234. data/platform/shared/ruby/wince/wince.h +22 -0
  235. data/platform/shared/rubyext/System.cpp +19 -1
  236. data/platform/shared/sqlite/sqlite3.c +18993 -8129
  237. data/platform/shared/sqlite/sqlite3.h +953 -358
  238. data/platform/shared/sqlite/sqlite3ext.h +42 -0
  239. data/platform/shared/sync/SyncEngine.cpp +10 -0
  240. data/platform/shared/sync/SyncSource.cpp +41 -19
  241. data/platform/shared/sync/SyncSource.h +1 -1
  242. data/platform/shared/tcmalloc/rhomem.h +7 -2
  243. data/platform/shared/tcmalloc/windows/port.h +2 -0
  244. data/platform/shared/unzip/unzip.cpp +1 -0
  245. data/platform/shared/xruby/src/com/xruby/compiler/parser/RubyParser.java +11 -1
  246. data/platform/wm/RhoLib/RhoLib.vcproj +182 -24
  247. data/platform/wm/build/wm.rake +16 -3
  248. data/platform/wm/rhodes.sln +106 -113
  249. data/platform/wm/rhodes/Alert.cpp +6 -7
  250. data/platform/wm/rhodes/AppManager.cpp +8 -17
  251. data/platform/wm/rhodes/DateTimePicker.cpp +3 -0
  252. data/platform/wm/rhodes/DateTimePicker.h +2 -0
  253. data/platform/wm/rhodes/MainWindow.cpp +36 -16
  254. data/platform/wm/rhodes/MainWindow.h +6 -3
  255. data/platform/wm/rhodes/OutlookApp.cpp +3 -3
  256. data/platform/wm/rhodes/Rhodes.cpp +46 -27
  257. data/platform/wm/rhodes/Rhodes.rc +16 -3
  258. data/platform/wm/rhodes/RingtoneManager.cpp +7 -7
  259. data/platform/wm/rhodes/RingtoneManager.h +1 -1
  260. data/platform/wm/rhodes/Utils.cpp +2 -1
  261. data/platform/wm/rhodes/bluetooth/Bluetooth.cpp +1 -13
  262. data/platform/wm/rhodes/bluetooth/Bluetooth.h +1 -2
  263. data/platform/wm/rhodes/camera/Camera.cpp +6 -12
  264. data/platform/wm/rhodes/phonebook/phonebook.cpp +11 -11
  265. data/platform/wm/rhodes/phonebook/phonebook.h +1 -1
  266. data/platform/wm/rhodes/resource.h +3 -1
  267. data/platform/wm/rhodes/rho/net/NetRequestImpl.cpp +7 -5
  268. data/platform/wm/rhodes/rho/rubyext/GeoLocationImpl.cpp +6 -6
  269. data/platform/wm/rhodes/rho/rubyext/GeoLocationImpl.h +1 -1
  270. data/platform/wm/rhodes/rho/rubyext/NativeToolbar.cpp +6 -1
  271. data/platform/wm/rhodes/rho/rubyext/SystemImpl.cpp +84 -19
  272. data/platform/wm/rhodes/rho/rubyext/calendar.cpp +2 -2
  273. data/platform/wm/rhodes/rhodes.vcproj +316 -73
  274. data/platform/wm/rhodes/signature/Signature.cpp +336 -6
  275. data/platform/wm/rhodes/signature/Signature.h +55 -0
  276. data/platform/wm/rhodes/stdafx.h +7 -4
  277. data/platform/wm/rubylib/rubylib.vcproj +261 -91
  278. data/platform/wm/sqlite3/sqlite3.vcproj +223 -69
  279. data/platform/wm/syncengine/syncengine.vcproj +220 -66
  280. data/platform/wm/tcmalloc/tcmalloc.vcproj +197 -43
  281. data/platform/wp7/IronRuby/Languages/Ruby/Ruby/Builtins/ConsoleStream.cs +107 -0
  282. data/platform/wp7/IronRuby/Languages/Ruby/Ruby/Runtime/Loader.cs +1037 -0
  283. data/platform/wp7/IronRuby/Languages/Ruby/Ruby/Runtime/RubyUtils.cs +1476 -0
  284. data/platform/wp7/RhoAppRunner/Program.cs +55 -0
  285. data/platform/wp7/RhoAppRunner/Properties/AssemblyInfo.cs +36 -0
  286. data/platform/wp7/RhoAppRunner/RhoAppRunner.csproj +69 -0
  287. data/platform/wp7/RhoRubyExtGen/GenerateInitializers.cmd +7 -0
  288. data/platform/wp7/RhoRubyExtGen/Properties/AssemblyInfo.cs +36 -0
  289. data/platform/wp7/RhoRubyExtGen/RhoAsyncHttp.cs +38 -0
  290. data/platform/wp7/RhoRubyExtGen/RhoDatabase.cs +93 -0
  291. data/platform/wp7/RhoRubyExtGen/RhoJSON.cs +37 -0
  292. data/platform/wp7/RhoRubyExtGen/RhoNativeBar.cs +106 -0
  293. data/platform/wp7/RhoRubyExtGen/RhoRubyExtGen.csproj +75 -0
  294. data/platform/wp7/RhoRubyExtGen/RhoSyncEngine.cs +123 -0
  295. data/platform/wp7/RhoRubyExtGen/RhoWebView.cs +42 -0
  296. data/platform/wp7/RhoRubyLib/Initializers.Generated.cs +309 -0
  297. data/platform/wp7/RhoRubyLib/Properties/AssemblyInfo.cs +36 -0
  298. data/platform/wp7/RhoRubyLib/RhoAppAdapter.cs +96 -0
  299. data/platform/wp7/RhoRubyLib/RhoRuby.cs +296 -0
  300. data/platform/wp7/RhoRubyLib/RhoRubyLib.csproj +155 -0
  301. data/platform/wp7/RhoRubyLib/WP_PlatformAdaptationLayer.cs +107 -0
  302. data/platform/wp7/RhoRubyLib/common/IInputStream.cs +21 -0
  303. data/platform/wp7/RhoRubyLib/common/Mutex.cs +30 -0
  304. data/platform/wp7/RhoRubyLib/common/RhoConf.cs +389 -0
  305. data/platform/wp7/RhoRubyLib/common/RhoEmptyProfiler.cs +27 -0
  306. data/platform/wp7/RhoRubyLib/common/RhoFile.cs +332 -0
  307. data/platform/wp7/RhoRubyLib/common/RhoFilePath.cs +89 -0
  308. data/platform/wp7/RhoRubyLib/common/RhoParamArray.cs +33 -0
  309. data/platform/wp7/RhoRubyLib/common/RhoParams.cs +66 -0
  310. data/platform/wp7/RhoRubyLib/common/RhoProfiler.cs +145 -0
  311. data/platform/wp7/RhoRubyLib/common/RhoResourceMap.cs +68 -0
  312. data/platform/wp7/RhoRubyLib/common/RhoStd.cs +205 -0
  313. data/platform/wp7/RhoRubyLib/common/RhoThread.cs +114 -0
  314. data/platform/wp7/RhoRubyLib/common/RhodesApp.cs +504 -0
  315. data/platform/wp7/RhoRubyLib/common/ThreadQueue.cs +199 -0
  316. data/platform/wp7/RhoRubyLib/common/TimeInterval.cs +56 -0
  317. data/platform/wp7/RhoRubyLib/common/Tokenizer.cs +52 -0
  318. data/platform/wp7/RhoRubyLib/db/DBAdapter.cs +1129 -0
  319. data/platform/wp7/RhoRubyLib/db/DBAttrManager.cs +92 -0
  320. data/platform/wp7/RhoRubyLib/db/DBException.cs +35 -0
  321. data/platform/wp7/RhoRubyLib/db/IDBCallback.cs +10 -0
  322. data/platform/wp7/RhoRubyLib/db/IDBResult.cs +33 -0
  323. data/platform/wp7/RhoRubyLib/db/IDBStorage.cs +32 -0
  324. data/platform/wp7/RhoRubyLib/db/SqliteCopyResult.cs +79 -0
  325. data/platform/wp7/RhoRubyLib/db/SqliteResult.cs +267 -0
  326. data/platform/wp7/RhoRubyLib/db/SqliteStorage.cs +319 -0
  327. data/platform/wp7/RhoRubyLib/json/JSONArrayIterator.cs +63 -0
  328. data/platform/wp7/RhoRubyLib/json/JSONEntry.cs +96 -0
  329. data/platform/wp7/RhoRubyLib/json/JSONStructIterator.cs +77 -0
  330. data/platform/wp7/RhoRubyLib/json/JsonParser.cs +483 -0
  331. data/platform/wp7/RhoRubyLib/json/RJSONTokener.cs +406 -0
  332. data/platform/wp7/RhoRubyLib/logging/IRhoLogSink.cs +12 -0
  333. data/platform/wp7/RhoRubyLib/logging/RhoLogConf.cs +161 -0
  334. data/platform/wp7/RhoRubyLib/logging/RhoLogFileSink.cs +174 -0
  335. data/platform/wp7/RhoRubyLib/logging/RhoLogger.cs +320 -0
  336. data/platform/wp7/RhoRubyLib/net/AsyncHttp.cs +362 -0
  337. data/platform/wp7/RhoRubyLib/net/HttpServer.cs +466 -0
  338. data/platform/wp7/RhoRubyLib/net/NetRequest.cs +717 -0
  339. data/platform/wp7/RhoRubyLib/net/NetResponse.cs +64 -0
  340. data/platform/wp7/RhoRubyLib/net/URI.cs +187 -0
  341. data/platform/wp7/RhoRubyLib/rubyext/RhoAsyncHttp.cs +43 -0
  342. data/platform/wp7/RhoRubyLib/rubyext/RhoDatabase.cs +177 -0
  343. data/platform/wp7/RhoRubyLib/rubyext/RhoJSON.cs +39 -0
  344. data/platform/wp7/RhoRubyLib/rubyext/RhoKernelOps.cs +19 -0
  345. data/platform/wp7/RhoRubyLib/rubyext/RhoNativeBar.cs +117 -0
  346. data/platform/wp7/RhoRubyLib/rubyext/RhoSyncEngine.cs +199 -0
  347. data/platform/wp7/RhoRubyLib/rubyext/RhoWebView.cs +49 -0
  348. data/platform/wp7/RhoRubyLib/sync/ClientRegister.cs +142 -0
  349. data/platform/wp7/RhoRubyLib/sync/ISyncProtocol.cs +23 -0
  350. data/platform/wp7/RhoRubyLib/sync/ISyncStatusListener.cs +10 -0
  351. data/platform/wp7/RhoRubyLib/sync/SyncEngine.cs +1051 -0
  352. data/platform/wp7/RhoRubyLib/sync/SyncNotify.cs +651 -0
  353. data/platform/wp7/RhoRubyLib/sync/SyncProtocol_3.cs +79 -0
  354. data/platform/wp7/RhoRubyLib/sync/SyncSource.cs +1105 -0
  355. data/platform/wp7/RhoRubyLib/sync/SyncThread.cs +301 -0
  356. data/platform/wp7/WPApplication.sln +50 -0
  357. data/platform/wp7/WPApplication/App.xaml +19 -0
  358. data/platform/wp7/WPApplication/App.xaml.cs +211 -0
  359. data/platform/wp7/WPApplication/ApplicationIcon.png +0 -0
  360. data/platform/wp7/WPApplication/Background.png +0 -0
  361. data/platform/wp7/WPApplication/MainPage.xaml +44 -0
  362. data/platform/wp7/WPApplication/MainPage.xaml.cs +132 -0
  363. data/platform/wp7/WPApplication/Properties/AppManifest.xml +6 -0
  364. data/platform/wp7/WPApplication/Properties/AssemblyInfo.cs +35 -0
  365. data/platform/wp7/WPApplication/Properties/WMAppManifest.xml +32 -0
  366. data/platform/wp7/WPApplication/SplashScreenImage.jpg +0 -0
  367. data/platform/wp7/WPApplication/WPApplication.csproj +201 -0
  368. data/platform/wp7/WPApplication/WP_PlatformAdaptationLayer.cs +88 -0
  369. data/platform/wp7/WPApplication/app_manifest.txt +1 -0
  370. data/platform/wp7/WPApplication/readme.htm +40 -0
  371. data/platform/wp7/WPApplication/readme2.htm +37 -0
  372. data/platform/wp7/WPApplication/rho/apps/app/Model1/edit.bb.erb +29 -0
  373. data/platform/wp7/WPApplication/rho/apps/app/Model1/edit.erb +32 -0
  374. data/platform/wp7/WPApplication/rho/apps/app/Model1/index.bb.erb +21 -0
  375. data/platform/wp7/WPApplication/rho/apps/app/Model1/index.erb +26 -0
  376. data/platform/wp7/WPApplication/rho/apps/app/Model1/model1.rb +10 -0
  377. data/platform/wp7/WPApplication/rho/apps/app/Model1/model1_controller.rb +58 -0
  378. data/platform/wp7/WPApplication/rho/apps/app/Model1/new.bb.erb +29 -0
  379. data/platform/wp7/WPApplication/rho/apps/app/Model1/new.erb +31 -0
  380. data/platform/wp7/WPApplication/rho/apps/app/Model1/show.bb.erb +26 -0
  381. data/platform/wp7/WPApplication/rho/apps/app/Model1/show.erb +28 -0
  382. data/platform/wp7/WPApplication/rho/apps/app/Settings/controller.rb +75 -0
  383. data/platform/wp7/WPApplication/rho/apps/app/Settings/home.bb.erb +17 -0
  384. data/platform/wp7/WPApplication/rho/apps/app/Settings/home.erb +20 -0
  385. data/platform/wp7/WPApplication/rho/apps/app/Settings/index.bb.erb +32 -0
  386. data/platform/wp7/WPApplication/rho/apps/app/Settings/index.erb +30 -0
  387. data/platform/wp7/WPApplication/rho/apps/app/Settings/login.bb.erb +35 -0
  388. data/platform/wp7/WPApplication/rho/apps/app/Settings/login.erb +27 -0
  389. data/platform/wp7/WPApplication/rho/apps/app/Settings/reset.bb.erb +15 -0
  390. data/platform/wp7/WPApplication/rho/apps/app/Settings/reset.erb +17 -0
  391. data/platform/wp7/WPApplication/rho/apps/app/Settings/wait.bb.erb +3 -0
  392. data/platform/wp7/WPApplication/rho/apps/app/Settings/wait.erb +5 -0
  393. data/platform/wp7/WPApplication/rho/apps/app/application.rb +16 -0
  394. data/platform/wp7/WPApplication/rho/apps/app/helpers/application_helper.rb +126 -0
  395. data/platform/wp7/WPApplication/rho/apps/app/helpers/browser_helper.rb +18 -0
  396. data/platform/wp7/WPApplication/rho/apps/app/index.bb.erb +26 -0
  397. data/platform/wp7/WPApplication/rho/apps/app/index.erb +26 -0
  398. data/platform/wp7/WPApplication/rho/apps/app/layout.erb +45 -0
  399. data/platform/wp7/WPApplication/rho/apps/app/loading.html +11 -0
  400. data/platform/wp7/WPApplication/rho/apps/app_manifest.txt +1 -0
  401. data/platform/wp7/WPApplication/rho/apps/public/css/android.css +330 -0
  402. data/platform/wp7/WPApplication/rho/apps/public/css/blackberry.css +115 -0
  403. data/platform/wp7/WPApplication/rho/apps/public/css/iphone.css +410 -0
  404. data/platform/wp7/WPApplication/rho/apps/public/css/windows_mobile.css +222 -0
  405. data/platform/wp7/WPApplication/rho/apps/public/images/IUI_LICENSE.txt +21 -0
  406. data/platform/wp7/WPApplication/rho/apps/public/images/android/btn_check_off.png +0 -0
  407. data/platform/wp7/WPApplication/rho/apps/public/images/android/btn_check_on.png +0 -0
  408. data/platform/wp7/WPApplication/rho/apps/public/images/android/btn_radio_off.png +0 -0
  409. data/platform/wp7/WPApplication/rho/apps/public/images/android/btn_radio_on.png +0 -0
  410. data/platform/wp7/WPApplication/rho/apps/public/images/android/disclosure.png +0 -0
  411. data/platform/wp7/WPApplication/rho/apps/public/images/android/ic_menu_more.png +0 -0
  412. data/platform/wp7/WPApplication/rho/apps/public/images/backButton.png +0 -0
  413. data/platform/wp7/WPApplication/rho/apps/public/images/blueButton.png +0 -0
  414. data/platform/wp7/WPApplication/rho/apps/public/images/cancel.png +0 -0
  415. data/platform/wp7/WPApplication/rho/apps/public/images/grayButton.png +0 -0
  416. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/disclosure.png +0 -0
  417. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/disclosure_detail.png +0 -0
  418. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/backButton.png +0 -0
  419. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/blueButton.png +0 -0
  420. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/cancel.png +0 -0
  421. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/chevron.png +0 -0
  422. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/grayButton.png +0 -0
  423. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/listArrowSel.png +0 -0
  424. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/listGroup.png +0 -0
  425. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/loading.gif +0 -0
  426. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/on_off.png +0 -0
  427. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/pinstripes.png +0 -0
  428. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/selection.png +0 -0
  429. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/thumb.png +0 -0
  430. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/toggle.png +0 -0
  431. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/toggleOn.png +0 -0
  432. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/toolButton.png +0 -0
  433. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/toolbar.png +0 -0
  434. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/jqtouch/whiteButton.png +0 -0
  435. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/radiobutton.png +0 -0
  436. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/select.png +0 -0
  437. data/platform/wp7/WPApplication/rho/apps/public/images/iphone/switch.png +0 -0
  438. data/platform/wp7/WPApplication/rho/apps/public/images/iui-logo-touch-icon.png +0 -0
  439. data/platform/wp7/WPApplication/rho/apps/public/images/listArrow.png +0 -0
  440. data/platform/wp7/WPApplication/rho/apps/public/images/listArrowDown.png +0 -0
  441. data/platform/wp7/WPApplication/rho/apps/public/images/listArrowSel.png +0 -0
  442. data/platform/wp7/WPApplication/rho/apps/public/images/listGroup.png +0 -0
  443. data/platform/wp7/WPApplication/rho/apps/public/images/loading.gif +0 -0
  444. data/platform/wp7/WPApplication/rho/apps/public/images/pinstripes.png +0 -0
  445. data/platform/wp7/WPApplication/rho/apps/public/images/right_button.png +0 -0
  446. data/platform/wp7/WPApplication/rho/apps/public/images/selection.png +0 -0
  447. data/platform/wp7/WPApplication/rho/apps/public/images/thumb.png +0 -0
  448. data/platform/wp7/WPApplication/rho/apps/public/images/toggle.png +0 -0
  449. data/platform/wp7/WPApplication/rho/apps/public/images/toggleOn.png +0 -0
  450. data/platform/wp7/WPApplication/rho/apps/public/images/toolButton.png +0 -0
  451. data/platform/wp7/WPApplication/rho/apps/public/images/toolButton_new.png +0 -0
  452. data/platform/wp7/WPApplication/rho/apps/public/images/toolbar.png +0 -0
  453. data/platform/wp7/WPApplication/rho/apps/public/images/whiteButton.png +0 -0
  454. data/platform/wp7/WPApplication/rho/apps/public/jqtouch/jqtouch-iphone.css +9 -0
  455. data/platform/wp7/WPApplication/rho/apps/public/jqtouch/jqtouch.css +374 -0
  456. data/platform/wp7/WPApplication/rho/apps/public/jqtouch/jqtouch.js +742 -0
  457. data/platform/wp7/WPApplication/rho/apps/public/jqtouch/jqtouch.transitions.js +60 -0
  458. data/platform/wp7/WPApplication/rho/apps/public/jqtouch/jquery.1.3.2.min.js +19 -0
  459. data/platform/wp7/WPApplication/rho/apps/public/js/application.js +1 -0
  460. data/platform/wp7/WPApplication/rho/apps/public/js/rho.js +4 -0
  461. data/platform/wp7/WPApplication/rho/apps/public/js/rhogeolocation-wm.js +59 -0
  462. data/platform/wp7/WPApplication/rho/apps/public/js/rhogeolocation.js +11 -0
  463. data/platform/wp7/WPApplication/rho/apps/rhoconfig.txt +32 -0
  464. data/platform/wp7/WPApplication/rhoconfig.txt +32 -0
  465. data/platform/wp7/WPApplication/windows_mobile.css +222 -0
  466. data/platform/wp7/build/wp.rake +261 -0
  467. data/platform/wp7/rhodes.sln +79 -0
  468. data/platform/wp7/rhodes/App.xaml +19 -0
  469. data/platform/wp7/rhodes/App.xaml.cs +144 -0
  470. data/platform/wp7/rhodes/Background.png +0 -0
  471. data/platform/wp7/rhodes/MainPage.xaml +44 -0
  472. data/platform/wp7/rhodes/MainPage.xaml.cs +98 -0
  473. data/platform/wp7/rhodes/Properties/AppManifest.xml +6 -0
  474. data/platform/wp7/rhodes/Properties/AssemblyInfo.cs +35 -0
  475. data/platform/wp7/rhodes/Properties/WMAppManifest.xml +31 -0
  476. data/platform/wp7/rhodes/Rhodes.csproj +127 -0
  477. data/platform/wp7/rhodes/SplashScreenImage.jpg +0 -0
  478. data/platform/wp7/rhodes/icon.png +0 -0
  479. data/platform/wp7/sqlite3/Properties/AssemblyInfo.cs +35 -0
  480. data/platform/wp7/sqlite3/SQLiteClient.cs +550 -0
  481. data/platform/wp7/sqlite3/SqliteWrapper/BtreeInt_h.cs +774 -0
  482. data/platform/wp7/sqlite3/SqliteWrapper/Btree_h.cs +280 -0
  483. data/platform/wp7/sqlite3/SqliteWrapper/ClassDiagram1.cd +1306 -0
  484. data/platform/wp7/sqlite3/SqliteWrapper/Delagates.cs +365 -0
  485. data/platform/wp7/sqlite3/SqliteWrapper/Hash_h.cs +133 -0
  486. data/platform/wp7/sqlite3/SqliteWrapper/VdbeInt_h.cs +620 -0
  487. data/platform/wp7/sqlite3/SqliteWrapper/Vdbe_h.cs +302 -0
  488. data/platform/wp7/sqlite3/SqliteWrapper/_Custom.cs +449 -0
  489. data/platform/wp7/sqlite3/SqliteWrapper/alter_c.cs +872 -0
  490. data/platform/wp7/sqlite3/SqliteWrapper/analyze_c.cs +757 -0
  491. data/platform/wp7/sqlite3/SqliteWrapper/attach_c.cs +628 -0
  492. data/platform/wp7/sqlite3/SqliteWrapper/auth_c.cs +268 -0
  493. data/platform/wp7/sqlite3/SqliteWrapper/backup_c.cs +737 -0
  494. data/platform/wp7/sqlite3/SqliteWrapper/bitvec_c.cs +509 -0
  495. data/platform/wp7/sqlite3/SqliteWrapper/btmutex_c.cs +379 -0
  496. data/platform/wp7/sqlite3/SqliteWrapper/btree_c.cs +9138 -0
  497. data/platform/wp7/sqlite3/SqliteWrapper/build_c.cs +4189 -0
  498. data/platform/wp7/sqlite3/SqliteWrapper/callback_c.cs +548 -0
  499. data/platform/wp7/sqlite3/SqliteWrapper/complete_c.cs +342 -0
  500. data/platform/wp7/sqlite3/SqliteWrapper/ctime_cs.cs +408 -0
  501. data/platform/wp7/sqlite3/SqliteWrapper/date_c.cs +1317 -0
  502. data/platform/wp7/sqlite3/SqliteWrapper/delete_c.cs +726 -0
  503. data/platform/wp7/sqlite3/SqliteWrapper/expr_c.cs +4406 -0
  504. data/platform/wp7/sqlite3/SqliteWrapper/fault_c.cs +115 -0
  505. data/platform/wp7/sqlite3/SqliteWrapper/fkey_c.cs +1330 -0
  506. data/platform/wp7/sqlite3/SqliteWrapper/func_c.cs +2025 -0
  507. data/platform/wp7/sqlite3/SqliteWrapper/global_c.cs +228 -0
  508. data/platform/wp7/sqlite3/SqliteWrapper/hash_c.cs +351 -0
  509. data/platform/wp7/sqlite3/SqliteWrapper/hwtime_c.cs +101 -0
  510. data/platform/wp7/sqlite3/SqliteWrapper/insert_c.cs +2122 -0
  511. data/platform/wp7/sqlite3/SqliteWrapper/journal_c.cs +247 -0
  512. data/platform/wp7/sqlite3/SqliteWrapper/keywordhash_h.cs +302 -0
  513. data/platform/wp7/sqlite3/SqliteWrapper/legacy_c.cs +223 -0
  514. data/platform/wp7/sqlite3/SqliteWrapper/loadext_c.cs +683 -0
  515. data/platform/wp7/sqlite3/SqliteWrapper/main_c.cs +2716 -0
  516. data/platform/wp7/sqlite3/SqliteWrapper/malloc_c.cs +977 -0
  517. data/platform/wp7/sqlite3/SqliteWrapper/mem_Pool.cs +394 -0
  518. data/platform/wp7/sqlite3/SqliteWrapper/memjournal_c.cs +315 -0
  519. data/platform/wp7/sqlite3/SqliteWrapper/mutex_c.cs +182 -0
  520. data/platform/wp7/sqlite3/SqliteWrapper/mutex_h.cs +91 -0
  521. data/platform/wp7/sqlite3/SqliteWrapper/mutex_noop_c.cs +202 -0
  522. data/platform/wp7/sqlite3/SqliteWrapper/mutex_w32.cs +344 -0
  523. data/platform/wp7/sqlite3/SqliteWrapper/notify_c.cs +347 -0
  524. data/platform/wp7/sqlite3/SqliteWrapper/opcodes_c.cs +171 -0
  525. data/platform/wp7/sqlite3/SqliteWrapper/opcodes_h.cs +346 -0
  526. data/platform/wp7/sqlite3/SqliteWrapper/os_c.cs +367 -0
  527. data/platform/wp7/sqlite3/SqliteWrapper/os_common_h.cs +174 -0
  528. data/platform/wp7/sqlite3/SqliteWrapper/os_h.cs +295 -0
  529. data/platform/wp7/sqlite3/SqliteWrapper/os_win_c.cs +1255 -0
  530. data/platform/wp7/sqlite3/SqliteWrapper/pager_c.cs +6078 -0
  531. data/platform/wp7/sqlite3/SqliteWrapper/pager_h.cs +188 -0
  532. data/platform/wp7/sqlite3/SqliteWrapper/parse_c.cs +4045 -0
  533. data/platform/wp7/sqlite3/SqliteWrapper/parse_h.cs +331 -0
  534. data/platform/wp7/sqlite3/SqliteWrapper/pcache1_c.cs +969 -0
  535. data/platform/wp7/sqlite3/SqliteWrapper/pcache_c.cs +712 -0
  536. data/platform/wp7/sqlite3/SqliteWrapper/pcache_h.cs +213 -0
  537. data/platform/wp7/sqlite3/SqliteWrapper/pragma_c.cs +1767 -0
  538. data/platform/wp7/sqlite3/SqliteWrapper/prepare_c.cs +1015 -0
  539. data/platform/wp7/sqlite3/SqliteWrapper/printf_c.cs +1300 -0
  540. data/platform/wp7/sqlite3/SqliteWrapper/random_c.cs +201 -0
  541. data/platform/wp7/sqlite3/SqliteWrapper/resolve_c.cs +1396 -0
  542. data/platform/wp7/sqlite3/SqliteWrapper/rowset_c.cs +519 -0
  543. data/platform/wp7/sqlite3/SqliteWrapper/select_c.cs +4878 -0
  544. data/platform/wp7/sqlite3/SqliteWrapper/sqlite3_h.cs +6253 -0
  545. data/platform/wp7/sqlite3/SqliteWrapper/sqlite3ext_h.cs +397 -0
  546. data/platform/wp7/sqlite3/SqliteWrapper/sqliteInt_h.cs +4075 -0
  547. data/platform/wp7/sqlite3/SqliteWrapper/sqliteLimit_h.cs +214 -0
  548. data/platform/wp7/sqlite3/SqliteWrapper/sqliteicu_h.cs +39 -0
  549. data/platform/wp7/sqlite3/SqliteWrapper/status_c.cs +155 -0
  550. data/platform/wp7/sqlite3/SqliteWrapper/table_c.cs +222 -0
  551. data/platform/wp7/sqlite3/SqliteWrapper/tokenize_c.cs +673 -0
  552. data/platform/wp7/sqlite3/SqliteWrapper/trigger_c.cs +1219 -0
  553. data/platform/wp7/sqlite3/SqliteWrapper/update_c.cs +766 -0
  554. data/platform/wp7/sqlite3/SqliteWrapper/utf_c.cs +612 -0
  555. data/platform/wp7/sqlite3/SqliteWrapper/util_c.cs +1476 -0
  556. data/platform/wp7/sqlite3/SqliteWrapper/vacuum_c.cs +382 -0
  557. data/platform/wp7/sqlite3/SqliteWrapper/vdbe_c.cs +6566 -0
  558. data/platform/wp7/sqlite3/SqliteWrapper/vdbeapi_c.cs +1557 -0
  559. data/platform/wp7/sqlite3/SqliteWrapper/vdbeaux_c.cs +4019 -0
  560. data/platform/wp7/sqlite3/SqliteWrapper/vdbeblob_c.cs +396 -0
  561. data/platform/wp7/sqlite3/SqliteWrapper/vdbemem_c.cs +1480 -0
  562. data/platform/wp7/sqlite3/SqliteWrapper/vdbetrace_c.cs +181 -0
  563. data/platform/wp7/sqlite3/SqliteWrapper/vtab_c.cs +957 -0
  564. data/platform/wp7/sqlite3/SqliteWrapper/walker_c.cs +174 -0
  565. data/platform/wp7/sqlite3/SqliteWrapper/where_c.cs +4651 -0
  566. data/platform/wp7/sqlite3/sqlite3.csproj +155 -0
  567. data/rakefile.rb +60 -2
  568. data/res/build-tools/7za.exe +0 -0
  569. data/res/build-tools/RhoAppRunner.exe +0 -0
  570. data/res/build-tools/xruby-0.3.3.jar +0 -0
  571. data/res/generators/rhogen.rb +9 -1
  572. data/res/generators/templates/application/app/Settings/reset.erb +1 -1
  573. data/res/generators/templates/application/app/layout.erb +17 -10
  574. data/res/generators/templates/application/build.yml +5 -3
  575. data/res/generators/templates/application/public/jqtouch/changes.txt +20 -0
  576. data/res/generators/templates/application/public/jqtouch/jqtouch.js +12 -4
  577. data/res/generators/templates/application/public/jqtouch/jquery.1.3.2.min.js +1 -1
  578. data/res/generators/templates/application/public/js/wp7.js +7 -0
  579. data/res/generators/templates/model/controller.rb +5 -6
  580. data/rhobuild.yml.example +1 -0
  581. data/rhodes.gemspec +2 -1
  582. data/spec/framework_spec/app/spec/core/dir/close_spec.rb +1 -1
  583. data/spec/framework_spec/app/spec/core/dir/shared/pwd.rb +13 -11
  584. data/spec/framework_spec/app/spec/core/env/shared/store.rb +12 -10
  585. data/spec/framework_spec/app/spec/core/env/update_spec.rb +1 -0
  586. data/spec/framework_spec/app/spec/core/file/expand_path_spec.rb +3 -2
  587. data/spec/framework_spec/app/spec/core/file/fixtures/file_types.rb +7 -1
  588. data/spec/framework_spec/app/spec/core/file/flock_spec.rb +8 -1
  589. data/spec/framework_spec/app/spec/core/file/ftype_spec.rb +5 -3
  590. data/spec/framework_spec/app/spec/core/file/lchmod_spec.rb +1 -1
  591. data/spec/framework_spec/app/spec/core/file/setgid_spec.rb +1 -1
  592. data/spec/framework_spec/app/spec/core/file/setuid_spec.rb +1 -1
  593. data/spec/framework_spec/app/spec/core/file/stat/ftype_spec.rb +6 -4
  594. data/spec/framework_spec/app/spec/core/file/truncate_spec.rb +5 -1
  595. data/spec/framework_spec/app/spec/core/float/to_s_spec.rb +1 -1
  596. data/spec/framework_spec/app/spec/core/process/gid_spec.rb +5 -3
  597. data/spec/framework_spec/app/spec/core/process/groups_spec.rb +11 -9
  598. data/spec/framework_spec/app/spec/core/process/uid_spec.rb +5 -3
  599. data/spec/framework_spec/app/spec/language/execution_spec.rb +10 -6
  600. data/spec/framework_spec/app/spec/shared/file/directory.rb +6 -1
  601. data/spec/framework_spec/app/spec/shared/file/executable.rb +7 -1
  602. data/spec/framework_spec/app/spec/shared/file/file.rb +6 -1
  603. data/spec/framework_spec/app/spec/shared/file/readable.rb +13 -4
  604. data/spec/framework_spec/app/spec/shared/file/writable.rb +6 -1
  605. data/spec/phone_spec/app/spec/rho_controller_spec.rb +11 -0
  606. data/spec/phone_spec/app/spec/rho_spec.rb +11 -0
  607. data/spec/phone_spec/app/spec/rhom_object_spec.rb +102 -6
  608. data/spec/phone_spec/app/spec/string/end_with_spec.rb +4 -1
  609. data/spec/phone_spec/app/spec/string/slice_spec.rb +5 -1
  610. data/spec/phone_spec/app/spec/string/start_with_spec.rb +4 -0
  611. data/spec/phone_spec/app/spec/syncengine_spec.rb +73 -6
  612. data/spec/phone_spec/app/spec_runner.rb +7 -3
  613. metadata +380 -41
  614. data/Manifest.txt +0 -5819
  615. data/platform/bb/Hsqldb/Hsqldb.cso +0 -5
  616. data/platform/bb/Hsqldb/Hsqldb.jdp +0 -197
  617. data/platform/bb/RhoBundle/RhoBundle.cso +0 -5
  618. data/platform/bb/RhoBundle/RhoBundle.jdp +0 -42
  619. data/platform/bb/RubyVM/RubyVM.cso +0 -5
  620. data/platform/bb/RubyVM/RubyVM.jdp +0 -467
  621. data/platform/bb/rhodes/rhodes.csl +0 -3
  622. data/platform/bb/rhodes/rhodes.cso +0 -5
  623. data/platform/bb/rhodes/rhodes.jdp +0 -104
@@ -0,0 +1,2025 @@
1
+ using System;
2
+ using System.Diagnostics;
3
+ using System.Text;
4
+
5
+ using sqlite3_int64 = System.Int64;
6
+ using i64 = System.Int64;
7
+ using u8 = System.Byte;
8
+ using u32 = System.UInt32;
9
+ using u64 = System.UInt64;
10
+
11
+ namespace Community.CsharpSqlite
12
+ {
13
+ using sqlite3_value = Sqlite3.Mem;
14
+ using sqlite_int64 = System.Int64;
15
+
16
+ public partial class Sqlite3
17
+ {
18
+ /*
19
+ ** 2002 February 23
20
+ **
21
+ ** The author disclaims copyright to this source code. In place of
22
+ ** a legal notice, here is a blessing:
23
+ **
24
+ ** May you do good and not evil.
25
+ ** May you find forgiveness for yourself and forgive others.
26
+ ** May you share freely, never taking more than you give.
27
+ **
28
+ *************************************************************************
29
+ ** This file contains the C functions that implement various SQL
30
+ ** functions of SQLite.
31
+ **
32
+ ** There is only one exported symbol in this file - the function
33
+ ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
34
+ ** All other code has file scope.
35
+ *************************************************************************
36
+ ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
37
+ ** C#-SQLite is an independent reimplementation of the SQLite software library
38
+ **
39
+ ** SQLITE_SOURCE_ID: 2010-03-09 19:31:43 4ae453ea7be69018d8c16eb8dabe05617397dc4d
40
+ **
41
+ ** $Header$
42
+ *************************************************************************
43
+ */
44
+ //#include "sqliteInt.h"
45
+ //#include <stdlib.h>
46
+ //#include <assert.h>
47
+ //#include "vdbeInt.h"
48
+
49
+
50
+ /*
51
+ ** Return the collating function associated with a function.
52
+ */
53
+ static CollSeq sqlite3GetFuncCollSeq(sqlite3_context context)
54
+ {
55
+ return context.pColl;
56
+ }
57
+
58
+ /*
59
+ ** Implementation of the non-aggregate min() and max() functions
60
+ */
61
+ static void minmaxFunc(
62
+ sqlite3_context context,
63
+ int argc,
64
+ sqlite3_value[] argv
65
+ )
66
+ {
67
+ int i;
68
+ int mask; /* 0 for min() or 0xffffffff for max() */
69
+ int iBest;
70
+ CollSeq pColl;
71
+
72
+ Debug.Assert(argc > 1);
73
+ mask = (int)sqlite3_user_data(context) == 0 ? 0 : -1;
74
+ pColl = sqlite3GetFuncCollSeq(context);
75
+ Debug.Assert(pColl != null);
76
+ Debug.Assert(mask == -1 || mask == 0);
77
+ testcase(mask == 0);
78
+ iBest = 0;
79
+ if (sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
80
+ for (i = 1; i < argc; i++)
81
+ {
82
+ if (sqlite3_value_type(argv[i]) == SQLITE_NULL) return;
83
+ if ((sqlite3MemCompare(argv[iBest], argv[i], pColl) ^ mask) >= 0)
84
+ {
85
+ iBest = i;
86
+ }
87
+ }
88
+ sqlite3_result_value(context, argv[iBest]);
89
+ }
90
+
91
+ /*
92
+ ** Return the type of the argument.
93
+ */
94
+ static void typeofFunc(
95
+ sqlite3_context context,
96
+ int NotUsed,
97
+ sqlite3_value[] argv
98
+ )
99
+ {
100
+ string z = "";
101
+ UNUSED_PARAMETER(NotUsed);
102
+ switch (sqlite3_value_type(argv[0]))
103
+ {
104
+ case SQLITE_INTEGER: z = "integer"; break;
105
+ case SQLITE_TEXT: z = "text"; break;
106
+ case SQLITE_FLOAT: z = "real"; break;
107
+ case SQLITE_BLOB: z = "blob"; break;
108
+ default: z = "null"; break;
109
+ }
110
+ sqlite3_result_text(context, z, -1, SQLITE_STATIC);
111
+ }
112
+
113
+
114
+ /*
115
+ ** Implementation of the length() function
116
+ */
117
+ static void lengthFunc(
118
+ sqlite3_context context,
119
+ int argc,
120
+ sqlite3_value[] argv
121
+ )
122
+ {
123
+ int len;
124
+
125
+ Debug.Assert(argc == 1);
126
+ UNUSED_PARAMETER(argc);
127
+ switch (sqlite3_value_type(argv[0]))
128
+ {
129
+ case SQLITE_BLOB:
130
+ case SQLITE_INTEGER:
131
+ case SQLITE_FLOAT:
132
+ {
133
+ sqlite3_result_int(context, sqlite3_value_bytes(argv[0]));
134
+ break;
135
+ }
136
+ case SQLITE_TEXT:
137
+ {
138
+ byte[] z = sqlite3_value_blob(argv[0]);
139
+ if (z == null) return;
140
+ len = 0;
141
+ int iz = 0;
142
+ while (iz < z.Length && z[iz] != '\0')
143
+ {
144
+ len++;
145
+ SQLITE_SKIP_UTF8(z, ref iz);
146
+ }
147
+ sqlite3_result_int(context, len);
148
+ break;
149
+ }
150
+ default:
151
+ {
152
+ sqlite3_result_null(context);
153
+ break;
154
+ }
155
+ }
156
+ }
157
+
158
+ /*
159
+ ** Implementation of the abs() function.
160
+ **
161
+ ** IMP: R-23979-26855 The abs(X) function returns the absolute value of
162
+ ** the numeric argument X.
163
+ */
164
+ static void absFunc(
165
+ sqlite3_context context,
166
+ int argc,
167
+ sqlite3_value[] argv
168
+ )
169
+ {
170
+ Debug.Assert(argc == 1);
171
+ UNUSED_PARAMETER(argc);
172
+ switch (sqlite3_value_type(argv[0]))
173
+ {
174
+ case SQLITE_INTEGER:
175
+ {
176
+ i64 iVal = sqlite3_value_int64(argv[0]);
177
+ if (iVal < 0)
178
+ {
179
+ if ((iVal << 1) == 0)
180
+ {
181
+ /* IMP: R-35460-15084 If X is the integer -9223372036854775807 then
182
+ ** abs(X) throws an integer overflow error since there is no
183
+ ** equivalent positive 64-bit two complement value. */
184
+ sqlite3_result_error(context, "integer overflow", -1);
185
+ return;
186
+ }
187
+ iVal = -iVal;
188
+ }
189
+ sqlite3_result_int64(context, iVal);
190
+ break;
191
+ }
192
+ case SQLITE_NULL:
193
+ {
194
+ /* IMP: R-37434-19929 Abs(X) returns NULL if X is NULL. */
195
+ sqlite3_result_null(context);
196
+ break;
197
+ }
198
+ default:
199
+ {
200
+ /* Because sqlite3_value_double() returns 0.0 if the argument is not
201
+ ** something that can be converted into a number, we have:
202
+ ** IMP: R-57326-31541 Abs(X) return 0.0 if X is a string or blob that
203
+ ** cannot be converted to a numeric value.
204
+ */
205
+ double rVal = sqlite3_value_double(argv[0]);
206
+ if (rVal < 0) rVal = -rVal;
207
+ sqlite3_result_double(context, rVal);
208
+ break;
209
+ }
210
+ }
211
+ }
212
+
213
+ /*
214
+ ** Implementation of the substr() function.
215
+ **
216
+ ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
217
+ ** p1 is 1-indexed. So substr(x,1,1) returns the first character
218
+ ** of x. If x is text, then we actually count UTF-8 characters.
219
+ ** If x is a blob, then we count bytes.
220
+ **
221
+ ** If p1 is negative, then we begin abs(p1) from the end of x[].
222
+ **
223
+ ** If p2 is negative, return the p2 characters preceeding p1.
224
+ */
225
+ static void substrFunc(
226
+ sqlite3_context context,
227
+ int argc,
228
+ sqlite3_value[] argv
229
+ )
230
+ {
231
+ string z = "";
232
+ byte[] zBLOB = null;
233
+ string z2;
234
+ int len;
235
+ int p0type;
236
+ int p1, p2;
237
+ int negP2 = 0;
238
+
239
+ Debug.Assert(argc == 3 || argc == 2);
240
+ if (sqlite3_value_type(argv[1]) == SQLITE_NULL
241
+ || (argc == 3 && sqlite3_value_type(argv[2]) == SQLITE_NULL)
242
+ )
243
+ {
244
+ return;
245
+ }
246
+ p0type = sqlite3_value_type(argv[0]);
247
+ p1 = sqlite3_value_int(argv[1]);
248
+ if (p0type == SQLITE_BLOB)
249
+ {
250
+ len = sqlite3_value_bytes(argv[0]);
251
+ zBLOB = argv[0].zBLOB;
252
+ if (zBLOB == null) return;
253
+ Debug.Assert(len == zBLOB.Length);
254
+ }
255
+ else
256
+ {
257
+ z = sqlite3_value_text(argv[0]);
258
+ if (String.IsNullOrEmpty(z)) return;
259
+ len = 0;
260
+ if (p1 < 0)
261
+ {
262
+ len = z.Length;
263
+ //for ( z2 = z ; z2 != "" ; len++ )
264
+ //{
265
+ // SQLITE_SKIP_UTF8( ref z2 );
266
+ //}
267
+ }
268
+ }
269
+ if (argc == 3)
270
+ {
271
+ p2 = sqlite3_value_int(argv[2]);
272
+ if (p2 < 0)
273
+ {
274
+ p2 = -p2;
275
+ negP2 = 1;
276
+ }
277
+ }
278
+ else
279
+ {
280
+ p2 = (sqlite3_context_db_handle(context)).aLimit[SQLITE_LIMIT_LENGTH];
281
+ }
282
+ if (p1 < 0)
283
+ {
284
+ p1 += len;
285
+ if (p1 < 0)
286
+ {
287
+ p2 += p1;
288
+ if (p2 < 0) p2 = 0;
289
+ p1 = 0;
290
+ }
291
+ }
292
+ else if (p1 > 0)
293
+ {
294
+ p1--;
295
+ }
296
+ else if (p2 > 0)
297
+ {
298
+ p2--;
299
+ }
300
+ if (negP2 != 0)
301
+ {
302
+ p1 -= p2;
303
+ if (p1 < 0)
304
+ {
305
+ p2 += p1;
306
+ p1 = 0;
307
+ }
308
+ }
309
+ Debug.Assert(p1 >= 0 && p2 >= 0);
310
+ if (p0type != SQLITE_BLOB)
311
+ {
312
+ //while ( z != "" && p1 != 0 )
313
+ //{
314
+ // SQLITE_SKIP_UTF8( ref z );
315
+ // p1--;
316
+ //}
317
+ //for ( z2 = z ; z2 != "" && p2 != 0 ; p2-- )
318
+ //{
319
+ // SQLITE_SKIP_UTF8( ref z2 );
320
+ //}
321
+ sqlite3_result_text(context, z, p1, p2 <= z.Length - p1 ? p2 : z.Length - p1, SQLITE_TRANSIENT);
322
+ }
323
+ else
324
+ {
325
+ if (p1 + p2 > len)
326
+ {
327
+ p2 = len - p1;
328
+ if (p2 < 0) p2 = 0;
329
+ }
330
+ StringBuilder sb = new StringBuilder(zBLOB.Length);
331
+ if (zBLOB.Length == 0 || p1 > zBLOB.Length) sb.Length = 0;
332
+ else
333
+ {
334
+ for (int i = p1; i < p1 + p2; i++) { sb.Append((char)zBLOB[i]); }
335
+ }
336
+
337
+ sqlite3_result_blob(context, sb.ToString(), (int)p2, SQLITE_TRANSIENT);
338
+ }
339
+ }
340
+
341
+ /*
342
+ ** Implementation of the round() function
343
+ */
344
+ #if !SQLITE_OMIT_FLOATING_POINT
345
+ static void roundFunc(
346
+ sqlite3_context context,
347
+ int argc,
348
+ sqlite3_value[] argv
349
+ )
350
+ {
351
+ int n = 0;
352
+ double r;
353
+ string zBuf = "";
354
+ Debug.Assert(argc == 1 || argc == 2);
355
+ if (argc == 2)
356
+ {
357
+ if (SQLITE_NULL == sqlite3_value_type(argv[1])) return;
358
+ n = sqlite3_value_int(argv[1]);
359
+ if (n > 30) n = 30;
360
+ if (n < 0) n = 0;
361
+ }
362
+ if (sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
363
+ r = sqlite3_value_double(argv[0]);
364
+ /* If Y==0 and X will fit in a 64-bit int,
365
+ ** handle the rounding directly,
366
+ ** otherwise use printf.
367
+ */
368
+ if (n == 0 && r >= 0 && r < LARGEST_INT64 - 1)
369
+ {
370
+ r = (double)((sqlite_int64)(r + 0.5));
371
+ }
372
+ else if (n == 0 && r < 0 && (-r) < LARGEST_INT64 - 1)
373
+ {
374
+ r = -(double)((sqlite_int64)((-r) + 0.5));
375
+ }
376
+ else
377
+ {
378
+ zBuf = sqlite3_mprintf("%.*f", n, r);
379
+ if (zBuf == null)
380
+ {
381
+ sqlite3_result_error_nomem(context);
382
+ return;
383
+ }
384
+ sqlite3AtoF(zBuf, ref r);
385
+ //sqlite3_free( ref zBuf );
386
+ }
387
+ sqlite3_result_double(context, r);
388
+ }
389
+ #endif
390
+
391
+ /*
392
+ ** Allocate nByte bytes of space using sqlite3_malloc(). If the
393
+ ** allocation fails, call sqlite3_result_error_nomem() to notify
394
+ ** the database handle that malloc() has failed and return NULL.
395
+ ** If nByte is larger than the maximum string or blob length, then
396
+ ** raise an SQLITE_TOOBIG exception and return NULL.
397
+ */
398
+ //static void* contextMalloc( sqlite3_context* context, i64 nByte )
399
+ //{
400
+ // char* z;
401
+ // sqlite3* db = sqlite3_context_db_handle( context );
402
+ // assert( nByte > 0 );
403
+ // testcase( nByte == db->aLimit[SQLITE_LIMIT_LENGTH] );
404
+ // testcase( nByte == db->aLimit[SQLITE_LIMIT_LENGTH] + 1 );
405
+ // if ( nByte > db->aLimit[SQLITE_LIMIT_LENGTH] )
406
+ // {
407
+ // sqlite3_result_error_toobig( context );
408
+ // z = 0;
409
+ // }
410
+ // else
411
+ // {
412
+ // z = sqlite3Malloc( (int)nByte );
413
+ // if ( !z )
414
+ // {
415
+ // sqlite3_result_error_nomem( context );
416
+ // }
417
+ // }
418
+ // return z;
419
+ //}
420
+
421
+ /*
422
+ ** Implementation of the upper() and lower() SQL functions.
423
+ */
424
+ static void upperFunc(
425
+ sqlite3_context context,
426
+ int argc,
427
+ sqlite3_value[] argv
428
+ )
429
+ {
430
+ string z1;
431
+ string z2;
432
+ int i, n;
433
+ UNUSED_PARAMETER(argc);
434
+ z2 = sqlite3_value_text(argv[0]);
435
+ n = sqlite3_value_bytes(argv[0]);
436
+ /* Verify that the call to _bytes() does not invalidate the _text() pointer */
437
+ //Debug.Assert( z2 == sqlite3_value_text( argv[0] ) );
438
+ if (z2 != null)
439
+ {
440
+ //z1 = new byte[n];// contextMalloc(context, ((i64)n)+1);
441
+ //if ( z1 !=null)
442
+ //{
443
+ // memcpy( z1, z2, n + 1 );
444
+ //for ( i = 0 ; i< z1.Length ; i++ )
445
+ //{
446
+ //(char)sqlite3Toupper( z1[i] );
447
+ //}
448
+ sqlite3_result_text(context, z2.Length == 0 ? "" : z2.Substring(0, n).ToUpper(), -1, null); //sqlite3_free );
449
+ // }
450
+ }
451
+ }
452
+
453
+ static void lowerFunc(
454
+ sqlite3_context context,
455
+ int argc,
456
+ sqlite3_value[] argv
457
+ )
458
+ {
459
+ string z1;
460
+ string z2;
461
+ int i, n;
462
+ UNUSED_PARAMETER(argc);
463
+ z2 = sqlite3_value_text(argv[0]);
464
+ n = sqlite3_value_bytes(argv[0]);
465
+ /* Verify that the call to _bytes() does not invalidate the _text() pointer */
466
+ //Debug.Assert( z2 == sqlite3_value_text( argv[0] ) );
467
+ if (z2 != null)
468
+ {
469
+ //z1 = contextMalloc(context, ((i64)n)+1);
470
+ //if ( z1 )
471
+ //{
472
+ // memcpy( z1, z2, n + 1 );
473
+ // for ( i = 0 ; z1[i] ; i++ )
474
+ // {
475
+ // z1[i] = (char)sqlite3Tolower( z1[i] );
476
+ // }
477
+ sqlite3_result_text(context, z2.Length == 0 ? "" : z2.Substring(0, n).ToLower(), -1, null);//sqlite3_free );
478
+ //}
479
+ }
480
+ }
481
+
482
+ #if FALSE //* This function is never used. */
483
+ /*
484
+ ** The COALESCE() and IFNULL() functions used to be implemented as shown
485
+ ** here. But now they are implemented as VDBE code so that unused arguments
486
+ ** do not have to be computed. This legacy implementation is retained as
487
+ ** comment.
488
+ */
489
+ /*
490
+ ** Implementation of the IFNULL(), NVL(), and COALESCE() functions.
491
+ ** All three do the same thing. They return the first non-NULL
492
+ ** argument.
493
+ */
494
+ static void ifnullFunc(
495
+ sqlite3_context context,
496
+ int argc,
497
+ sqlite3_value[] argv
498
+ )
499
+ {
500
+ int i;
501
+ for ( i = 0 ; i < argc ; i++ )
502
+ {
503
+ if ( SQLITE_NULL != sqlite3_value_type( argv[i] ) )
504
+ {
505
+ sqlite3_result_value( context, argv[i] );
506
+ break;
507
+ }
508
+ }
509
+ }
510
+ #endif //* NOT USED */
511
+ //#define ifnullFunc versionFunc /* Substitute function - never called */
512
+
513
+ /*
514
+ ** Implementation of random(). Return a random integer.
515
+ */
516
+ static void randomFunc(
517
+ sqlite3_context context,
518
+ int NotUsed,
519
+ sqlite3_value[] NotUsed2
520
+ )
521
+ {
522
+ sqlite_int64 r = 0;
523
+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
524
+ sqlite3_randomness(sizeof(sqlite_int64), ref r);
525
+ if (r < 0)
526
+ {
527
+ /* We need to prevent a random number of 0x8000000000000000
528
+ ** (or -9223372036854775808) since when you do abs() of that
529
+ ** number of you get the same value back again. To do this
530
+ ** in a way that is testable, mask the sign bit off of negative
531
+ ** values, resulting in a positive value. Then take the
532
+ ** 2s complement of that positive value. The end result can
533
+ ** therefore be no less than -9223372036854775807.
534
+ */
535
+ r = -(r ^ (((sqlite3_int64)1) << 63));
536
+ }
537
+ sqlite3_result_int64(context, r);
538
+ }
539
+
540
+ /*
541
+ ** Implementation of randomblob(N). Return a random blob
542
+ ** that is N bytes long.
543
+ */
544
+ static void randomBlob(
545
+ sqlite3_context context,
546
+ int argc,
547
+ sqlite3_value[] argv
548
+ )
549
+ {
550
+ int n;
551
+ char[] p;
552
+ Debug.Assert(argc == 1);
553
+ UNUSED_PARAMETER(argc);
554
+ n = sqlite3_value_int(argv[0]);
555
+ if (n < 1)
556
+ {
557
+ n = 1;
558
+ }
559
+ p = new char[n]; //contextMalloc( context, n );
560
+ if (p != null)
561
+ {
562
+ i64 _p = 0;
563
+ for (int i = 0; i < n; i++)
564
+ {
565
+ sqlite3_randomness(sizeof(u8), ref _p);
566
+ p[i] = (char)(_p & 0x7F);
567
+ }
568
+ sqlite3_result_blob(context, new string(p), n, null);//sqlite3_free );
569
+ }
570
+ }
571
+
572
+ /*
573
+ ** Implementation of the last_insert_rowid() SQL function. The return
574
+ ** value is the same as the sqlite3_last_insert_rowid() API function.
575
+ */
576
+ static void last_insert_rowid(
577
+ sqlite3_context context,
578
+ int NotUsed,
579
+ sqlite3_value[] NotUsed2
580
+ )
581
+ {
582
+ sqlite3 db = sqlite3_context_db_handle(context);
583
+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
584
+ /* IMP: R-51513-12026 The last_insert_rowid() SQL function is a
585
+ ** wrapper around the sqlite3_last_insert_rowid() C/C++ interface
586
+ ** function. */
587
+ sqlite3_result_int64(context, sqlite3_last_insert_rowid(db));
588
+ }
589
+
590
+ /*
591
+ ** Implementation of the changes() SQL function.
592
+ **
593
+ ** IMP: R-62073-11209 The changes() SQL function is a wrapper
594
+ ** around the sqlite3_changes() C/C++ function and hence follows the same
595
+ ** rules for counting changes.
596
+ */
597
+ static void changes(
598
+ sqlite3_context context,
599
+ int NotUsed,
600
+ sqlite3_value[] NotUsed2
601
+ )
602
+ {
603
+ sqlite3 db = sqlite3_context_db_handle(context);
604
+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
605
+ sqlite3_result_int(context, sqlite3_changes(db));
606
+ }
607
+
608
+ /*
609
+ ** Implementation of the total_changes() SQL function. The return value is
610
+ ** the same as the sqlite3_total_changes() API function.
611
+ */
612
+ static void total_changes(
613
+ sqlite3_context context,
614
+ int NotUsed,
615
+ sqlite3_value[] NotUsed2
616
+ )
617
+ {
618
+ sqlite3 db = (sqlite3)sqlite3_context_db_handle(context);
619
+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
620
+ /* IMP: R-52756-41993 This function is a wrapper around the
621
+ ** sqlite3_total_changes() C/C++ interface. */
622
+ sqlite3_result_int(context, sqlite3_total_changes(db));
623
+ }
624
+
625
+ /*
626
+ ** A structure defining how to do GLOB-style comparisons.
627
+ */
628
+ struct compareInfo
629
+ {
630
+ public char matchAll;
631
+ public char matchOne;
632
+ public char matchSet;
633
+ public bool noCase;
634
+ public compareInfo(char matchAll, char matchOne, char matchSet, bool noCase)
635
+ {
636
+ this.matchAll = matchAll;
637
+ this.matchOne = matchOne;
638
+ this.matchSet = matchSet;
639
+ this.noCase = noCase;
640
+ }
641
+ };
642
+
643
+ /*
644
+ ** For LIKE and GLOB matching on EBCDIC machines, assume that every
645
+ ** character is exactly one byte in size. Also, all characters are
646
+ ** able to participate in upper-case-to-lower-case mappings in EBCDIC
647
+ ** whereas only characters less than 0x80 do in ASCII.
648
+ */
649
+ #if (SQLITE_EBCDIC)
650
+ //# define sqlite3Utf8Read(A,C) (*(A++))
651
+ //# define GlogUpperToLower(A) A = sqlite3UpperToLower[A]
652
+ #else
653
+ //# define GlogUpperToLower(A) if( A<0x80 ){ A = sqlite3UpperToLower[A]; }
654
+ #endif
655
+
656
+ static compareInfo globInfo = new compareInfo('*', '?', '[', false);
657
+ /* The correct SQL-92 behavior is for the LIKE operator to ignore
658
+ ** case. Thus 'a' LIKE 'A' would be true. */
659
+ static compareInfo likeInfoNorm = new compareInfo('%', '_', '\0', true);
660
+ /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator
661
+ ** is case sensitive causing 'a' LIKE 'A' to be false */
662
+ static compareInfo likeInfoAlt = new compareInfo('%', '_', '\0', false);
663
+
664
+ /*
665
+ ** Compare two UTF-8 strings for equality where the first string can
666
+ ** potentially be a "glob" expression. Return true (1) if they
667
+ ** are the same and false (0) if they are different.
668
+ **
669
+ ** Globbing rules:
670
+ **
671
+ ** '*' Matches any sequence of zero or more characters.
672
+ **
673
+ ** '?' Matches exactly one character.
674
+ **
675
+ ** [...] Matches one character from the enclosed list of
676
+ ** characters.
677
+ **
678
+ ** [^...] Matches one character not in the enclosed list.
679
+ **
680
+ ** With the [...] and [^...] matching, a ']' character can be included
681
+ ** in the list by making it the first character after '[' or '^'. A
682
+ ** range of characters can be specified using '-'. Example:
683
+ ** "[a-z]" matches any single lower-case letter. To match a '-', make
684
+ ** it the last character in the list.
685
+ **
686
+ ** This routine is usually quick, but can be N**2 in the worst case.
687
+ **
688
+ ** Hints: to match '*' or '?', put them in "[]". Like this:
689
+ **
690
+ ** abc[*]xyz Matches "abc*xyz" only
691
+ */
692
+ static bool patternCompare(
693
+ string zPattern, /* The glob pattern */
694
+ string zString, /* The string to compare against the glob */
695
+ compareInfo pInfo, /* Information about how to do the compare */
696
+ int esc /* The escape character */
697
+ )
698
+ {
699
+ int c, c2;
700
+ int invert;
701
+ int seen;
702
+ int matchOne = (int)pInfo.matchOne;
703
+ int matchAll = (int)pInfo.matchAll;
704
+ int matchSet = (int)pInfo.matchSet;
705
+ bool noCase = pInfo.noCase;
706
+ bool prevEscape = false; /* True if the previous character was 'escape' */
707
+ string inPattern = zPattern; //Entered Pattern
708
+
709
+ while ((c = sqlite3Utf8Read(zPattern, ref zPattern)) != 0)
710
+ {
711
+ if (!prevEscape && c == matchAll)
712
+ {
713
+ while ((c = sqlite3Utf8Read(zPattern, ref zPattern)) == matchAll
714
+ || c == matchOne)
715
+ {
716
+ if (c == matchOne && sqlite3Utf8Read(zString, ref zString) == 0)
717
+ {
718
+ return false;
719
+ }
720
+ }
721
+ if (c == 0)
722
+ {
723
+ return true;
724
+ }
725
+ else if (c == esc)
726
+ {
727
+ c = sqlite3Utf8Read(zPattern, ref zPattern);
728
+ if (c == 0)
729
+ {
730
+ return false;
731
+ }
732
+ }
733
+ else if (c == matchSet)
734
+ {
735
+ Debug.Assert(esc == 0); /* This is GLOB, not LIKE */
736
+ Debug.Assert(matchSet < 0x80); /* '[' is a single-byte character */
737
+ int len = 0;
738
+ while (len < zString.Length && patternCompare(inPattern.Substring(inPattern.Length - zPattern.Length - 1), zString.Substring(len), pInfo, esc) == false)
739
+ {
740
+ SQLITE_SKIP_UTF8(zString, ref len);
741
+ }
742
+ return len < zString.Length;
743
+ }
744
+ while ((c2 = sqlite3Utf8Read(zString, ref zString)) != 0)
745
+ {
746
+ if (noCase)
747
+ {
748
+ if (c2 < 0x80) c2 = sqlite3UpperToLower[c2]; //GlogUpperToLower(c2);
749
+ if (c < 0x80) c = sqlite3UpperToLower[c]; //GlogUpperToLower(c);
750
+ while (c2 != 0 && c2 != c)
751
+ {
752
+ c2 = sqlite3Utf8Read(zString, ref zString);
753
+ if (c2 < 0x80) c2 = sqlite3UpperToLower[c2]; //GlogUpperToLower(c2);
754
+ }
755
+ }
756
+ else
757
+ {
758
+ while (c2 != 0 && c2 != c)
759
+ {
760
+ c2 = sqlite3Utf8Read(zString, ref zString);
761
+ }
762
+ }
763
+ if (c2 == 0) return false;
764
+ if (patternCompare(zPattern, zString, pInfo, esc)) return true;
765
+ }
766
+ return false;
767
+ }
768
+ else if (!prevEscape && c == matchOne)
769
+ {
770
+ if (sqlite3Utf8Read(zString, ref zString) == 0)
771
+ {
772
+ return false;
773
+ }
774
+ }
775
+ else if (c == matchSet)
776
+ {
777
+ int prior_c = 0;
778
+ Debug.Assert(esc == 0); /* This only occurs for GLOB, not LIKE */
779
+ seen = 0;
780
+ invert = 0;
781
+ c = sqlite3Utf8Read(zString, ref zString);
782
+ if (c == 0) return false;
783
+ c2 = sqlite3Utf8Read(zPattern, ref zPattern);
784
+ if (c2 == '^')
785
+ {
786
+ invert = 1;
787
+ c2 = sqlite3Utf8Read(zPattern, ref zPattern);
788
+ }
789
+ if (c2 == ']')
790
+ {
791
+ if (c == ']') seen = 1;
792
+ c2 = sqlite3Utf8Read(zPattern, ref zPattern);
793
+ }
794
+ while (c2 != 0 && c2 != ']')
795
+ {
796
+ if (c2 == '-' && zPattern[0] != ']' && zPattern[0] != 0 && prior_c > 0)
797
+ {
798
+ c2 = sqlite3Utf8Read(zPattern, ref zPattern);
799
+ if (c >= prior_c && c <= c2) seen = 1;
800
+ prior_c = 0;
801
+ }
802
+ else
803
+ {
804
+ if (c == c2)
805
+ {
806
+ seen = 1;
807
+ }
808
+ prior_c = c2;
809
+ }
810
+ c2 = sqlite3Utf8Read(zPattern, ref zPattern);
811
+ }
812
+ if (c2 == 0 || (seen ^ invert) == 0)
813
+ {
814
+ return false;
815
+ }
816
+ }
817
+ else if (esc == c && !prevEscape)
818
+ {
819
+ prevEscape = true;
820
+ }
821
+ else
822
+ {
823
+ c2 = sqlite3Utf8Read(zString, ref zString);
824
+ if (noCase)
825
+ {
826
+ if (c < 0x80) c = sqlite3UpperToLower[c]; //GlogUpperToLower(c);
827
+ if (c2 < 0x80) c2 = sqlite3UpperToLower[c2]; //GlogUpperToLower(c2);
828
+ }
829
+ if (c != c2)
830
+ {
831
+ return false;
832
+ }
833
+ prevEscape = false;
834
+ }
835
+ }
836
+ return zString.Length == 0;
837
+ }
838
+
839
+ /*
840
+ ** Count the number of times that the LIKE operator (or GLOB which is
841
+ ** just a variation of LIKE) gets called. This is used for testing
842
+ ** only.
843
+ */
844
+ #if SQLITE_TEST
845
+ //static int sqlite3_like_count = 0;
846
+ #endif
847
+
848
+
849
+ /*
850
+ ** Implementation of the like() SQL function. This function implements
851
+ ** the build-in LIKE operator. The first argument to the function is the
852
+ ** pattern and the second argument is the string. So, the SQL statements:
853
+ **
854
+ ** A LIKE B
855
+ **
856
+ ** is implemented as like(B,A).
857
+ **
858
+ ** This same function (with a different compareInfo structure) computes
859
+ ** the GLOB operator.
860
+ */
861
+ static void likeFunc(
862
+ sqlite3_context context,
863
+ int argc,
864
+ sqlite3_value[] argv
865
+ )
866
+ {
867
+ string zA, zB;
868
+ int escape = 0;
869
+ int nPat;
870
+ sqlite3 db = sqlite3_context_db_handle(context);
871
+
872
+ zB = sqlite3_value_text(argv[0]);
873
+ zA = sqlite3_value_text(argv[1]);
874
+
875
+ /* Limit the length of the LIKE or GLOB pattern to avoid problems
876
+ ** of deep recursion and N*N behavior in patternCompare().
877
+ */
878
+ nPat = sqlite3_value_bytes(argv[0]);
879
+ testcase(nPat == db.aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]);
880
+ testcase(nPat == db.aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] + 1);
881
+ if (nPat > db.aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH])
882
+ {
883
+ sqlite3_result_error(context, "LIKE or GLOB pattern too complex", -1);
884
+ return;
885
+ }
886
+ //Debug.Assert( zB == sqlite3_value_text( argv[0] ) ); /* Encoding did not change */
887
+
888
+ if (argc == 3)
889
+ {
890
+ /* The escape character string must consist of a single UTF-8 character.
891
+ ** Otherwise, return an error.
892
+ */
893
+ string zEsc = sqlite3_value_text(argv[2]);
894
+ if (zEsc == null) return;
895
+ if (sqlite3Utf8CharLen(zEsc, -1) != 1)
896
+ {
897
+ sqlite3_result_error(context,
898
+ "ESCAPE expression must be a single character", -1);
899
+ return;
900
+ }
901
+ escape = sqlite3Utf8Read(zEsc, ref zEsc);
902
+ }
903
+ if (zA != null && zB != null)
904
+ {
905
+ compareInfo pInfo = (compareInfo)sqlite3_user_data(context);
906
+ #if SQLITE_TEST
907
+ sqlite3_like_count.iValue++;
908
+ #endif
909
+ sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape) ? 1 : 0);
910
+ }
911
+ }
912
+
913
+ /*
914
+ ** Implementation of the NULLIF(x,y) function. The result is the first
915
+ ** argument if the arguments are different. The result is NULL if the
916
+ ** arguments are equal to each other.
917
+ */
918
+ static void nullifFunc(
919
+ sqlite3_context context,
920
+ int NotUsed,
921
+ sqlite3_value[] argv
922
+ )
923
+ {
924
+ CollSeq pColl = sqlite3GetFuncCollSeq(context);
925
+ UNUSED_PARAMETER(NotUsed);
926
+ if (sqlite3MemCompare(argv[0], argv[1], pColl) != 0)
927
+ {
928
+ sqlite3_result_value(context, argv[0]);
929
+ }
930
+ }
931
+
932
+ /*
933
+ ** Implementation of the sqlite_version() function. The result is the version
934
+ ** of the SQLite library that is running.
935
+ */
936
+ static void versionFunc(
937
+ sqlite3_context context,
938
+ int NotUsed,
939
+ sqlite3_value[] NotUsed2
940
+ )
941
+ {
942
+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
943
+ /* IMP: R-48699-48617 This function is an SQL wrapper around the
944
+ ** sqlite3_libversion() C-interface. */
945
+ sqlite3_result_text(context, sqlite3_libversion(), -1, SQLITE_STATIC);
946
+ }
947
+
948
+ /*
949
+ ** Implementation of the sqlite_source_id() function. The result is a string
950
+ ** that identifies the particular version of the source code used to build
951
+ ** SQLite.
952
+ */
953
+ static void sourceidFunc(
954
+ sqlite3_context context,
955
+ int NotUsed,
956
+ sqlite3_value[] NotUsed2
957
+ )
958
+ {
959
+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
960
+ /* IMP: R-24470-31136 This function is an SQL wrapper around the
961
+ ** sqlite3_sourceid() C interface. */
962
+ sqlite3_result_text(context, sqlite3_sourceid(), -1, SQLITE_STATIC);
963
+ }
964
+
965
+ /*
966
+ ** Implementation of the sqlite_compileoption_used() function.
967
+ ** The result is an integer that identifies if the compiler option
968
+ ** was used to build SQLite.
969
+ */
970
+ #if !SQLITE_OMIT_COMPILEOPTION_DIAGS
971
+ static void compileoptionusedFunc(
972
+ sqlite3_context context,
973
+ int argc,
974
+ sqlite3_value[] argv
975
+ )
976
+ {
977
+ string zOptName;
978
+ Debug.Assert(argc == 1);
979
+ UNUSED_PARAMETER(argc);
980
+ /* IMP: R-xxxx This function is an SQL wrapper around the
981
+ ** sqlite3_compileoption_used() C interface. */
982
+ if ((zOptName = sqlite3_value_text(argv[0])) != null)
983
+ {
984
+ sqlite3_result_int(context, sqlite3_compileoption_used(zOptName));
985
+ }
986
+ }
987
+ #endif //* SQLITE_OMIT_COMPILEOPTION_DIAGS */
988
+
989
+
990
+ /*
991
+ ** Implementation of the sqlite_compileoption_get() function.
992
+ ** The result is a string that identifies the compiler options
993
+ ** used to build SQLite.
994
+ */
995
+ #if !SQLITE_OMIT_COMPILEOPTION_DIAGS
996
+ static void compileoptiongetFunc(
997
+ sqlite3_context context,
998
+ int argc,
999
+ sqlite3_value[] argv
1000
+ )
1001
+ {
1002
+ int n;
1003
+ Debug.Assert(argc == 1);
1004
+ UNUSED_PARAMETER(argc);
1005
+ /* IMP: R-xxxx This function is an SQL wrapper around the
1006
+ ** sqlite3_compileoption_get() C interface. */
1007
+ n = sqlite3_value_int(argv[0]);
1008
+ sqlite3_result_text(context, sqlite3_compileoption_get(n), -1, SQLITE_STATIC);
1009
+ }
1010
+ #endif //* SQLITE_OMIT_COMPILEOPTION_DIAGS */
1011
+
1012
+ /* Array for converting from half-bytes (nybbles) into ASCII hex
1013
+ ** digits. */
1014
+ static char[] hexdigits = new char[] {
1015
+ '0', '1', '2', '3', '4', '5', '6', '7',
1016
+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
1017
+ };
1018
+
1019
+ /*
1020
+ ** EXPERIMENTAL - This is not an official function. The interface may
1021
+ ** change. This function may disappear. Do not write code that depends
1022
+ ** on this function.
1023
+ **
1024
+ ** Implementation of the QUOTE() function. This function takes a single
1025
+ ** argument. If the argument is numeric, the return value is the same as
1026
+ ** the argument. If the argument is NULL, the return value is the string
1027
+ ** "NULL". Otherwise, the argument is enclosed in single quotes with
1028
+ ** single-quote escapes.
1029
+ */
1030
+ static void quoteFunc(
1031
+ sqlite3_context context,
1032
+ int argc,
1033
+ sqlite3_value[] argv
1034
+ )
1035
+ {
1036
+ Debug.Assert(argc == 1);
1037
+ UNUSED_PARAMETER(argc);
1038
+
1039
+ switch (sqlite3_value_type(argv[0]))
1040
+ {
1041
+ case SQLITE_INTEGER:
1042
+ case SQLITE_FLOAT:
1043
+ {
1044
+ sqlite3_result_value(context, argv[0]);
1045
+ break;
1046
+ }
1047
+ case SQLITE_BLOB:
1048
+ {
1049
+ StringBuilder zText;
1050
+ byte[] zBlob = sqlite3_value_blob(argv[0]);
1051
+ int nBlob = sqlite3_value_bytes(argv[0]);
1052
+ Debug.Assert(zBlob.Length == sqlite3_value_blob(argv[0]).Length); /* No encoding change */
1053
+ zText = new StringBuilder(2 * nBlob + 4);//(char*)contextMalloc(context, (2*(i64)nBlob)+4);
1054
+ zText.Append("X'");
1055
+ if (zText != null)
1056
+ {
1057
+ int i;
1058
+ for (i = 0; i < nBlob; i++)
1059
+ {
1060
+ zText.Append(hexdigits[(zBlob[i] >> 4) & 0x0F]);
1061
+ zText.Append(hexdigits[(zBlob[i]) & 0x0F]);
1062
+ }
1063
+ zText.Append("'");
1064
+ //zText[( nBlob * 2 ) + 2] = '\'';
1065
+ //zText[( nBlob * 2 ) + 3] = '\0';
1066
+ //zText[0] = 'X';
1067
+ //zText[1] = '\'';
1068
+ sqlite3_result_text(context, zText.ToString(), -1, SQLITE_TRANSIENT);
1069
+ //sqlite3_free( ref zText );
1070
+ }
1071
+ break;
1072
+ }
1073
+ case SQLITE_TEXT:
1074
+ {
1075
+ int i, j;
1076
+ int n;
1077
+ string zArg = sqlite3_value_text(argv[0]);
1078
+ StringBuilder z;
1079
+
1080
+ if (zArg == null || zArg.Length == 0) return;
1081
+ for (i = 0, n = 0; i < zArg.Length; i++) { if (zArg[i] == '\'') n++; }
1082
+ z = new StringBuilder(i + n + 3);// contextMalloc(context, ((i64)i)+((i64)n)+3);
1083
+ if (z != null)
1084
+ {
1085
+ z.Append('\'');
1086
+ for (i = 0, j = 1; i < zArg.Length && zArg[i] != 0; i++)
1087
+ {
1088
+ z.Append((char)zArg[i]); j++;
1089
+ if (zArg[i] == '\'')
1090
+ {
1091
+ z.Append('\''); j++;
1092
+ }
1093
+ }
1094
+ z.Append('\''); j++;
1095
+ //z[j] = '\0'; ;
1096
+ sqlite3_result_text(context, z.ToString(), j, null);//sqlite3_free );
1097
+ }
1098
+ break;
1099
+ }
1100
+ default:
1101
+ {
1102
+ Debug.Assert(sqlite3_value_type(argv[0]) == SQLITE_NULL);
1103
+ sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC);
1104
+ break;
1105
+ }
1106
+ }
1107
+ }
1108
+
1109
+ /*
1110
+ ** The hex() function. Interpret the argument as a blob. Return
1111
+ ** a hexadecimal rendering as text.
1112
+ */
1113
+ static void hexFunc(
1114
+ sqlite3_context context,
1115
+ int argc,
1116
+ sqlite3_value[] argv
1117
+ )
1118
+ {
1119
+ int i, n;
1120
+ byte[] pBlob;
1121
+ //string zHex, z;
1122
+ Debug.Assert(argc == 1);
1123
+ UNUSED_PARAMETER(argc);
1124
+ pBlob = sqlite3_value_blob(argv[0]);
1125
+ n = sqlite3_value_bytes(argv[0]);
1126
+ Debug.Assert(n == pBlob.Length); /* No encoding change */
1127
+ StringBuilder zHex = new StringBuilder(n * 2 + 1);
1128
+ // z = zHex = contextMalloc(context, ((i64)n)*2 + 1);
1129
+ if (zHex != null)
1130
+ {
1131
+ for (i = 0; i < n; i++)
1132
+ {//, pBlob++){
1133
+ byte c = pBlob[i];
1134
+ zHex.Append(hexdigits[(c >> 4) & 0xf]);
1135
+ zHex.Append(hexdigits[c & 0xf]);
1136
+ }
1137
+ sqlite3_result_text(context, zHex.ToString(), n * 2, null); //sqlite3_free );
1138
+ }
1139
+ }
1140
+
1141
+ /*
1142
+ ** The zeroblob(N) function returns a zero-filled blob of size N bytes.
1143
+ */
1144
+ static void zeroblobFunc(
1145
+ sqlite3_context context,
1146
+ int argc,
1147
+ sqlite3_value[] argv
1148
+ )
1149
+ {
1150
+ i64 n;
1151
+ sqlite3 db = sqlite3_context_db_handle(context);
1152
+ Debug.Assert(argc == 1);
1153
+ UNUSED_PARAMETER(argc);
1154
+ n = sqlite3_value_int64(argv[0]);
1155
+ testcase(n == db.aLimit[SQLITE_LIMIT_LENGTH]);
1156
+ testcase(n == db.aLimit[SQLITE_LIMIT_LENGTH] + 1);
1157
+ if (n > db.aLimit[SQLITE_LIMIT_LENGTH])
1158
+ {
1159
+ sqlite3_result_error_toobig(context);
1160
+ }
1161
+ else
1162
+ {
1163
+ sqlite3_result_zeroblob(context, (int)n);/* IMP: R-00293-64994 */
1164
+ }
1165
+ }
1166
+
1167
+ /*
1168
+ ** The replace() function. Three arguments are all strings: call
1169
+ ** them A, B, and C. The result is also a string which is derived
1170
+ ** from A by replacing every occurance of B with C. The match
1171
+ ** must be exact. Collating sequences are not used.
1172
+ */
1173
+ static void replaceFunc(
1174
+ sqlite3_context context,
1175
+ int argc,
1176
+ sqlite3_value[] argv
1177
+ )
1178
+ {
1179
+ string zStr; /* The input string A */
1180
+ string zPattern; /* The pattern string B */
1181
+ string zRep; /* The replacement string C */
1182
+ string zOut; /* The output */
1183
+ int nStr; /* Size of zStr */
1184
+ int nPattern; /* Size of zPattern */
1185
+ int nRep; /* Size of zRep */
1186
+ int nOut; /* Maximum size of zOut */
1187
+ //int loopLimit; /* Last zStr[] that might match zPattern[] */
1188
+ int i, j; /* Loop counters */
1189
+
1190
+ Debug.Assert(argc == 3);
1191
+ UNUSED_PARAMETER(argc);
1192
+ zStr = sqlite3_value_text(argv[0]);
1193
+ if (zStr == null) return;
1194
+ nStr = sqlite3_value_bytes(argv[0]);
1195
+ Debug.Assert(zStr == sqlite3_value_text(argv[0])); /* No encoding change */
1196
+ zPattern = sqlite3_value_text(argv[1]);
1197
+ if (zPattern == null)
1198
+ {
1199
+ Debug.Assert(sqlite3_value_type(argv[1]) == SQLITE_NULL
1200
+ //|| sqlite3_context_db_handle( context ).mallocFailed != 0
1201
+ );
1202
+ return;
1203
+ }
1204
+ if (zPattern == "")
1205
+ {
1206
+ Debug.Assert(sqlite3_value_type(argv[1]) != SQLITE_NULL);
1207
+ sqlite3_result_value(context, argv[0]);
1208
+ return;
1209
+ }
1210
+ nPattern = sqlite3_value_bytes(argv[1]);
1211
+ Debug.Assert(zPattern == sqlite3_value_text(argv[1])); /* No encoding change */
1212
+ zRep = sqlite3_value_text(argv[2]);
1213
+ if (zRep == null) return;
1214
+ nRep = sqlite3_value_bytes(argv[2]);
1215
+ Debug.Assert(zRep == sqlite3_value_text(argv[2]));
1216
+ nOut = nStr + 1;
1217
+ Debug.Assert(nOut < SQLITE_MAX_LENGTH);
1218
+ //zOut = contextMalloc(context, (i64)nOut);
1219
+ //if( zOut==0 ){
1220
+ // return;
1221
+ //}
1222
+ //loopLimit = nStr - nPattern;
1223
+ //for(i=j=0; i<=loopLimit; i++){
1224
+ // if( zStr[i]!=zPattern[0] || memcmp(&zStr[i], zPattern, nPattern) ){
1225
+ // zOut[j++] = zStr[i];
1226
+ // }else{
1227
+ // u8 *zOld;
1228
+ // sqlite3 db = sqlite3_context_db_handle( context );
1229
+ // nOut += nRep - nPattern;
1230
+ //testcase( nOut-1==db->aLimit[SQLITE_LIMIT_LENGTH] );
1231
+ //testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
1232
+ //if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
1233
+ // sqlite3_result_error_toobig(context);
1234
+ // sqlite3DbFree(db,ref zOut);
1235
+ // return;
1236
+ // }
1237
+ // zOld = zOut;
1238
+ // zOut = sqlite3_realloc(zOut, (int)nOut);
1239
+ // if( zOut==0 ){
1240
+ // sqlite3_result_error_nomem(context);
1241
+ // sqlite3DbFree(db,ref zOld);
1242
+ // return;
1243
+ // }
1244
+ // memcpy(&zOut[j], zRep, nRep);
1245
+ // j += nRep;
1246
+ // i += nPattern-1;
1247
+ // }
1248
+ //}
1249
+ //Debug.Assert( j+nStr-i+1==nOut );
1250
+ //memcpy(&zOut[j], zStr[i], nStr-i);
1251
+ //j += nStr - i;
1252
+ //Debug.Assert( j<=nOut );
1253
+ //zOut[j] = 0;
1254
+ zOut = zStr.Replace(zPattern, zRep);
1255
+ j = zOut.Length;
1256
+ sqlite3_result_text(context, zOut, j, null);//sqlite3_free );
1257
+ }
1258
+
1259
+ /*
1260
+ ** Implementation of the TRIM(), LTRIM(), and RTRIM() functions.
1261
+ ** The userdata is 0x1 for left trim, 0x2 for right trim, 0x3 for both.
1262
+ */
1263
+ static void trimFunc(
1264
+ sqlite3_context context,
1265
+ int argc,
1266
+ sqlite3_value[] argv
1267
+ )
1268
+ {
1269
+ string zIn; /* Input string */
1270
+ string zCharSet; /* Set of characters to trim */
1271
+ int nIn; /* Number of bytes in input */
1272
+ int izIn = 0; /* C# string pointer */
1273
+ int flags; /* 1: trimleft 2: trimright 3: trim */
1274
+ int i; /* Loop counter */
1275
+ int[] aLen = null; /* Length of each character in zCharSet */
1276
+ byte[][] azChar = null; /* Individual characters in zCharSet */
1277
+ int nChar = 0; /* Number of characters in zCharSet */
1278
+ byte[] zBytes = null;
1279
+ byte[] zBlob = null;
1280
+
1281
+ if (sqlite3_value_type(argv[0]) == SQLITE_NULL)
1282
+ {
1283
+ return;
1284
+ }
1285
+ zIn = sqlite3_value_text(argv[0]);
1286
+ if (zIn == null) return;
1287
+ nIn = sqlite3_value_bytes(argv[0]);
1288
+ zBlob = sqlite3_value_blob(argv[0]);
1289
+ //Debug.Assert( zIn == sqlite3_value_text( argv[0] ) );
1290
+ if (argc == 1)
1291
+ {
1292
+ int[] lenOne = new int[] { 1 };
1293
+ byte[] azOne = new byte[] { (u8)' ' };//static unsigned char * const azOne[] = { (u8*)" " };
1294
+ nChar = 1;
1295
+ aLen = lenOne;
1296
+ azChar = new byte[1][];
1297
+ azChar[0] = azOne;
1298
+ zCharSet = null;
1299
+ }
1300
+ else if ((zCharSet = sqlite3_value_text(argv[1])) == null)
1301
+ {
1302
+ return;
1303
+ }
1304
+ else
1305
+ {
1306
+ zBytes = sqlite3_value_blob(argv[1]);
1307
+ int iz = 0;
1308
+ for (nChar = 0; iz < zBytes.Length; nChar++)
1309
+ {
1310
+ SQLITE_SKIP_UTF8(zBytes, ref iz);
1311
+ }
1312
+ if (nChar > 0)
1313
+ {
1314
+ azChar = new byte[nChar][];//contextMalloc(context, ((i64)nChar)*(sizeof(char*)+1));
1315
+ if (azChar == null)
1316
+ {
1317
+ return;
1318
+ }
1319
+ aLen = new int[nChar];
1320
+
1321
+ int iz0 = 0;
1322
+ int iz1 = 0;
1323
+ for (int ii = 0; ii < nChar; ii++)
1324
+ {
1325
+ SQLITE_SKIP_UTF8(zBytes, ref iz1);
1326
+ aLen[ii] = iz1 - iz0;
1327
+ azChar[ii] = new byte[aLen[ii]];
1328
+ Buffer.BlockCopy(zBytes, iz0, azChar[ii], 0, azChar[ii].Length);
1329
+ iz0 = iz1;
1330
+ }
1331
+ }
1332
+ }
1333
+ if (nChar > 0)
1334
+ {
1335
+ flags = (int)sqlite3_user_data(context); // flags = SQLITE_PTR_TO_INT(sqlite3_user_data(context));
1336
+ if ((flags & 1) != 0)
1337
+ {
1338
+ while (nIn > 0)
1339
+ {
1340
+ int len = 0;
1341
+ for (i = 0; i < nChar; i++)
1342
+ {
1343
+ len = aLen[i];
1344
+ if (len <= nIn && memcmp(zBlob, izIn, azChar[i], len) == 0) break;
1345
+ }
1346
+ if (i >= nChar) break;
1347
+ izIn += len;
1348
+ nIn -= len;
1349
+ }
1350
+ }
1351
+ if ((flags & 2) != 0)
1352
+ {
1353
+ while (nIn > 0)
1354
+ {
1355
+ int len = 0;
1356
+ for (i = 0; i < nChar; i++)
1357
+ {
1358
+ len = aLen[i];
1359
+ if (len <= nIn && memcmp(zBlob, izIn + nIn - len, azChar[i], len) == 0) break;
1360
+ }
1361
+ if (i >= nChar) break;
1362
+ nIn -= len;
1363
+ }
1364
+ }
1365
+ if (zCharSet != null)
1366
+ {
1367
+ //sqlite3_free( ref azChar );
1368
+ }
1369
+ }
1370
+ StringBuilder sb = new StringBuilder(nIn);
1371
+ for (i = 0; i < nIn; i++) sb.Append((char)zBlob[izIn + i]);
1372
+ sqlite3_result_text(context, sb.ToString(), nIn, SQLITE_TRANSIENT);
1373
+ }
1374
+
1375
+ /* IMP: R-25361-16150 This function is omitted from SQLite by default. It
1376
+ ** is only available if the SQLITE_SOUNDEX compile-time option is used
1377
+ ** when SQLite is built.
1378
+ */
1379
+ #if SQLITE_SOUNDEX
1380
+ /*
1381
+ ** Compute the soundex encoding of a word.
1382
+ **
1383
+ ** IMP: R-59782-00072 The soundex(X) function returns a string that is the
1384
+ ** soundex encoding of the string X.
1385
+ */
1386
+ static void soundexFunc(
1387
+ sqlite3_context context,
1388
+ int argc,
1389
+ sqlite3_value[] argv
1390
+ )
1391
+ {
1392
+ Debug.Assert(false); // TODO -- func_c
1393
+ char zResult[8];
1394
+ const u8 *zIn;
1395
+ int i, j;
1396
+ static const unsigned char iCode[] = {
1397
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1398
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1399
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1400
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1401
+ 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
1402
+ 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
1403
+ 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0,
1404
+ 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0,
1405
+ };
1406
+ Debug.Assert( argc==1 );
1407
+ zIn = (u8*)sqlite3_value_text(argv[0]);
1408
+ if( zIn==0 ) zIn = (u8*)"";
1409
+ for(i=0; zIn[i] && !sqlite3Isalpha(zIn[i]); i++){}
1410
+ if( zIn[i] ){
1411
+ u8 prevcode = iCode[zIn[i]&0x7f];
1412
+ zResult[0] = sqlite3Toupper(zIn[i]);
1413
+ for(j=1; j<4 && zIn[i]; i++){
1414
+ int code = iCode[zIn[i]&0x7f];
1415
+ if( code>0 ){
1416
+ if( code!=prevcode ){
1417
+ prevcode = code;
1418
+ zResult[j++] = code + '0';
1419
+ }
1420
+ }else{
1421
+ prevcode = 0;
1422
+ }
1423
+ }
1424
+ while( j<4 ){
1425
+ zResult[j++] = '0';
1426
+ }
1427
+ zResult[j] = 0;
1428
+ sqlite3_result_text(context, zResult, 4, SQLITE_TRANSIENT);
1429
+ }else{
1430
+ /* IMP: R-64894-50321 The string "?000" is returned if the argument
1431
+ ** is NULL or contains no ASCII alphabetic characters. */
1432
+ sqlite3_result_text(context, "?000", 4, SQLITE_STATIC);
1433
+ }
1434
+ }
1435
+ #endif //* SQLITE_SOUNDEX */
1436
+
1437
+ #if ! SQLITE_OMIT_LOAD_EXTENSION
1438
+ /*
1439
+ ** A function that loads a shared-library extension then returns NULL.
1440
+ */
1441
+ static void loadExt(
1442
+ sqlite3_context context,
1443
+ int argc,
1444
+ sqlite3_value[] argv
1445
+ )
1446
+ {
1447
+ string zFile = sqlite3_value_text(argv[0]);
1448
+ string zProc;
1449
+ sqlite3 db = (sqlite3)sqlite3_context_db_handle(context);
1450
+ string zErrMsg = "";
1451
+
1452
+ if (argc == 2)
1453
+ {
1454
+ zProc = sqlite3_value_text(argv[1]);
1455
+ }
1456
+ else
1457
+ {
1458
+ zProc = "";
1459
+ }
1460
+ if (zFile != null && sqlite3_load_extension(db, zFile, zProc, ref zErrMsg) != 0)
1461
+ {
1462
+ sqlite3_result_error(context, zErrMsg, -1);
1463
+ sqlite3DbFree(db, ref zErrMsg);
1464
+ }
1465
+ }
1466
+ #endif
1467
+
1468
+ /*
1469
+ ** An instance of the following structure holds the context of a
1470
+ ** sum() or avg() aggregate computation.
1471
+ */
1472
+ //typedef struct SumCtx SumCtx;
1473
+ public class SumCtx
1474
+ {
1475
+ public double rSum; /* Floating point sum */
1476
+ public i64 iSum; /* Integer sum */
1477
+ public i64 cnt; /* Number of elements summed */
1478
+ public int overflow; /* True if integer overflow seen */
1479
+ public bool approx; /* True if non-integer value was input to the sum */
1480
+ public Mem _M;
1481
+ public Mem Context
1482
+ {
1483
+ get { return _M; }
1484
+ set
1485
+ {
1486
+ _M = value;
1487
+ if (_M == null || _M.z == null)
1488
+ iSum = 0;
1489
+ else iSum = Convert.ToInt64(_M.z);
1490
+ }
1491
+ }
1492
+ };
1493
+
1494
+ /*
1495
+ ** Routines used to compute the sum, average, and total.
1496
+ **
1497
+ ** The SUM() function follows the (broken) SQL standard which means
1498
+ ** that it returns NULL if it sums over no inputs. TOTAL returns
1499
+ ** 0.0 in that case. In addition, TOTAL always returns a float where
1500
+ ** SUM might return an integer if it never encounters a floating point
1501
+ ** value. TOTAL never fails, but SUM might through an exception if
1502
+ ** it overflows an integer.
1503
+ */
1504
+ static void sumStep(
1505
+ sqlite3_context context,
1506
+ int argc,
1507
+ sqlite3_value[] argv
1508
+ )
1509
+ {
1510
+ SumCtx p;
1511
+
1512
+ int type;
1513
+ Debug.Assert(argc == 1);
1514
+ UNUSED_PARAMETER(argc);
1515
+ Mem pMem = sqlite3_aggregate_context(context, 1);//sizeof(*p));
1516
+ if (pMem._SumCtx == null) pMem._SumCtx = new SumCtx();
1517
+ p = pMem._SumCtx;
1518
+ if (p.Context == null) p.Context = pMem;
1519
+ type = sqlite3_value_numeric_type(argv[0]);
1520
+ if (p != null && type != SQLITE_NULL)
1521
+ {
1522
+ p.cnt++;
1523
+ if (type == SQLITE_INTEGER)
1524
+ {
1525
+ i64 v = sqlite3_value_int64(argv[0]);
1526
+ p.rSum += v;
1527
+ if (!(p.approx | p.overflow != 0))
1528
+ {
1529
+ i64 iNewSum = p.iSum + v;
1530
+ int s1 = (int)(p.iSum >> (sizeof(i64) * 8 - 1));
1531
+ int s2 = (int)(v >> (sizeof(i64) * 8 - 1));
1532
+ int s3 = (int)(iNewSum >> (sizeof(i64) * 8 - 1));
1533
+ p.overflow = ((s1 & s2 & ~s3) | (~s1 & ~s2 & s3)) != 0 ? 1 : 0;
1534
+ p.iSum = iNewSum;
1535
+ }
1536
+ }
1537
+ else
1538
+ {
1539
+ p.rSum += sqlite3_value_double(argv[0]);
1540
+ p.approx = true;
1541
+ }
1542
+ }
1543
+ }
1544
+ static void sumFinalize(sqlite3_context context)
1545
+ {
1546
+ SumCtx p = null;
1547
+ Mem pMem = sqlite3_aggregate_context(context, 0);
1548
+ if (pMem != null) p = pMem._SumCtx;
1549
+ if (p != null && p.cnt > 0)
1550
+ {
1551
+ if (p.overflow != 0)
1552
+ {
1553
+ sqlite3_result_error(context, "integer overflow", -1);
1554
+ }
1555
+ else if (p.approx)
1556
+ {
1557
+ sqlite3_result_double(context, p.rSum);
1558
+ }
1559
+ else
1560
+ {
1561
+ sqlite3_result_int64(context, p.iSum);
1562
+ }
1563
+ p.cnt = 0; // Reset for C#
1564
+ }
1565
+ }
1566
+
1567
+ static void avgFinalize(sqlite3_context context)
1568
+ {
1569
+ SumCtx p = null;
1570
+ Mem pMem = sqlite3_aggregate_context(context, 0);
1571
+ if (pMem != null) p = pMem._SumCtx;
1572
+ if (p != null && p.cnt > 0)
1573
+ {
1574
+ sqlite3_result_double(context, p.rSum / (double)p.cnt);
1575
+ }
1576
+ }
1577
+
1578
+ static void totalFinalize(sqlite3_context context)
1579
+ {
1580
+ SumCtx p = null;
1581
+ Mem pMem = sqlite3_aggregate_context(context, 0);
1582
+ if (pMem != null) p = pMem._SumCtx;
1583
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
1584
+ sqlite3_result_double(context, p != null ? p.rSum : (double)0);
1585
+ }
1586
+
1587
+ /*
1588
+ ** The following structure keeps track of state information for the
1589
+ ** count() aggregate function.
1590
+ */
1591
+ //typedef struct CountCtx CountCtx;
1592
+ public class CountCtx
1593
+ {
1594
+ i64 _n;
1595
+ Mem _M;
1596
+ public Mem Context
1597
+ {
1598
+ get { return _M; }
1599
+ set
1600
+ {
1601
+ _M = value;
1602
+ if (_M == null || _M.z == null)
1603
+ _n = 0;
1604
+ else _n = Convert.ToInt64(_M.z);
1605
+ }
1606
+ }
1607
+ public i64 n
1608
+ {
1609
+ get { return _n; }
1610
+ set
1611
+ {
1612
+ _n = value;
1613
+ if (_M != null) _M.z = _n.ToString();
1614
+ }
1615
+ }
1616
+ }
1617
+
1618
+ /*
1619
+ ** Routines to implement the count() aggregate function.
1620
+ */
1621
+ static void countStep(
1622
+ sqlite3_context context,
1623
+ int argc,
1624
+ sqlite3_value[] argv
1625
+ )
1626
+ {
1627
+ CountCtx p = new CountCtx();
1628
+ p.Context = sqlite3_aggregate_context(context, 1);//sizeof(*p));
1629
+ if ((argc == 0 || SQLITE_NULL != sqlite3_value_type(argv[0])) && p.Context != null)
1630
+ {
1631
+ p.n++;
1632
+ }
1633
+ #if !SQLITE_OMIT_DEPRECATED
1634
+ /* The sqlite3_aggregate_count() function is deprecated. But just to make
1635
+ ** sure it still operates correctly, verify that its count agrees with our
1636
+ ** internal count when using count(*) and when the total count can be
1637
+ ** expressed as a 32-bit integer. */
1638
+ Debug.Assert( argc == 1 || p == null || p.n > 0x7fffffff
1639
+ || p.n == sqlite3_aggregate_count( context ) );
1640
+ #endif
1641
+ }
1642
+
1643
+ static void countFinalize(sqlite3_context context)
1644
+ {
1645
+ CountCtx p = new CountCtx();
1646
+ p.Context = sqlite3_aggregate_context(context, 0);
1647
+ sqlite3_result_int64(context, p != null ? p.n : 0);
1648
+ }
1649
+
1650
+ /*
1651
+ ** Routines to implement min() and max() aggregate functions.
1652
+ */
1653
+ static void minmaxStep(
1654
+ sqlite3_context context,
1655
+ int NotUsed,
1656
+ sqlite3_value[] argv
1657
+ )
1658
+ {
1659
+ Mem pArg = (Mem)argv[0];
1660
+ Mem pBest;
1661
+ UNUSED_PARAMETER(NotUsed);
1662
+
1663
+ if (sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
1664
+ pBest = (Mem)sqlite3_aggregate_context(context, 1);//sizeof(*pBest));
1665
+ //if ( pBest == null ) return;
1666
+
1667
+ if (pBest.flags != 0)
1668
+ {
1669
+ bool max;
1670
+ int cmp;
1671
+ CollSeq pColl = sqlite3GetFuncCollSeq(context);
1672
+ /* This step function is used for both the min() and max() aggregates,
1673
+ ** the only difference between the two being that the sense of the
1674
+ ** comparison is inverted. For the max() aggregate, the
1675
+ ** sqlite3_context_db_handle() function returns (void *)-1. For min() it
1676
+ ** returns (void *)db, where db is the sqlite3* database pointer.
1677
+ ** Therefore the next statement sets variable 'max' to 1 for the max()
1678
+ ** aggregate, or 0 for min().
1679
+ */
1680
+ max = sqlite3_context_db_handle(context) != null && (int)sqlite3_user_data(context) != 0;
1681
+ cmp = sqlite3MemCompare(pBest, pArg, pColl);
1682
+ if ((max && cmp < 0) || (!max && cmp > 0))
1683
+ {
1684
+ sqlite3VdbeMemCopy(pBest, pArg);
1685
+ }
1686
+ }
1687
+ else
1688
+ {
1689
+ sqlite3VdbeMemCopy(pBest, pArg);
1690
+ }
1691
+ }
1692
+
1693
+ static void minMaxFinalize(sqlite3_context context)
1694
+ {
1695
+ sqlite3_value pRes;
1696
+ pRes = (sqlite3_value)sqlite3_aggregate_context(context, 0);
1697
+ if (pRes != null)
1698
+ {
1699
+ if (ALWAYS(pRes.flags != 0))
1700
+ {
1701
+ sqlite3_result_value(context, pRes);
1702
+ }
1703
+ sqlite3VdbeMemRelease(pRes);
1704
+ }
1705
+ }
1706
+
1707
+ /*
1708
+ ** group_concat(EXPR, ?SEPARATOR?)
1709
+ */
1710
+ static void groupConcatStep(
1711
+ sqlite3_context context,
1712
+ int argc,
1713
+ sqlite3_value[] argv
1714
+ )
1715
+ {
1716
+ string zVal;
1717
+ //StrAccum pAccum;
1718
+ string zSep;
1719
+ int nVal, nSep;
1720
+ Debug.Assert(argc == 1 || argc == 2);
1721
+ if (sqlite3_value_type(argv[0]) == SQLITE_NULL) return;
1722
+ Mem pMem = sqlite3_aggregate_context(context, 1);//sizeof(*pAccum));
1723
+ if (pMem._StrAccum.zBase == null) pMem._StrAccum = new StrAccum(100);
1724
+ //pAccum = pMem._StrAccum;
1725
+ if (pMem._StrAccum.Context == null) pMem._StrAccum.Context = pMem;
1726
+ if (pMem._StrAccum.zBase != null)
1727
+ {
1728
+ sqlite3 db = sqlite3_context_db_handle(context);
1729
+ int firstTerm = pMem._StrAccum.useMalloc == 0 ? 1 : 0;
1730
+ pMem._StrAccum.useMalloc = 1;
1731
+ pMem._StrAccum.mxAlloc = db.aLimit[SQLITE_LIMIT_LENGTH];
1732
+ if (0 == firstTerm)
1733
+ {
1734
+ if (argc == 2)
1735
+ {
1736
+ zSep = sqlite3_value_text(argv[1]);
1737
+ nSep = sqlite3_value_bytes(argv[1]);
1738
+ }
1739
+ else
1740
+ {
1741
+ zSep = ",";
1742
+ nSep = 1;
1743
+ }
1744
+ sqlite3StrAccumAppend(pMem._StrAccum, zSep, nSep);
1745
+ }
1746
+ zVal = sqlite3_value_text(argv[0]);
1747
+ nVal = sqlite3_value_bytes(argv[0]);
1748
+ sqlite3StrAccumAppend(pMem._StrAccum, zVal, nVal);
1749
+ }
1750
+ }
1751
+
1752
+ static void groupConcatFinalize(sqlite3_context context)
1753
+ {
1754
+ //StrAccum pAccum = null;
1755
+ Mem pMem = sqlite3_aggregate_context(context, 0);
1756
+ if (pMem != null)
1757
+ {
1758
+ if (pMem._StrAccum.zBase == null) pMem._StrAccum = new StrAccum(100);
1759
+ StrAccum pAccum = pMem._StrAccum;
1760
+ //}
1761
+ //if ( pAccum != null )
1762
+ //{
1763
+ if (pAccum.tooBig != 0)
1764
+ {
1765
+ sqlite3_result_error_toobig(context);
1766
+ }
1767
+ //else if ( pAccum.mallocFailed != 0 )
1768
+ //{
1769
+ // sqlite3_result_error_nomem( context );
1770
+ //}
1771
+ else
1772
+ {
1773
+ sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
1774
+ null); //sqlite3_free );
1775
+ }
1776
+ }
1777
+ }
1778
+
1779
+ /*
1780
+ ** This function registered all of the above C functions as SQL
1781
+ ** functions. This should be the only routine in this file with
1782
+ ** external linkage.
1783
+ */
1784
+ public struct sFuncs
1785
+ {
1786
+ public string zName;
1787
+ public sbyte nArg;
1788
+ public u8 argType; /* 1: 0, 2: 1, 3: 2,... N: N-1. */
1789
+ public u8 eTextRep; /* 1: UTF-16. 0: UTF-8 */
1790
+ public u8 needCollSeq;
1791
+ public dxFunc xFunc; //(sqlite3_context*,int,sqlite3_value **);
1792
+
1793
+ // Constructor
1794
+ public sFuncs(string zName, sbyte nArg, u8 argType, u8 eTextRep, u8 needCollSeq, dxFunc xFunc)
1795
+ {
1796
+ this.zName = zName;
1797
+ this.nArg = nArg;
1798
+ this.argType = argType;
1799
+ this.eTextRep = eTextRep;
1800
+ this.needCollSeq = needCollSeq;
1801
+ this.xFunc = xFunc;
1802
+ }
1803
+ };
1804
+
1805
+ public struct sAggs
1806
+ {
1807
+ public string zName;
1808
+ public sbyte nArg;
1809
+ public u8 argType;
1810
+ public u8 needCollSeq;
1811
+ public dxStep xStep; //(sqlite3_context*,int,sqlite3_value**);
1812
+ public dxFinal xFinalize; //(sqlite3_context*);
1813
+ // Constructor
1814
+ public sAggs(string zName, sbyte nArg, u8 argType, u8 needCollSeq, dxStep xStep, dxFinal xFinalize)
1815
+ {
1816
+ this.zName = zName;
1817
+ this.nArg = nArg;
1818
+ this.argType = argType;
1819
+ this.needCollSeq = needCollSeq;
1820
+ this.xStep = xStep;
1821
+ this.xFinalize = xFinalize;
1822
+ }
1823
+ }
1824
+ static void sqlite3RegisterBuiltinFunctions(sqlite3 db)
1825
+ {
1826
+ #if !SQLITE_OMIT_ALTERTABLE
1827
+ sqlite3AlterFunctions(db);
1828
+ #endif
1829
+ ////if ( 0 == db.mallocFailed )
1830
+ {
1831
+ int rc = sqlite3_overload_function(db, "MATCH", 2);
1832
+ Debug.Assert(rc == SQLITE_NOMEM || rc == SQLITE_OK);
1833
+ if (rc == SQLITE_NOMEM)
1834
+ {
1835
+ //// db.mallocFailed = 1;
1836
+ }
1837
+ }
1838
+ }
1839
+
1840
+ /*
1841
+ ** Set the LIKEOPT flag on the 2-argument function with the given name.
1842
+ */
1843
+ static void setLikeOptFlag(sqlite3 db, string zName, int flagVal)
1844
+ {
1845
+ FuncDef pDef;
1846
+ pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
1847
+ 2, SQLITE_UTF8, 0);
1848
+ if (ALWAYS(pDef != null))
1849
+ {
1850
+ pDef.flags = (byte)flagVal;
1851
+ }
1852
+ }
1853
+
1854
+ /*
1855
+ ** Register the built-in LIKE and GLOB functions. The caseSensitive
1856
+ ** parameter determines whether or not the LIKE operator is case
1857
+ ** sensitive. GLOB is always case sensitive.
1858
+ */
1859
+ static void sqlite3RegisterLikeFunctions(sqlite3 db, int caseSensitive)
1860
+ {
1861
+ compareInfo pInfo;
1862
+ if (caseSensitive != 0)
1863
+ {
1864
+ pInfo = likeInfoAlt;
1865
+ }
1866
+ else
1867
+ {
1868
+ pInfo = likeInfoNorm;
1869
+ }
1870
+ sqlite3CreateFunc(db, "like", 2, SQLITE_ANY, pInfo, (dxFunc)likeFunc, null, null);
1871
+ sqlite3CreateFunc(db, "like", 3, SQLITE_ANY, pInfo, (dxFunc)likeFunc, null, null);
1872
+ sqlite3CreateFunc(db, "glob", 2, SQLITE_ANY,
1873
+ globInfo, (dxFunc)likeFunc, null, null);
1874
+ setLikeOptFlag(db, "glob", SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE);
1875
+ setLikeOptFlag(db, "like",
1876
+ caseSensitive != 0 ? (SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
1877
+ }
1878
+
1879
+ /*
1880
+ ** pExpr points to an expression which implements a function. If
1881
+ ** it is appropriate to apply the LIKE optimization to that function
1882
+ ** then set aWc[0] through aWc[2] to the wildcard characters and
1883
+ ** return TRUE. If the function is not a LIKE-style function then
1884
+ ** return FALSE.
1885
+ */
1886
+ static bool sqlite3IsLikeFunction(sqlite3 db, Expr pExpr, ref bool pIsNocase, char[] aWc)
1887
+ {
1888
+ FuncDef pDef;
1889
+ if (pExpr.op != TK_FUNCTION
1890
+ || null == pExpr.x.pList
1891
+ || pExpr.x.pList.nExpr != 2
1892
+ )
1893
+ {
1894
+ return false;
1895
+ }
1896
+ Debug.Assert(!ExprHasProperty(pExpr, EP_xIsSelect));
1897
+ pDef = sqlite3FindFunction(db, pExpr.u.zToken, sqlite3Strlen30(pExpr.u.zToken),
1898
+ 2, SQLITE_UTF8, 0);
1899
+ if (NEVER(pDef == null) || (pDef.flags & SQLITE_FUNC_LIKE) == 0)
1900
+ {
1901
+ return false;
1902
+ }
1903
+
1904
+ /* The memcpy() statement assumes that the wildcard characters are
1905
+ ** the first three statements in the compareInfo structure. The
1906
+ ** Debug.Asserts() that follow verify that assumption
1907
+ */
1908
+ //memcpy( aWc, pDef.pUserData, 3 );
1909
+ aWc[0] = ((compareInfo)pDef.pUserData).matchAll;
1910
+ aWc[1] = ((compareInfo)pDef.pUserData).matchOne;
1911
+ aWc[2] = ((compareInfo)pDef.pUserData).matchSet;
1912
+ // Debug.Assert((char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll);
1913
+ // Debug.Assert(&((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne);
1914
+ // Debug.Assert(&((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet);
1915
+ pIsNocase = (pDef.flags & SQLITE_FUNC_CASE) == 0;
1916
+ return true;
1917
+ }
1918
+
1919
+ /*
1920
+ ** All all of the FuncDef structures in the aBuiltinFunc[] array above
1921
+ ** to the global function hash table. This occurs at start-time (as
1922
+ ** a consequence of calling sqlite3_initialize()).
1923
+ **
1924
+ ** After this routine runs
1925
+ */
1926
+ static void sqlite3RegisterGlobalFunctions()
1927
+ {
1928
+ /*
1929
+ ** The following array holds FuncDef structures for all of the functions
1930
+ ** defined in this file.
1931
+ **
1932
+ ** The array cannot be constant since changes are made to the
1933
+ ** FuncDef.pHash elements at start-time. The elements of this array
1934
+ ** are read-only after initialization is complete.
1935
+ */
1936
+ FuncDef[] aBuiltinFunc = {
1937
+ FUNCTION("ltrim", 1, 1, 0, trimFunc ),
1938
+ FUNCTION("ltrim", 2, 1, 0, trimFunc ),
1939
+ FUNCTION("rtrim", 1, 2, 0, trimFunc ),
1940
+ FUNCTION("rtrim", 2, 2, 0, trimFunc ),
1941
+ FUNCTION("trim", 1, 3, 0, trimFunc ),
1942
+ FUNCTION("trim", 2, 3, 0, trimFunc ),
1943
+ FUNCTION("min", -1, 0, 1, minmaxFunc ),
1944
+ FUNCTION("min", 0, 0, 1, null ),
1945
+ AGGREGATE("min", 1, 0, 1, minmaxStep, minMaxFinalize ),
1946
+ FUNCTION("max", -1, 1, 1, minmaxFunc ),
1947
+ FUNCTION("max", 0, 1, 1, null ),
1948
+ AGGREGATE("max", 1, 1, 1, minmaxStep, minMaxFinalize ),
1949
+ FUNCTION("typeof", 1, 0, 0, typeofFunc ),
1950
+ FUNCTION("length", 1, 0, 0, lengthFunc ),
1951
+ FUNCTION("substr", 2, 0, 0, substrFunc ),
1952
+ FUNCTION("substr", 3, 0, 0, substrFunc ),
1953
+ FUNCTION("abs", 1, 0, 0, absFunc ),
1954
+ #if !SQLITE_OMIT_FLOATING_POINT
1955
+ FUNCTION("round", 1, 0, 0, roundFunc ),
1956
+ FUNCTION("round", 2, 0, 0, roundFunc ),
1957
+ #endif
1958
+ FUNCTION("upper", 1, 0, 0, upperFunc ),
1959
+ FUNCTION("lower", 1, 0, 0, lowerFunc ),
1960
+ FUNCTION("coalesce", 1, 0, 0, null ),
1961
+ FUNCTION("coalesce", 0, 0, 0, null ),
1962
+ /* FUNCTION(coalesce, -1, 0, 0, ifnullFunc ), */
1963
+ // use versionFunc here just for a dummy placeholder
1964
+ new FuncDef(-1,SQLITE_UTF8,SQLITE_FUNC_COALESCE,null,null,versionFunc,null,null,"coalesce",null),
1965
+ FUNCTION("hex", 1, 0, 0, hexFunc ),
1966
+ /* FUNCTION(ifnull, 2, 0, 0, ifnullFunc ), */
1967
+ // use versionFunc here just for a dummy placeholder
1968
+ new FuncDef(2,SQLITE_UTF8,SQLITE_FUNC_COALESCE,null,null,versionFunc,null,null,"ifnull",null),
1969
+ FUNCTION("random", 0, 0, 0, randomFunc ),
1970
+ FUNCTION("randomblob", 1, 0, 0, randomBlob ),
1971
+ FUNCTION("nullif", 2, 0, 1, nullifFunc ),
1972
+ FUNCTION("sqlite_version", 0, 0, 0, versionFunc ),
1973
+ FUNCTION("sqlite_source_id", 0, 0, 0, sourceidFunc ),
1974
+ #if !SQLITE_OMIT_COMPILEOPTION_DIAGS
1975
+ FUNCTION("sqlite_compileoption_used",1, 0, 0, compileoptionusedFunc ),
1976
+ FUNCTION("sqlite_compileoption_get", 1, 0, 0, compileoptiongetFunc ),
1977
+ #endif //* SQLITE_OMIT_COMPILEOPTION_DIAGS */
1978
+ FUNCTION("quote", 1, 0, 0, quoteFunc ),
1979
+ FUNCTION("last_insert_rowid", 0, 0, 0, last_insert_rowid),
1980
+ FUNCTION("changes", 0, 0, 0, changes ),
1981
+ FUNCTION("total_changes", 0, 0, 0, total_changes ),
1982
+ FUNCTION("replace", 3, 0, 0, replaceFunc ),
1983
+ FUNCTION("zeroblob", 1, 0, 0, zeroblobFunc ),
1984
+ #if SQLITE_SOUNDEX
1985
+ FUNCTION("soundex", 1, 0, 0, soundexFunc ),
1986
+ #endif
1987
+ #if !SQLITE_OMIT_LOAD_EXTENSION
1988
+ FUNCTION("load_extension", 1, 0, 0, loadExt ),
1989
+ FUNCTION("load_extension", 2, 0, 0, loadExt ),
1990
+ #endif
1991
+ AGGREGATE("sum", 1, 0, 0, sumStep, sumFinalize ),
1992
+ AGGREGATE("total", 1, 0, 0, sumStep, totalFinalize ),
1993
+ AGGREGATE("avg", 1, 0, 0, sumStep, avgFinalize ),
1994
+ /*AGGREGATE("count", 0, 0, 0, countStep, countFinalize ), */
1995
+ /* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
1996
+ new FuncDef( 0,SQLITE_UTF8,SQLITE_FUNC_COUNT,null,null,null,countStep,countFinalize,"count",null),
1997
+ AGGREGATE("count", 1, 0, 0, countStep, countFinalize ),
1998
+ AGGREGATE("group_concat", 1, 0, 0, groupConcatStep, groupConcatFinalize),
1999
+ AGGREGATE("group_concat", 2, 0, 0, groupConcatStep, groupConcatFinalize),
2000
+
2001
+ LIKEFUNC("glob", 2, globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
2002
+ #if SQLITE_CASE_SENSITIVE_LIKE
2003
+ LIKEFUNC("like", 2, likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
2004
+ LIKEFUNC("like", 3, likeInfoAlt, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
2005
+ #else
2006
+ LIKEFUNC("like", 2, likeInfoNorm, SQLITE_FUNC_LIKE),
2007
+ LIKEFUNC("like", 3, likeInfoNorm, SQLITE_FUNC_LIKE),
2008
+ #endif
2009
+ };
2010
+ int i;
2011
+ #if SQLITE_OMIT_WSD
2012
+ FuncDefHash pHash = GLOBAL( FuncDefHash, sqlite3GlobalFunctions );
2013
+ FuncDef[] aFunc = (FuncDef[])GLOBAL( FuncDef, aBuiltinFunc );
2014
+ #else
2015
+ FuncDefHash pHash = sqlite3GlobalFunctions;
2016
+ FuncDef[] aFunc = aBuiltinFunc;
2017
+ #endif
2018
+ for (i = 0; i < ArraySize(aBuiltinFunc); i++)
2019
+ {
2020
+ sqlite3FuncDefInsert(pHash, aFunc[i]);
2021
+ }
2022
+ sqlite3RegisterDateTimeFunctions();
2023
+ }
2024
+ }
2025
+ }