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,396 @@
1
+ using System.Diagnostics;
2
+
3
+ namespace Community.CsharpSqlite
4
+ {
5
+ using sqlite3_stmt = Sqlite3.Vdbe;
6
+
7
+ public partial class Sqlite3
8
+ {
9
+ /*
10
+ ** 2007 May 1
11
+ **
12
+ ** The author disclaims copyright to this source code. In place of
13
+ ** a legal notice, here is a blessing:
14
+ **
15
+ ** May you do good and not evil.
16
+ ** May you find forgiveness for yourself and forgive others.
17
+ ** May you share freely, never taking more than you give.
18
+ **
19
+ *************************************************************************
20
+ **
21
+ ** This file contains code used to implement incremental BLOB I/O.
22
+ *************************************************************************
23
+ ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
24
+ ** C#-SQLite is an independent reimplementation of the SQLite software library
25
+ **
26
+ ** SQLITE_SOURCE_ID: 2010-03-09 19:31:43 4ae453ea7be69018d8c16eb8dabe05617397dc4d
27
+ **
28
+ ** $Header$
29
+ *************************************************************************
30
+ */
31
+ //#include "sqliteInt.h"
32
+ //#include "vdbeInt.h"
33
+
34
+ #if !SQLITE_OMIT_INCRBLOB
35
+ /*
36
+ ** Valid sqlite3_blob* handles point to Incrblob structures.
37
+ */
38
+ typedef struct Incrblob Incrblob;
39
+ struct Incrblob {
40
+ int flags; /* Copy of "flags" passed to sqlite3_blob_open() */
41
+ int nByte; /* Size of open blob, in bytes */
42
+ int iOffset; /* Byte offset of blob in cursor data */
43
+ BtCursor *pCsr; /* Cursor pointing at blob row */
44
+ sqlite3_stmt *pStmt; /* Statement holding cursor open */
45
+ sqlite3 *db; /* The associated database */
46
+ };
47
+
48
+ /*
49
+ ** Open a blob handle.
50
+ */
51
+ int sqlite3_blob_open(
52
+ sqlite3* db, /* The database connection */
53
+ const char *zDb, /* The attached database containing the blob */
54
+ const char *zTable, /* The table containing the blob */
55
+ const char *zColumn, /* The column containing the blob */
56
+ sqlite_int64 iRow, /* The row containing the glob */
57
+ int flags, /* True -> read/write access, false -> read-only */
58
+ sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */
59
+ ){
60
+ int nAttempt = 0;
61
+ int iCol; /* Index of zColumn in row-record */
62
+
63
+ /* This VDBE program seeks a btree cursor to the identified
64
+ ** db/table/row entry. The reason for using a vdbe program instead
65
+ ** of writing code to use the b-tree layer directly is that the
66
+ ** vdbe program will take advantage of the various transaction,
67
+ ** locking and error handling infrastructure built into the vdbe.
68
+ **
69
+ ** After seeking the cursor, the vdbe executes an OP_ResultRow.
70
+ ** Code external to the Vdbe then "borrows" the b-tree cursor and
71
+ ** uses it to implement the blob_read(), blob_write() and
72
+ ** blob_bytes() functions.
73
+ **
74
+ ** The sqlite3_blob_close() function finalizes the vdbe program,
75
+ ** which closes the b-tree cursor and (possibly) commits the
76
+ ** transaction.
77
+ */
78
+ static const VdbeOpList openBlob[] = {
79
+ {OP_Transaction, 0, 0, 0}, /* 0: Start a transaction */
80
+ {OP_VerifyCookie, 0, 0, 0}, /* 1: Check the schema cookie */
81
+ {OP_TableLock, 0, 0, 0}, /* 2: Acquire a read or write lock */
82
+
83
+ /* One of the following two instructions is replaced by an OP_Noop. */
84
+ {OP_OpenRead, 0, 0, 0}, /* 3: Open cursor 0 for reading */
85
+ {OP_OpenWrite, 0, 0, 0}, /* 4: Open cursor 0 for read/write */
86
+
87
+ {OP_Variable, 1, 1, 1}, /* 5: Push the rowid to the stack */
88
+ {OP_NotExists, 0, 9, 1}, /* 6: Seek the cursor */
89
+ {OP_Column, 0, 0, 1}, /* 7 */
90
+ {OP_ResultRow, 1, 0, 0}, /* 8 */
91
+ {OP_Close, 0, 0, 0}, /* 9 */
92
+ {OP_Halt, 0, 0, 0}, /* 10 */
93
+ };
94
+
95
+ Vdbe *v = 0;
96
+ int rc = SQLITE_OK;
97
+ char *zErr = 0;
98
+ Table *pTab;
99
+ Parse *pParse;
100
+
101
+ *ppBlob = 0;
102
+ sqlite3_mutex_enter(db->mutex);
103
+ pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
104
+ if( pParse==0 ){
105
+ rc = SQLITE_NOMEM;
106
+ goto blob_open_out;
107
+ }
108
+ do {
109
+ memset(pParse, 0, sizeof(Parse));
110
+ pParse->db = db;
111
+
112
+ sqlite3BtreeEnterAll(db);
113
+ pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
114
+ if( pTab && IsVirtual(pTab) ){
115
+ pTab = 0;
116
+ sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
117
+ }
118
+ #if !SQLITE_OMIT_VIEW
119
+ if( pTab && pTab->pSelect ){
120
+ pTab = 0;
121
+ sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
122
+ }
123
+ #endif
124
+ if( !pTab ){
125
+ if( pParse->zErrMsg ){
126
+ sqlite3DbFree(db, zErr);
127
+ zErr = pParse->zErrMsg;
128
+ pParse->zErrMsg = 0;
129
+ }
130
+ rc = SQLITE_ERROR;
131
+ sqlite3BtreeLeaveAll(db);
132
+ goto blob_open_out;
133
+ }
134
+
135
+ /* Now search pTab for the exact column. */
136
+ for(iCol=0; iCol < pTab->nCol; iCol++) {
137
+ if( sqlite3StrICmp(pTab->aCol[iCol].zName, zColumn)==0 ){
138
+ break;
139
+ }
140
+ }
141
+ if( iCol==pTab->nCol ){
142
+ sqlite3DbFree(db, zErr);
143
+ zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
144
+ rc = SQLITE_ERROR;
145
+ sqlite3BtreeLeaveAll(db);
146
+ goto blob_open_out;
147
+ }
148
+
149
+ /* If the value is being opened for writing, check that the
150
+ ** column is not indexed, and that it is not part of a foreign key.
151
+ ** It is against the rules to open a column to which either of these
152
+ ** descriptions applies for writing. */
153
+ if( flags ){
154
+ const char *zFault = 0;
155
+ Index *pIdx;
156
+ #if !SQLITE_OMIT_FOREIGN_KEY
157
+ if( db->flags&SQLITE_ForeignKeys ){
158
+ /* Check that the column is not part of an FK child key definition. It
159
+ ** is not necessary to check if it is part of a parent key, as parent
160
+ ** key columns must be indexed. The check below will pick up this
161
+ ** case. */
162
+ FKey *pFKey;
163
+ for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
164
+ int j;
165
+ for(j=0; j<pFKey->nCol; j++){
166
+ if( pFKey->aCol[j].iFrom==iCol ){
167
+ zFault = "foreign key";
168
+ }
169
+ }
170
+ }
171
+ }
172
+ #endif
173
+ for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
174
+ int j;
175
+ for(j=0; j<pIdx->nColumn; j++){
176
+ if( pIdx->aiColumn[j]==iCol ){
177
+ zFault = "indexed";
178
+ }
179
+ }
180
+ }
181
+ if( zFault ){
182
+ sqlite3DbFree(db, zErr);
183
+ zErr = sqlite3MPrintf(db, "cannot open %s column for writing", zFault);
184
+ rc = SQLITE_ERROR;
185
+ sqlite3BtreeLeaveAll(db);
186
+ goto blob_open_out;
187
+ }
188
+ }
189
+
190
+ v = sqlite3VdbeCreate(db);
191
+ if( v ){
192
+ int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
193
+ sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob);
194
+ flags = !!flags; /* flags = (flags ? 1 : 0); */
195
+
196
+ /* Configure the OP_Transaction */
197
+ sqlite3VdbeChangeP1(v, 0, iDb);
198
+ sqlite3VdbeChangeP2(v, 0, flags);
199
+
200
+ /* Configure the OP_VerifyCookie */
201
+ sqlite3VdbeChangeP1(v, 1, iDb);
202
+ sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
203
+
204
+ /* Make sure a mutex is held on the table to be accessed */
205
+ sqlite3VdbeUsesBtree(v, iDb);
206
+
207
+ /* Configure the OP_TableLock instruction */
208
+ sqlite3VdbeChangeP1(v, 2, iDb);
209
+ sqlite3VdbeChangeP2(v, 2, pTab->tnum);
210
+ sqlite3VdbeChangeP3(v, 2, flags);
211
+ sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
212
+
213
+ /* Remove either the OP_OpenWrite or OpenRead. Set the P2
214
+ ** parameter of the other to pTab->tnum. */
215
+ sqlite3VdbeChangeToNoop(v, 4 - flags, 1);
216
+ sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
217
+ sqlite3VdbeChangeP3(v, 3 + flags, iDb);
218
+
219
+ /* Configure the number of columns. Configure the cursor to
220
+ ** think that the table has one more column than it really
221
+ ** does. An OP_Column to retrieve this imaginary column will
222
+ ** always return an SQL NULL. This is useful because it means
223
+ ** we can invoke OP_Column to fill in the vdbe cursors type
224
+ ** and offset cache without causing any IO.
225
+ */
226
+ sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
227
+ sqlite3VdbeChangeP2(v, 7, pTab->nCol);
228
+ if( !db->mallocFailed ){
229
+ sqlite3VdbeMakeReady(v, 1, 1, 1, 0, 0, 0);
230
+ }
231
+ }
232
+
233
+ sqlite3BtreeLeaveAll(db);
234
+ goto blob_open_out;
235
+ }
236
+
237
+ sqlite3_bind_int64((sqlite3_stmt *)v, 1, iRow);
238
+ rc = sqlite3_step((sqlite3_stmt *)v);
239
+ if( rc!=SQLITE_ROW ){
240
+ nAttempt++;
241
+ rc = sqlite3_finalize((sqlite3_stmt *)v);
242
+ sqlite3DbFree(db, zErr);
243
+ zErr = sqlite3MPrintf(db, sqlite3_errmsg(db));
244
+ v = 0;
245
+ }
246
+ } while( nAttempt<5 && rc==SQLITE_SCHEMA );
247
+
248
+ if( rc==SQLITE_ROW ){
249
+ /* The row-record has been opened successfully. Check that the
250
+ ** column in question contains text or a blob. If it contains
251
+ ** text, it is up to the caller to get the encoding right.
252
+ */
253
+ Incrblob *pBlob;
254
+ u32 type = v->apCsr[0]->aType[iCol];
255
+
256
+ if( type<12 ){
257
+ sqlite3DbFree(db, zErr);
258
+ zErr = sqlite3MPrintf(db, "cannot open value of type %s",
259
+ type==0?"null": type==7?"real": "integer"
260
+ );
261
+ rc = SQLITE_ERROR;
262
+ goto blob_open_out;
263
+ }
264
+ pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
265
+ if( db->mallocFailed ){
266
+ sqlite3DbFree(db, ref pBlob);
267
+ goto blob_open_out;
268
+ }
269
+ pBlob->flags = flags;
270
+ pBlob->pCsr = v->apCsr[0]->pCursor;
271
+ sqlite3BtreeEnterCursor(pBlob->pCsr);
272
+ sqlite3BtreeCacheOverflow(pBlob->pCsr);
273
+ sqlite3BtreeLeaveCursor(pBlob->pCsr);
274
+ pBlob->pStmt = (sqlite3_stmt *)v;
275
+ pBlob->iOffset = v->apCsr[0]->aOffset[iCol];
276
+ pBlob->nByte = sqlite3VdbeSerialTypeLen(type);
277
+ pBlob->db = db;
278
+ *ppBlob = (sqlite3_blob *)pBlob;
279
+ rc = SQLITE_OK;
280
+ }else if( rc==SQLITE_OK ){
281
+ sqlite3DbFree(db, zErr);
282
+ zErr = sqlite3MPrintf(db, "no such rowid: %lld", iRow);
283
+ rc = SQLITE_ERROR;
284
+ }
285
+
286
+ blob_open_out:
287
+ if( v && (rc!=SQLITE_OK || db->mallocFailed) ){
288
+ sqlite3VdbeFinalize(v);
289
+ }
290
+ sqlite3Error(db, rc, zErr);
291
+ sqlite3DbFree(db, zErr);
292
+ sqlite3StackFree(db, pParse);
293
+ rc = sqlite3ApiExit(db, rc);
294
+ sqlite3_mutex_leave(db->mutex);
295
+ return rc;
296
+ }
297
+
298
+ /*
299
+ ** Close a blob handle that was previously created using
300
+ ** sqlite3_blob_open().
301
+ */
302
+ int sqlite3_blob_close(sqlite3_blob *pBlob){
303
+ Incrblob *p = (Incrblob *)pBlob;
304
+ int rc;
305
+ sqlite3 *db;
306
+
307
+ if( p ){
308
+ db = p->db;
309
+ sqlite3_mutex_enter(db->mutex);
310
+ rc = sqlite3_finalize(p->pStmt);
311
+ sqlite3DbFree(db, ref p);
312
+ sqlite3_mutex_leave(db->mutex);
313
+ }else{
314
+ rc = SQLITE_OK;
315
+ }
316
+ return rc;
317
+ }
318
+
319
+ /*
320
+ ** Perform a read or write operation on a blob
321
+ */
322
+ static int blobReadWrite(
323
+ sqlite3_blob *pBlob,
324
+ void *z,
325
+ int n,
326
+ int iOffset,
327
+ int (*xCall)(BtCursor*, u32, u32, void*)
328
+ ){
329
+ int rc;
330
+ Incrblob *p = (Incrblob *)pBlob;
331
+ Vdbe *v;
332
+ sqlite3 *db;
333
+
334
+ if( p==0 ) return SQLITE_MISUSE_BKPT();
335
+ db = p->db;
336
+ sqlite3_mutex_enter(db->mutex);
337
+ v = (Vdbe*)p->pStmt;
338
+
339
+ if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
340
+ /* Request is out of range. Return a transient error. */
341
+ rc = SQLITE_ERROR;
342
+ sqlite3Error(db, SQLITE_ERROR, 0);
343
+ } else if( v==0 ){
344
+ /* If there is no statement handle, then the blob-handle has
345
+ ** already been invalidated. Return SQLITE_ABORT in this case.
346
+ */
347
+ rc = SQLITE_ABORT;
348
+ }else{
349
+ /* Call either BtreeData() or BtreePutData(). If SQLITE_ABORT is
350
+ ** returned, clean-up the statement handle.
351
+ */
352
+ assert( db == v->db );
353
+ sqlite3BtreeEnterCursor(p->pCsr);
354
+ rc = xCall(p->pCsr, iOffset+p->iOffset, n, z);
355
+ sqlite3BtreeLeaveCursor(p->pCsr);
356
+ if( rc==SQLITE_ABORT ){
357
+ sqlite3VdbeFinalize(v);
358
+ p->pStmt = 0;
359
+ }else{
360
+ db->errCode = rc;
361
+ v->rc = rc;
362
+ }
363
+ }
364
+ rc = sqlite3ApiExit(db, rc);
365
+ sqlite3_mutex_leave(db->mutex);
366
+ return rc;
367
+ }
368
+
369
+ /*
370
+ ** Read data from a blob handle.
371
+ */
372
+ int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){
373
+ return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreeData);
374
+ }
375
+
376
+ /*
377
+ ** Write data to a blob handle.
378
+ */
379
+ int sqlite3_blob_write(sqlite3_blob *pBlob, const void *z, int n, int iOffset){
380
+ return blobReadWrite(pBlob, (void *)z, n, iOffset, sqlite3BtreePutData);
381
+ }
382
+
383
+ /*
384
+ ** Query a blob handle for the size of the data.
385
+ **
386
+ ** The Incrblob.nByte field is fixed for the lifetime of the Incrblob
387
+ ** so no mutex is required for access.
388
+ */
389
+ int sqlite3_blob_bytes(sqlite3_blob *pBlob){
390
+ Incrblob *p = (Incrblob *)pBlob;
391
+ return p ? p->nByte : 0;
392
+ }
393
+
394
+ #endif // * #if !SQLITE_OMIT_INCRBLOB */
395
+ }
396
+ }
@@ -0,0 +1,1480 @@
1
+ using System;
2
+ using System.Diagnostics;
3
+ using System.Text;
4
+
5
+ using i64 = System.Int64;
6
+ using u8 = System.Byte;
7
+ using u16 = System.UInt16;
8
+ using u32 = System.UInt32;
9
+
10
+ namespace Community.CsharpSqlite
11
+ {
12
+ using sqlite3_value = Sqlite3.Mem;
13
+
14
+ public partial class Sqlite3
15
+ {
16
+ /*
17
+ ** 2004 May 26
18
+ **
19
+ ** The author disclaims copyright to this source code. In place of
20
+ ** a legal notice, here is a blessing:
21
+ **
22
+ ** May you do good and not evil.
23
+ ** May you find forgiveness for yourself and forgive others.
24
+ ** May you share freely, never taking more than you give.
25
+ **
26
+ *************************************************************************
27
+ **
28
+ ** This file contains code use to manipulate "Mem" structure. A "Mem"
29
+ ** stores a single value in the VDBE. Mem is an opaque structure visible
30
+ ** only within the VDBE. Interface routines refer to a Mem using the
31
+ ** name sqlite_value
32
+ *************************************************************************
33
+ ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
34
+ ** C#-SQLite is an independent reimplementation of the SQLite software library
35
+ **
36
+ ** SQLITE_SOURCE_ID: 2010-03-09 19:31:43 4ae453ea7be69018d8c16eb8dabe05617397dc4d
37
+ **
38
+ ** $Header$
39
+ *************************************************************************
40
+ */
41
+ //#include "sqliteInt.h"
42
+ //#include "vdbeInt.h"
43
+
44
+ /*
45
+ ** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*)
46
+ ** P if required.
47
+ */
48
+ //#define expandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
49
+ static void expandBlob( Mem P )
50
+ { if ( ( P.flags & MEM_Zero ) != 0 ) sqlite3VdbeMemExpandBlob( P ); } // TODO -- Convert to inline for speed
51
+
52
+ /*
53
+ ** If pMem is an object with a valid string representation, this routine
54
+ ** ensures the internal encoding for the string representation is
55
+ ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
56
+ **
57
+ ** If pMem is not a string object, or the encoding of the string
58
+ ** representation is already stored using the requested encoding, then this
59
+ ** routine is a no-op.
60
+ **
61
+ ** SQLITE_OK is returned if the conversion is successful (or not required).
62
+ ** SQLITE_NOMEM may be returned if a malloc() fails during conversion
63
+ ** between formats.
64
+ */
65
+ static int sqlite3VdbeChangeEncoding( Mem pMem, int desiredEnc )
66
+ {
67
+ int rc;
68
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
69
+ Debug.Assert( desiredEnc == SQLITE_UTF8 || desiredEnc == SQLITE_UTF16LE
70
+ || desiredEnc == SQLITE_UTF16BE );
71
+ if ( ( pMem.flags & MEM_Str ) == 0 || pMem.enc == desiredEnc )
72
+ {
73
+ if (pMem.z == null && pMem.zBLOB != null) pMem.z = Encoding.UTF8.GetString(pMem.zBLOB, 0, pMem.zBLOB.Length);
74
+ return SQLITE_OK;
75
+ }
76
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
77
+ #if SQLITE_OMIT_UTF16
78
+ return SQLITE_ERROR;
79
+ #else
80
+
81
+ /* MemTranslate() may return SQLITE_OK or SQLITE_NOMEM. If NOMEM is returned,
82
+ ** then the encoding of the value may not have changed.
83
+ */
84
+ rc = sqlite3VdbeMemTranslate(pMem, (u8)desiredEnc);
85
+ Debug.Assert(rc==SQLITE_OK || rc==SQLITE_NOMEM);
86
+ Debug.Assert(rc==SQLITE_OK || pMem.enc!=desiredEnc);
87
+ Debug.Assert(rc==SQLITE_NOMEM || pMem.enc==desiredEnc);
88
+ return rc;
89
+ #endif
90
+ }
91
+
92
+ /*
93
+ ** Make sure pMem.z points to a writable allocation of at least
94
+ ** n bytes.
95
+ **
96
+ ** If the memory cell currently contains string or blob data
97
+ ** and the third argument passed to this function is true, the
98
+ ** current content of the cell is preserved. Otherwise, it may
99
+ ** be discarded.
100
+ **
101
+ ** This function sets the MEM_Dyn flag and clears any xDel callback.
102
+ ** It also clears MEM_Ephem and MEM_Static. If the preserve flag is
103
+ ** not set, Mem.n is zeroed.
104
+ */
105
+ static int sqlite3VdbeMemGrow( Mem pMem, int n, int preserve )
106
+ {
107
+ // TODO -- What do we want to do about this routine?
108
+ //Debug.Assert( 1 >=
109
+ // ((pMem.zMalloc !=null )? 1 : 0) + //&& pMem.zMalloc==pMem.z) ? 1 : 0) +
110
+ // (((pMem.flags & MEM_Dyn)!=0 && pMem.xDel!=null) ? 1 : 0) +
111
+ // ((pMem.flags & MEM_Ephem)!=0 ? 1 : 0) +
112
+ // ((pMem.flags & MEM_Static)!=0 ? 1 : 0)
113
+ //);
114
+ //assert( (pMem->flags&MEM_RowSet)==0 );
115
+
116
+ //if( n<32 ) n = 32;
117
+ //if( sqlite3DbMallocSize(pMem->db, pMem.zMalloc)<n ){
118
+ if ( preserve != 0 )
119
+ {//& pMem.z==pMem.zMalloc ){
120
+ if ( pMem.z == null ) pMem.z = "";// sqlite3DbReallocOrFree( pMem.db, pMem.z, n );
121
+ else pMem.z = pMem.z.Substring( 0, n );
122
+ preserve = 0;
123
+ }
124
+ else
125
+ {
126
+ // sqlite3DbFree(pMem->db,ref pMem.zMalloc);
127
+ pMem.z = "";// sqlite3DbMallocRaw( pMem.db, n );
128
+ }
129
+ //}
130
+
131
+ // if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
132
+ // memcpy(pMem.zMalloc, pMem.z, pMem.n);
133
+ //}
134
+ if ( ( pMem.flags & MEM_Dyn ) != 0 && pMem.xDel != null )
135
+ {
136
+ pMem.xDel( ref pMem.z );
137
+ }
138
+
139
+ // TODO --pMem.z = pMem.zMalloc;
140
+ if ( pMem.z == null )
141
+ {
142
+ pMem.flags = MEM_Null;
143
+ }
144
+ else
145
+ {
146
+ pMem.flags = (u16)( pMem.flags & ~( MEM_Ephem | MEM_Static ) );
147
+ }
148
+ pMem.xDel = null;
149
+ return pMem.z != null ? SQLITE_OK : SQLITE_NOMEM;
150
+ }
151
+
152
+ /*
153
+ ** Make the given Mem object MEM_Dyn. In other words, make it so
154
+ ** that any TEXT or BLOB content is stored in memory obtained from
155
+ ** malloc(). In this way, we know that the memory is safe to be
156
+ ** overwritten or altered.
157
+ **
158
+ ** Return SQLITE_OK on success or SQLITE_NOMEM if malloc fails.
159
+ */
160
+ static int sqlite3VdbeMemMakeWriteable( Mem pMem )
161
+ {
162
+ int f;
163
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
164
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
165
+ expandBlob( pMem );
166
+ f = pMem.flags;
167
+ if ( ( f & ( MEM_Str | MEM_Blob ) ) != 0 ) // TODO -- && pMem.z != pMem.zMalloc )
168
+ {
169
+ //if ( sqlite3VdbeMemGrow( pMem, pMem.n + 2, 1 ) != 0 )
170
+ //{
171
+ // return SQLITE_NOMEM;
172
+ //}
173
+ //pMem.z[pMem->n] = 0;
174
+ //pMem.z[pMem->n + 1] = 0;
175
+ pMem.flags |= MEM_Term;
176
+ }
177
+
178
+ return SQLITE_OK;
179
+ }
180
+ /*
181
+ ** If the given Mem* has a zero-filled tail, turn it into an ordinary
182
+ ** blob stored in dynamically allocated space.
183
+ */
184
+ #if !SQLITE_OMIT_INCRBLOB
185
+ static int sqlite3VdbeMemExpandBlob( Mem pMem )
186
+ {
187
+ if ( ( pMem.flags & MEM_Zero ) != 0 )
188
+ {
189
+ u32 nByte;
190
+ Debug.Assert( ( pMem.flags & MEM_Blob ) != 0 );
191
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
192
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
193
+ /* Set nByte to the number of bytes required to store the expanded blob. */
194
+ nByte = (u32)( pMem.n + pMem.u.nZero );
195
+ if ( nByte <= 0 )
196
+ {
197
+ nByte = 1;
198
+ }
199
+ if ( sqlite3VdbeMemGrow( pMem, (int)nByte, 1 ) != 0 )
200
+ {
201
+ return SQLITE_NOMEM;
202
+ } /* Set nByte to the number of bytes required to store the expanded blob. */
203
+ nByte = (u32)( pMem.n + pMem.u.nZero );
204
+ if ( nByte <= 0 )
205
+ {
206
+ nByte = 1;
207
+ }
208
+ if ( sqlite3VdbeMemGrow( pMem, (int)nByte, 1 ) != 0 )
209
+ {
210
+ return SQLITE_NOMEM;
211
+ }
212
+ //memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
213
+ pMem.zBLOB = Encoding.UTF8.GetBytes( pMem.z );
214
+ pMem.z = null;
215
+ pMem.n += (int)pMem.u.nZero;
216
+ pMem.u.i = 0;
217
+ pMem.flags = (u16)( pMem.flags & ~( MEM_Zero | MEM_Static | MEM_Ephem | MEM_Term ) );
218
+ pMem.flags |= MEM_Dyn;
219
+ }
220
+ return SQLITE_OK;
221
+ }
222
+ #endif
223
+
224
+
225
+ /*
226
+ ** Make sure the given Mem is \u0000 terminated.
227
+ */
228
+ static int sqlite3VdbeMemNulTerminate( Mem pMem )
229
+ {
230
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
231
+ if ( ( pMem.flags & MEM_Term ) != 0 || ( pMem.flags & MEM_Str ) == 0 )
232
+ {
233
+ return SQLITE_OK; /* Nothing to do */
234
+ }
235
+ //if ( pMem.n != 0 && sqlite3VdbeMemGrow( pMem, pMem.n + 2, 1 ) != 0 )
236
+ //{
237
+ // return SQLITE_NOMEM;
238
+ //}
239
+ // pMem.z[pMem->n] = 0;
240
+ // pMem.z[pMem->n+1] = 0;
241
+ if ( pMem.z != null && pMem.n < pMem.z.Length ) pMem.z = pMem.z.Substring( 0, pMem.n );
242
+ pMem.flags |= MEM_Term;
243
+ return SQLITE_OK;
244
+ }
245
+
246
+ /*
247
+ ** Add MEM_Str to the set of representations for the given Mem. Numbers
248
+ ** are converted using sqlite3_snprintf(). Converting a BLOB to a string
249
+ ** is a no-op.
250
+ **
251
+ ** Existing representations MEM_Int and MEM_Real are *not* invalidated.
252
+ **
253
+ ** A MEM_Null value will never be passed to this function. This function is
254
+ ** used for converting values to text for returning to the user (i.e. via
255
+ ** sqlite3_value_text()), or for ensuring that values to be used as btree
256
+ ** keys are strings. In the former case a NULL pointer is returned the
257
+ ** user and the later is an internal programming error.
258
+ */
259
+ static int sqlite3VdbeMemStringify( Mem pMem, int enc )
260
+ {
261
+ int rc = SQLITE_OK;
262
+ int fg = pMem.flags;
263
+ const int nByte = 32;
264
+
265
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
266
+ Debug.Assert( ( fg & MEM_Zero ) == 0 );
267
+ Debug.Assert( ( fg & ( MEM_Str | MEM_Blob ) ) == 0 );
268
+ Debug.Assert( ( fg & ( MEM_Int | MEM_Real ) ) != 0 );
269
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
270
+ //assert( EIGHT_BYTE_ALIGNMENT(pMem) );
271
+
272
+ if ( sqlite3VdbeMemGrow( pMem, nByte, 0 ) != 0 )
273
+ {
274
+ return SQLITE_NOMEM;
275
+ }
276
+
277
+ /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
278
+ ** string representation of the value. Then, if the required encoding
279
+ ** is UTF-16le or UTF-16be do a translation.
280
+ **
281
+ ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
282
+ */
283
+ if ( ( fg & MEM_Int ) != 0 )
284
+ {
285
+ pMem.z = pMem.u.i.ToString(); //sqlite3_snprintf(nByte, pMem.z, "%lld", pMem->u.i);
286
+ }
287
+ else
288
+ {
289
+ Debug.Assert( ( fg & MEM_Real ) != 0 );
290
+ if ( Double.IsNegativeInfinity( pMem.r ) ) pMem.z = "-Inf";
291
+ else if ( Double.IsInfinity( pMem.r ) ) pMem.z = "Inf";
292
+ else if ( Double.IsPositiveInfinity( pMem.r ) ) pMem.z = "+Inf";
293
+ else if ( pMem.r.ToString().Contains( "." ) ) pMem.z = pMem.r.ToString().ToLower();//sqlite3_snprintf(nByte, pMem.z, "%!.15g", pMem->r);
294
+ else pMem.z = pMem.r.ToString() + ".0";
295
+ }
296
+ pMem.n = sqlite3Strlen30( pMem.z );
297
+ pMem.enc = SQLITE_UTF8;
298
+ pMem.flags |= MEM_Str | MEM_Term;
299
+ sqlite3VdbeChangeEncoding( pMem, enc );
300
+ return rc;
301
+ }
302
+
303
+ /*
304
+ ** Memory cell pMem contains the context of an aggregate function.
305
+ ** This routine calls the finalize method for that function. The
306
+ ** result of the aggregate is stored back into pMem.
307
+ **
308
+ ** Return SQLITE_ERROR if the finalizer reports an error. SQLITE_OK
309
+ ** otherwise.
310
+ */
311
+ static int sqlite3VdbeMemFinalize( Mem pMem, FuncDef pFunc )
312
+ {
313
+ int rc = SQLITE_OK;
314
+ if ( ALWAYS( pFunc != null && pFunc.xFinalize != null ) )
315
+ {
316
+ sqlite3_context ctx = new sqlite3_context();
317
+ Debug.Assert( ( pMem.flags & MEM_Null ) != 0 || pFunc == pMem.u.pDef );
318
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
319
+ //memset(&ctx, 0, sizeof(ctx));
320
+ ctx.s.flags = MEM_Null;
321
+ ctx.s.db = pMem.db;
322
+ ctx.pMem = pMem;
323
+ ctx.pFunc = pFunc;
324
+ pFunc.xFinalize( ctx );
325
+ Debug.Assert( 0 == ( pMem.flags & MEM_Dyn ) && pMem.xDel == null );
326
+ sqlite3DbFree(pMem.db, ref pMem.zBLOB);//zMalloc );
327
+ ctx.s.CopyTo( pMem );//memcpy(pMem, &ctx.s, sizeof(ctx.s));
328
+ rc = ctx.isError;
329
+ }
330
+ return rc;
331
+ }
332
+
333
+ /*
334
+ ** If the memory cell contains a string value that must be freed by
335
+ ** invoking an external callback, free it now. Calling this function
336
+ ** does not free any Mem.zMalloc buffer.
337
+ */
338
+ static void sqlite3VdbeMemReleaseExternal( Mem p )
339
+ {
340
+ Debug.Assert( p.db == null || sqlite3_mutex_held( p.db.mutex ) );
341
+ testcase( p.flags & MEM_Agg );
342
+ testcase( p.flags & MEM_Dyn );
343
+ testcase( p.flags & MEM_RowSet );
344
+ testcase( p.flags & MEM_Frame );
345
+ if ( ( p.flags & ( MEM_Agg | MEM_Dyn | MEM_RowSet | MEM_Frame ) ) != 0 )
346
+ {
347
+ if ( ( p.flags & MEM_Agg ) != 0 )
348
+ {
349
+ sqlite3VdbeMemFinalize( p, p.u.pDef );
350
+ Debug.Assert( ( p.flags & MEM_Agg ) == 0 );
351
+ sqlite3VdbeMemRelease( p );
352
+ }
353
+ else if ( ( p.flags & MEM_Dyn ) != 0 && p.xDel != null )
354
+ {
355
+ Debug.Assert( ( p.flags & MEM_RowSet ) == 0 );
356
+ p.xDel( ref p.z );
357
+ p.xDel = null;
358
+ }
359
+ else if ( ( p.flags & MEM_RowSet ) != 0 )
360
+ {
361
+ sqlite3RowSetClear( p.u.pRowSet );
362
+ }
363
+ else if ( ( p.flags & MEM_Frame ) != 0 )
364
+ {
365
+ sqlite3VdbeMemSetNull( p );
366
+ }
367
+ }
368
+ p.n = 0;
369
+ p.z = null;
370
+ p.zBLOB = null;
371
+ }
372
+
373
+ /*
374
+ ** Release any memory held by the Mem. This may leave the Mem in an
375
+ ** inconsistent state, for example with (Mem.z==0) and
376
+ ** (Mem.type==SQLITE_TEXT).
377
+ */
378
+ static void sqlite3VdbeMemRelease( Mem p )
379
+ {
380
+ sqlite3VdbeMemReleaseExternal( p );
381
+ sqlite3DbFree( p.db, ref p.zBLOB);//zMalloc );
382
+ p.z = null;
383
+ //p.zMalloc = 0;
384
+ p.xDel = null;
385
+ }
386
+
387
+ /*
388
+ ** Convert a 64-bit IEEE double into a 64-bit signed integer.
389
+ ** If the double is too large, return 0x8000000000000000.
390
+ **
391
+ ** Most systems appear to do this simply by assigning
392
+ ** variables and without the extra range tests. But
393
+ ** there are reports that windows throws an expection
394
+ ** if the floating point value is out of range. (See ticket #2880.)
395
+ ** Because we do not completely understand the problem, we will
396
+ ** take the conservative approach and always do range tests
397
+ ** before attempting the conversion.
398
+ */
399
+ static i64 doubleToInt64( double r )
400
+ {
401
+ #if SQLITE_OMIT_FLOATING_POINT
402
+ /* When floating-point is omitted, double and int64 are the same thing */
403
+ return r;
404
+ #else
405
+ /*
406
+ ** Many compilers we encounter do not define constants for the
407
+ ** minimum and maximum 64-bit integers, or they define them
408
+ ** inconsistently. And many do not understand the "LL" notation.
409
+ ** So we define our own static constants here using nothing
410
+ ** larger than a 32-bit integer constant.
411
+ */
412
+ const i64 maxInt = LARGEST_INT64;
413
+ const i64 minInt = SMALLEST_INT64;
414
+
415
+ if ( r < (double)minInt )
416
+ {
417
+ return minInt;
418
+ }
419
+ else if ( r > (double)maxInt )
420
+ {
421
+ /* minInt is correct here - not maxInt. It turns out that assigning
422
+ ** a very large positive number to an integer results in a very large
423
+ ** negative integer. This makes no sense, but it is what x86 hardware
424
+ ** does so for compatibility we will do the same in software. */
425
+ return minInt;
426
+ }
427
+ else
428
+ {
429
+ return (i64)r;
430
+ }
431
+ #endif
432
+ }
433
+
434
+ /*
435
+ ** Return some kind of integer value which is the best we can do
436
+ ** at representing the value that *pMem describes as an integer.
437
+ ** If pMem is an integer, then the value is exact. If pMem is
438
+ ** a floating-point then the value returned is the integer part.
439
+ ** If pMem is a string or blob, then we make an attempt to convert
440
+ ** it into a integer and return that. If pMem represents an
441
+ ** an SQL-NULL value, return 0.
442
+ **
443
+ ** If pMem represents a string value, its encoding might be changed.
444
+ */
445
+ static i64 sqlite3VdbeIntValue( Mem pMem )
446
+ {
447
+ int flags;
448
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
449
+ // assert( EIGHT_BYTE_ALIGNMENT(pMem) );
450
+ flags = pMem.flags;
451
+ if ( ( flags & MEM_Int ) != 0 )
452
+ {
453
+ return pMem.u.i;
454
+ }
455
+ else if ( ( flags & MEM_Real ) != 0 )
456
+ {
457
+ return doubleToInt64( pMem.r );
458
+ }
459
+ else if ( ( flags & ( MEM_Str | MEM_Blob ) ) != 0 )
460
+ {
461
+ i64 value = 0;
462
+ pMem.flags |= MEM_Str;
463
+ if ( sqlite3VdbeChangeEncoding( pMem, SQLITE_UTF8 ) != 0
464
+ || ( sqlite3VdbeMemNulTerminate( pMem ) != 0 ) )
465
+ {
466
+ return 0;
467
+ }
468
+ if ( pMem.z == null ) return 0;
469
+ Debug.Assert( pMem.z != null );
470
+ sqlite3Atoi64( pMem.z, ref value );
471
+ return value;
472
+ }
473
+ else
474
+ {
475
+ return 0;
476
+ }
477
+ }
478
+
479
+ /*
480
+ ** Return the best representation of pMem that we can get into a
481
+ ** double. If pMem is already a double or an integer, return its
482
+ ** value. If it is a string or blob, try to convert it to a double.
483
+ ** If it is a NULL, return 0.0.
484
+ */
485
+ static double sqlite3VdbeRealValue( Mem pMem )
486
+ {
487
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
488
+ //assert( EIGHT_BYTE_ALIGNMENT(pMem) );
489
+ if ( ( pMem.flags & MEM_Real ) != 0 )
490
+ {
491
+ return pMem.r;
492
+ }
493
+ else if ( ( pMem.flags & MEM_Int ) != 0 )
494
+ {
495
+ return (double)pMem.u.i;
496
+ }
497
+ else if ( ( pMem.flags & ( MEM_Str | MEM_Blob ) ) != 0 )
498
+ {
499
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
500
+ double val = (double)0;
501
+ pMem.flags |= MEM_Str;
502
+ if ( sqlite3VdbeChangeEncoding( pMem, SQLITE_UTF8 ) != 0
503
+ || sqlite3VdbeMemNulTerminate( pMem ) != 0 )
504
+ {
505
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
506
+ return (double)0;
507
+ }
508
+ if (pMem.zBLOB != null) sqlite3AtoF(Encoding.UTF8.GetString(pMem.zBLOB, 0, pMem.zBLOB.Length), ref val);
509
+ else if ( !String.IsNullOrEmpty( pMem.z ) ) sqlite3AtoF( pMem.z, ref val );
510
+ else val = 0.0;
511
+ return val;
512
+ }
513
+ else
514
+ {
515
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
516
+ return (double)0;
517
+ }
518
+ }
519
+
520
+ /*
521
+ ** The MEM structure is already a MEM_Real. Try to also make it a
522
+ ** MEM_Int if we can.
523
+ */
524
+ static void sqlite3VdbeIntegerAffinity( Mem pMem )
525
+ {
526
+ Debug.Assert( ( pMem.flags & MEM_Real ) != 0 );
527
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
528
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
529
+ //assert( EIGHT_BYTE_ALIGNMENT(pMem) );
530
+
531
+ pMem.u.i = doubleToInt64( pMem.r );
532
+
533
+ /* Only mark the value as an integer if
534
+ **
535
+ ** (1) the round-trip conversion real->int->real is a no-op, and
536
+ ** (2) The integer is neither the largest nor the smallest
537
+ ** possible integer (ticket #3922)
538
+ **
539
+ ** The second and third terms in the following conditional enforces
540
+ ** the second condition under the assumption that addition overflow causes
541
+ ** values to wrap around. On x86 hardware, the third term is always
542
+ ** true and could be omitted. But we leave it in because other
543
+ ** architectures might behave differently.
544
+ */
545
+ if ( pMem.r == (double)pMem.u.i && pMem.u.i > SMALLEST_INT64
546
+ && ALWAYS( pMem.u.i < LARGEST_INT64 ) )
547
+ {
548
+ pMem.flags |= MEM_Int;
549
+ }
550
+ }
551
+
552
+ /*
553
+ ** Convert pMem to type integer. Invalidate any prior representations.
554
+ */
555
+ static int sqlite3VdbeMemIntegerify( Mem pMem )
556
+ {
557
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
558
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
559
+ //assert( EIGHT_BYTE_ALIGNMENT(pMem) );
560
+
561
+ pMem.u.i = sqlite3VdbeIntValue( pMem );
562
+ MemSetTypeFlag( pMem, MEM_Int );
563
+ return SQLITE_OK;
564
+ }
565
+
566
+ /*
567
+ ** Convert pMem so that it is of type MEM_Real.
568
+ ** Invalidate any prior representations.
569
+ */
570
+ static int sqlite3VdbeMemRealify( Mem pMem )
571
+ {
572
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
573
+ //assert( EIGHT_BYTE_ALIGNMENT(pMem) );
574
+
575
+ pMem.r = sqlite3VdbeRealValue( pMem );
576
+ MemSetTypeFlag( pMem, MEM_Real );
577
+ return SQLITE_OK;
578
+ }
579
+
580
+ /*
581
+ ** Convert pMem so that it has types MEM_Real or MEM_Int or both.
582
+ ** Invalidate any prior representations.
583
+ **
584
+ ** Every effort is made to force the conversion, even if the input
585
+ ** is a string that does not look completely like a number. Convert
586
+ ** as much of the string as we can and ignore the rest.
587
+ */
588
+ static int sqlite3VdbeMemNumerify( Mem pMem )
589
+ {
590
+ int rc;
591
+ Debug.Assert( ( pMem.flags & ( MEM_Int | MEM_Real | MEM_Null ) ) == 0 );
592
+ Debug.Assert( ( pMem.flags & ( MEM_Blob | MEM_Str ) ) != 0 );
593
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
594
+ rc = sqlite3VdbeChangeEncoding( pMem, SQLITE_UTF8 );
595
+ if ( rc != 0 ) return rc;
596
+ rc = sqlite3VdbeMemNulTerminate( pMem );
597
+ if ( rc !=0) return rc;
598
+ if ( sqlite3Atoi64( pMem.z, ref pMem.u.i ) )
599
+ {
600
+ MemSetTypeFlag( pMem, MEM_Int );
601
+ }
602
+ else
603
+ {
604
+ pMem.r = sqlite3VdbeRealValue( pMem );
605
+ MemSetTypeFlag( pMem, MEM_Real );
606
+ sqlite3VdbeIntegerAffinity( pMem );
607
+ }
608
+ return SQLITE_OK;
609
+ }
610
+
611
+ #if !SQLITE_OMIT_FLOATING_POINT
612
+ /*
613
+ ** Delete any previous value and set the value stored in pMem to NULL.
614
+ */
615
+ static void sqlite3VdbeMemSetNull( Mem pMem )
616
+ {
617
+ if ( ( pMem.flags & MEM_Frame ) != 0 )
618
+ {
619
+ sqlite3VdbeFrameDelete( pMem.u.pFrame );
620
+ }
621
+ if ( ( pMem.flags & MEM_RowSet ) != 0 )
622
+ {
623
+ sqlite3RowSetClear( pMem.u.pRowSet );
624
+ }
625
+ MemSetTypeFlag( pMem, MEM_Null );
626
+ sqlite3_free(ref pMem.zBLOB );
627
+ pMem.z = null;
628
+ pMem.type = SQLITE_NULL;
629
+ }
630
+ #endif
631
+
632
+ /*
633
+ ** Delete any previous value and set the value to be a BLOB of length
634
+ ** n containing all zeros.
635
+ */
636
+ static void sqlite3VdbeMemSetZeroBlob( Mem pMem, int n )
637
+ {
638
+ sqlite3VdbeMemRelease( pMem );
639
+ pMem.flags = MEM_Blob | MEM_Zero;
640
+ pMem.type = SQLITE_BLOB;
641
+ pMem.n = 0;
642
+ if ( n < 0 ) n = 0;
643
+ pMem.u.nZero = n;
644
+ pMem.enc = SQLITE_UTF8;
645
+ #if SQLITE_OMIT_INCRBLOB
646
+ sqlite3VdbeMemGrow( pMem, n, 0 );
647
+ //if( pMem.z!= null ){
648
+ pMem.n = n;
649
+ pMem.z = null;//memset(pMem.z, 0, n);
650
+ pMem.zBLOB = sqlite3Malloc(n);
651
+ //}
652
+ #endif
653
+ }
654
+
655
+ /*
656
+ ** Delete any previous value and set the value stored in pMem to val,
657
+ ** manifest type INTEGER.
658
+ */
659
+ static void sqlite3VdbeMemSetInt64( Mem pMem, i64 val )
660
+ {
661
+ sqlite3VdbeMemRelease( pMem );
662
+ pMem.u.i = val;
663
+ pMem.flags = MEM_Int;
664
+ pMem.type = SQLITE_INTEGER;
665
+ }
666
+
667
+ /*
668
+ ** Delete any previous value and set the value stored in pMem to val,
669
+ ** manifest type REAL.
670
+ */
671
+ static void sqlite3VdbeMemSetDouble( Mem pMem, double val )
672
+ {
673
+ if ( sqlite3IsNaN( val ) )
674
+ {
675
+ sqlite3VdbeMemSetNull( pMem );
676
+ }
677
+ else
678
+ {
679
+ sqlite3VdbeMemRelease( pMem );
680
+ pMem.r = val;
681
+ pMem.flags = MEM_Real;
682
+ pMem.type = SQLITE_FLOAT;
683
+ }
684
+ }
685
+
686
+ /*
687
+ ** Delete any previous value and set the value of pMem to be an
688
+ ** empty boolean index.
689
+ */
690
+ static void sqlite3VdbeMemSetRowSet( Mem pMem )
691
+ {
692
+ sqlite3 db = pMem.db;
693
+ Debug.Assert( db != null );
694
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
695
+ sqlite3VdbeMemRelease( pMem );
696
+ //pMem.zMalloc = sqlite3DbMallocRaw( db, 64 );
697
+ //if ( db.mallocFailed != 0 )
698
+ //{
699
+ // pMem.flags = MEM_Null;
700
+ //}
701
+ //else
702
+ {
703
+ //Debug.Assert( pMem.zMalloc );
704
+ pMem.u.pRowSet = new RowSet( db, 5 );// sqlite3RowSetInit( db, pMem.zMalloc,
705
+ // sqlite3DbMallocSize( db, pMem.zMalloc ) );
706
+ Debug.Assert( pMem.u.pRowSet != null );
707
+ pMem.flags = MEM_RowSet;
708
+ }
709
+ }
710
+
711
+ /*
712
+ ** Return true if the Mem object contains a TEXT or BLOB that is
713
+ ** too large - whose size exceeds p.db.aLimit[SQLITE_LIMIT_LENGTH].
714
+ */
715
+ static bool sqlite3VdbeMemTooBig( Mem p )
716
+ {
717
+ //Debug.Assert( p.db != null );
718
+ if ( ( p.flags & ( MEM_Str | MEM_Blob ) ) != 0 )
719
+ {
720
+ int n = p.n;
721
+ if ( ( p.flags & MEM_Zero ) != 0 )
722
+ {
723
+ n += p.u.nZero;
724
+ }
725
+ return n > p.db.aLimit[SQLITE_LIMIT_LENGTH];
726
+ }
727
+ return false;
728
+ }
729
+
730
+ /*
731
+ ** Size of struct Mem not including the Mem.zMalloc member.
732
+ */
733
+ //#define MEMCELLSIZE (size_t)(&(((Mem *)0).zMalloc))
734
+
735
+ /*
736
+ ** Make an shallow copy of pFrom into pTo. Prior contents of
737
+ ** pTo are freed. The pFrom.z field is not duplicated. If
738
+ ** pFrom.z is used, then pTo.z points to the same thing as pFrom.z
739
+ ** and flags gets srcType (either MEM_Ephem or MEM_Static).
740
+ */
741
+ static void sqlite3VdbeMemShallowCopy( Mem pTo, Mem pFrom, int srcType )
742
+ {
743
+ Debug.Assert( ( pFrom.flags & MEM_RowSet ) == 0 );
744
+ sqlite3VdbeMemReleaseExternal( pTo );
745
+ pFrom.CopyTo( pTo );// memcpy(pTo, pFrom, MEMCELLSIZE);
746
+ pTo.xDel = null;
747
+ if ((pFrom.flags & MEM_Static) != 0)
748
+ {
749
+ pTo.flags = (u16)( pFrom.flags & ~( MEM_Dyn | MEM_Static | MEM_Ephem ) );
750
+ Debug.Assert( srcType == MEM_Ephem || srcType == MEM_Static );
751
+ pTo.flags |= (u16)srcType;
752
+ }
753
+ }
754
+
755
+ /*
756
+ ** Make a full copy of pFrom into pTo. Prior contents of pTo are
757
+ ** freed before the copy is made.
758
+ */
759
+ static int sqlite3VdbeMemCopy( Mem pTo, Mem pFrom )
760
+ {
761
+ int rc = SQLITE_OK;
762
+
763
+ Debug.Assert( ( pFrom.flags & MEM_RowSet ) == 0 );
764
+ sqlite3VdbeMemReleaseExternal( pTo );
765
+ pFrom.CopyTo( pTo );// memcpy(pTo, pFrom, MEMCELLSIZE);
766
+ pTo.flags = (u16)( pTo.flags & ~MEM_Dyn );
767
+
768
+ if ( ( pTo.flags & ( MEM_Str | MEM_Blob ) ) != 0 )
769
+ {
770
+ if ( 0 == ( pFrom.flags & MEM_Static ) )
771
+ {
772
+ pTo.flags |= MEM_Ephem;
773
+ rc = sqlite3VdbeMemMakeWriteable( pTo );
774
+ }
775
+ }
776
+
777
+ return rc;
778
+ }
779
+
780
+
781
+
782
+
783
+ /*
784
+ ** Transfer the contents of pFrom to pTo. Any existing value in pTo is
785
+ ** freed. If pFrom contains ephemeral data, a copy is made.
786
+ **
787
+ ** pFrom contains an SQL NULL when this routine returns.
788
+ */
789
+ static void sqlite3VdbeMemMove( Mem pTo, Mem pFrom )
790
+ {
791
+ Debug.Assert( pFrom.db == null || sqlite3_mutex_held( pFrom.db.mutex ) );
792
+ Debug.Assert( pTo.db == null || sqlite3_mutex_held( pTo.db.mutex ) );
793
+ Debug.Assert( pFrom.db == null || pTo.db == null || pFrom.db == pTo.db );
794
+ sqlite3VdbeMemRelease( pTo );
795
+ pFrom.CopyTo( pTo );// memcpy(pTo, pFrom, Mem).Length;
796
+ pFrom.flags = MEM_Null;
797
+ pFrom.xDel = null;
798
+ pFrom.z = null;
799
+ sqlite3_free(ref pFrom.zBLOB ); //pFrom.zMalloc=0;
800
+ }
801
+
802
+ /*
803
+ ** Change the value of a Mem to be a string or a BLOB.
804
+ **
805
+ ** The memory management strategy depends on the value of the xDel
806
+ ** parameter. If the value passed is SQLITE_TRANSIENT, then the
807
+ ** string is copied into a (possibly existing) buffer managed by the
808
+ ** Mem structure. Otherwise, any existing buffer is freed and the
809
+ ** pointer copied.
810
+ **
811
+ ** If the string is too large (if it exceeds the SQLITE_LIMIT_LENGTH
812
+ ** size limit) then no memory allocation occurs. If the string can be
813
+ ** stored without allocating memory, then it is. If a memory allocation
814
+ ** is required to store the string, then value of pMem is unchanged. In
815
+ ** either case, SQLITE_TOOBIG is returned.
816
+ */
817
+ static int sqlite3VdbeMemSetBlob(
818
+ Mem pMem, /* Memory cell to set to string value */
819
+ byte[] zBlob, /* Blob pointer */
820
+ int n, /* Bytes in Blob */
821
+ u8 enc, /* 0 for BLOBs */
822
+ dxDel xDel /* Destructor function */
823
+ )
824
+ { return sqlite3VdbeMemSetBlob(pMem, zBlob, 0, n >= 0 ? n : zBlob.Length, enc, xDel); } // Call w/o offset
825
+
826
+ static int sqlite3VdbeMemSetBlob(
827
+ Mem pMem, /* Memory cell to set to string value */
828
+ byte[] zBlob, /* Blob pointer */
829
+ int offset, /* offset into string */
830
+ int n, /* Bytes in string, or negative */
831
+ u8 enc, /* Encoding of z. 0 for BLOBs */
832
+ dxDel xDel//)(void*)/* Destructor function */
833
+ )
834
+ {
835
+ int nByte = n; /* New value for pMem->n */
836
+ int iLimit; /* Maximum allowed string or blob size */
837
+
838
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
839
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
840
+
841
+ /* If zBlob is a NULL pointer, set pMem to contain an SQL NULL. */
842
+ if ( zBlob == null || zBlob.Length < offset )
843
+ {
844
+ sqlite3VdbeMemSetNull( pMem );
845
+ return SQLITE_OK;
846
+ }
847
+
848
+ if ( pMem.db != null )
849
+ {
850
+ iLimit = pMem.db.aLimit[SQLITE_LIMIT_LENGTH];
851
+ }
852
+ else
853
+ {
854
+ iLimit = SQLITE_MAX_LENGTH;
855
+ }
856
+ if ( nByte < 0 )
857
+ {
858
+ Debug.Assert( enc != 0 );
859
+ if ( enc == SQLITE_UTF8 )
860
+ {
861
+ for ( nByte = 0; nByte <= iLimit && nByte < zBlob.Length - offset && zBlob[offset + nByte] != 0; nByte++ ) { }
862
+ }
863
+ else
864
+ {
865
+ for ( nByte = 0; nByte <= iLimit && zBlob[nByte + offset] != 0 || zBlob[offset + nByte + 1] != 0; nByte += 2 ) { }
866
+ }
867
+ }
868
+
869
+ /* The following block sets the new values of Mem.z and Mem.xDel. It
870
+ ** also sets a flag in local variable "flags" to indicate the memory
871
+ ** management (one of MEM_Dyn or MEM_Static).
872
+ */
873
+ Debug.Assert( enc == 0 );
874
+ {
875
+ pMem.z = null;
876
+ pMem.zBLOB = sqlite3Malloc( n );
877
+ Buffer.BlockCopy(zBlob,offset,pMem.zBLOB,0,n);
878
+ }
879
+ pMem.n = nByte;
880
+ pMem.flags = MEM_Blob | MEM_Term;
881
+ pMem.enc = ( enc == 0 ? SQLITE_UTF8 : enc );
882
+ pMem.type = ( enc == 0 ? SQLITE_BLOB : SQLITE_TEXT );
883
+
884
+ if ( nByte > iLimit )
885
+ {
886
+ return SQLITE_TOOBIG;
887
+ }
888
+
889
+ return SQLITE_OK;
890
+ }
891
+
892
+ static int sqlite3VdbeMemSetStr(
893
+ Mem pMem, /* Memory cell to set to string value */
894
+ string z, /* String pointer */
895
+ int n, /* Bytes in string, or negative */
896
+ u8 enc, /* Encoding of z. 0 for BLOBs */
897
+ dxDel xDel /* Destructor function */
898
+ )
899
+ { return sqlite3VdbeMemSetStr( pMem, z, 0, n, enc, xDel ); } // Call w/o offset
900
+
901
+ static int sqlite3VdbeMemSetStr(
902
+ Mem pMem, /* Memory cell to set to string value */
903
+ string z, /* String pointer */
904
+ int offset, /* offset into string */
905
+ int n, /* Bytes in string, or negative */
906
+ u8 enc, /* Encoding of z. 0 for BLOBs */
907
+ dxDel xDel//)(void*)/* Destructor function */
908
+ )
909
+ {
910
+ int nByte = n; /* New value for pMem->n */
911
+ int iLimit; /* Maximum allowed string or blob size */
912
+ u16 flags = 0; /* New value for pMem->flags */
913
+
914
+ Debug.Assert( pMem.db == null || sqlite3_mutex_held( pMem.db.mutex ) );
915
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
916
+
917
+ /* If z is a NULL pointer, set pMem to contain an SQL NULL. */
918
+ if ( z == null || z.Length < offset )
919
+ {
920
+ sqlite3VdbeMemSetNull( pMem );
921
+ return SQLITE_OK;
922
+ }
923
+
924
+ if ( pMem.db != null )
925
+ {
926
+ iLimit = pMem.db.aLimit[SQLITE_LIMIT_LENGTH];
927
+ }
928
+ else
929
+ {
930
+ iLimit = SQLITE_MAX_LENGTH;
931
+ }
932
+ flags = (u16)( enc == 0 ? MEM_Blob : MEM_Str );
933
+ if ( nByte < 0 )
934
+ {
935
+ Debug.Assert( enc != 0 );
936
+ if ( enc == SQLITE_UTF8 )
937
+ {
938
+ for ( nByte = 0; nByte <= iLimit && nByte < z.Length - offset && z[offset + nByte] != 0; nByte++ ) { }
939
+ }
940
+ else
941
+ {
942
+ for ( nByte = 0; nByte <= iLimit && z[nByte + offset] != 0 || z[offset + nByte + 1] != 0; nByte += 2 ) { }
943
+ }
944
+ flags |= MEM_Term;
945
+ }
946
+
947
+ /* The following block sets the new values of Mem.z and Mem.xDel. It
948
+ ** also sets a flag in local variable "flags" to indicate the memory
949
+ ** management (one of MEM_Dyn or MEM_Static).
950
+ */
951
+ if ( xDel == SQLITE_TRANSIENT )
952
+ {
953
+ u32 nAlloc = (u32)nByte;
954
+ if ( ( flags & MEM_Term ) != 0 )
955
+ {
956
+ nAlloc += (u32)( enc == SQLITE_UTF8 ? 1 : 2 );
957
+ }
958
+ if ( nByte > iLimit )
959
+ {
960
+ return SQLITE_TOOBIG;
961
+ }
962
+ if ( sqlite3VdbeMemGrow( pMem, (int)nAlloc, 0 ) != 0 )
963
+ {
964
+ return SQLITE_NOMEM;
965
+ }
966
+ //if ( nAlloc < z.Length )
967
+ //{ pMem.z = new byte[nAlloc]; Buffer.BlockCopy( z, 0, pMem.z, 0, (int)nAlloc ); }
968
+ //else
969
+ if ( enc == 0 )
970
+ {
971
+ pMem.z = null;
972
+ pMem.zBLOB = sqlite3Malloc(n);
973
+ for ( int i = 0; i < n && i < z.Length - offset; i++ ) pMem.zBLOB[i] = (byte)z[offset + i];
974
+ }
975
+ else
976
+ {
977
+ pMem.z = n > 0 && z.Length - offset > n ? z.Substring( offset, n ) : z.Substring( offset );//memcpy(pMem.z, z, nAlloc);
978
+ sqlite3_free(ref pMem.zBLOB );
979
+ }
980
+ }
981
+ else if ( xDel == SQLITE_DYNAMIC )
982
+ {
983
+ sqlite3VdbeMemRelease( pMem );
984
+ //pMem.zMalloc = pMem.z = (char*)z;
985
+ if ( enc == 0 )
986
+ {
987
+ pMem.z = null;
988
+ if (pMem.zBLOB != null) sqlite3_free(ref pMem.zBLOB );
989
+ pMem.zBLOB = Encoding.UTF8.GetBytes( offset == 0 ? z : z.Length + offset < n ? z.Substring( offset, n ) : z.Substring( offset ) );
990
+ }
991
+ else
992
+ {
993
+ pMem.z = n > 0 && z.Length - offset > n ? z.Substring( offset, n ) : z.Substring( offset );//memcpy(pMem.z, z, nAlloc);
994
+ sqlite3_free(ref pMem.zBLOB );
995
+ }
996
+ pMem.xDel = null;
997
+ }
998
+ else
999
+ {
1000
+ sqlite3VdbeMemRelease( pMem );
1001
+ if ( enc == 0 )
1002
+ {
1003
+ pMem.z = null;
1004
+ if (pMem.zBLOB != null) sqlite3_free(ref pMem.zBLOB);
1005
+ pMem.zBLOB = Encoding.UTF8.GetBytes(offset == 0 ? z : z.Length + offset < n ? z.Substring(offset, n) : z.Substring(offset));
1006
+ }
1007
+ else
1008
+ {
1009
+ pMem.z = n > 0 && z.Length - offset > n ? z.Substring( offset, n ) : z.Substring( offset );//memcpy(pMem.z, z, nAlloc);
1010
+ sqlite3_free(ref pMem.zBLOB );
1011
+ }
1012
+ pMem.xDel = xDel;
1013
+ flags |= (u16)( ( xDel == SQLITE_STATIC ) ? MEM_Static : MEM_Dyn );
1014
+ }
1015
+ pMem.n = nByte;
1016
+ pMem.flags = flags;
1017
+ pMem.enc = ( enc == 0 ? SQLITE_UTF8 : enc );
1018
+ pMem.type = ( enc == 0 ? SQLITE_BLOB : SQLITE_TEXT );
1019
+
1020
+ #if !SQLITE_OMIT_UTF16
1021
+ if( pMem.enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem)!=0 ){
1022
+ return SQLITE_NOMEM;
1023
+ }
1024
+ #endif
1025
+
1026
+ if ( nByte > iLimit )
1027
+ {
1028
+ return SQLITE_TOOBIG;
1029
+ }
1030
+
1031
+ return SQLITE_OK;
1032
+ }
1033
+
1034
+ /*
1035
+ ** Compare the values contained by the two memory cells, returning
1036
+ ** negative, zero or positive if pMem1 is less than, equal to, or greater
1037
+ ** than pMem2. Sorting order is NULL's first, followed by numbers (integers
1038
+ ** and reals) sorted numerically, followed by text ordered by the collating
1039
+ ** sequence pColl and finally blob's ordered by memcmp().
1040
+ **
1041
+ ** Two NULL values are considered equal by this function.
1042
+ */
1043
+ static int sqlite3MemCompare( Mem pMem1, Mem pMem2, CollSeq pColl )
1044
+ {
1045
+ int rc;
1046
+ int f1, f2;
1047
+ int combined_flags;
1048
+
1049
+ f1 = pMem1.flags;
1050
+ f2 = pMem2.flags;
1051
+ combined_flags = f1 | f2;
1052
+ //TODO Debug.Assert( ( combined_flags & MEM_RowSet ) == 0 );
1053
+
1054
+ /* If one value is NULL, it is less than the other. If both values
1055
+ ** are NULL, return 0.
1056
+ */
1057
+ if ( ( combined_flags & MEM_Null ) != 0 )
1058
+ {
1059
+ return ( f2 & MEM_Null ) - ( f1 & MEM_Null );
1060
+ }
1061
+
1062
+ /* If one value is a number and the other is not, the number is less.
1063
+ ** If both are numbers, compare as reals if one is a real, or as integers
1064
+ ** if both values are integers.
1065
+ */
1066
+ if ( ( combined_flags & ( MEM_Int | MEM_Real ) ) != 0 )
1067
+ {
1068
+ if ( ( f1 & ( MEM_Int | MEM_Real ) ) == 0 )
1069
+ {
1070
+ return 1;
1071
+ }
1072
+ if ( ( f2 & ( MEM_Int | MEM_Real ) ) == 0 )
1073
+ {
1074
+ return -1;
1075
+ }
1076
+ if ( ( f1 & f2 & MEM_Int ) == 0 )
1077
+ {
1078
+ double r1, r2;
1079
+ if ( ( f1 & MEM_Real ) == 0 )
1080
+ {
1081
+ r1 = (double)pMem1.u.i;
1082
+ }
1083
+ else
1084
+ {
1085
+ r1 = pMem1.r;
1086
+ }
1087
+ if ( ( f2 & MEM_Real ) == 0 )
1088
+ {
1089
+ r2 = (double)pMem2.u.i;
1090
+ }
1091
+ else
1092
+ {
1093
+ r2 = pMem2.r;
1094
+ }
1095
+ if ( r1 < r2 ) return -1;
1096
+ if ( r1 > r2 ) return 1;
1097
+ return 0;
1098
+ }
1099
+ else
1100
+ {
1101
+ Debug.Assert( ( f1 & MEM_Int ) != 0 );
1102
+ Debug.Assert( ( f2 & MEM_Int ) != 0 );
1103
+ if ( pMem1.u.i < pMem2.u.i ) return -1;
1104
+ if ( pMem1.u.i > pMem2.u.i ) return 1;
1105
+ return 0;
1106
+ }
1107
+ }
1108
+
1109
+ /* If one value is a string and the other is a blob, the string is less.
1110
+ ** If both are strings, compare using the collating functions.
1111
+ */
1112
+ if ( ( combined_flags & MEM_Str ) != 0 )
1113
+ {
1114
+ if ( ( f1 & MEM_Str ) == 0 )
1115
+ {
1116
+ return 1;
1117
+ }
1118
+ if ( ( f2 & MEM_Str ) == 0 )
1119
+ {
1120
+ return -1;
1121
+ }
1122
+
1123
+ Debug.Assert( pMem1.enc == pMem2.enc );
1124
+ Debug.Assert( pMem1.enc == SQLITE_UTF8 ||
1125
+ pMem1.enc == SQLITE_UTF16LE || pMem1.enc == SQLITE_UTF16BE );
1126
+
1127
+ /* The collation sequence must be defined at this point, even if
1128
+ ** the user deletes the collation sequence after the vdbe program is
1129
+ ** compiled (this was not always the case).
1130
+ */
1131
+ Debug.Assert( pColl == null || pColl.xCmp != null );
1132
+
1133
+ if ( pColl != null )
1134
+ {
1135
+ if ( pMem1.enc == pColl.enc )
1136
+ {
1137
+ /* The strings are already in the correct encoding. Call the
1138
+ ** comparison function directly */
1139
+ return pColl.xCmp( pColl.pUser, pMem1.n, pMem1.z, pMem2.n, pMem2.z );
1140
+ }
1141
+ else
1142
+ {
1143
+ string v1, v2;
1144
+ int n1, n2;
1145
+ Mem c1 = null;
1146
+ Mem c2 = null;
1147
+
1148
+ c1 = sqlite3Malloc( c1 );// memset( &c1, 0, sizeof( c1 ) );
1149
+ c2 = sqlite3Malloc( c2 );// memset( &c2, 0, sizeof( c2 ) );
1150
+
1151
+ sqlite3VdbeMemShallowCopy( c1, pMem1, MEM_Ephem );
1152
+ sqlite3VdbeMemShallowCopy( c2, pMem2, MEM_Ephem );
1153
+ v1 = sqlite3ValueText( (sqlite3_value)c1, pColl.enc );
1154
+ n1 = v1 == null ? 0 : c1.n;
1155
+ v2 = sqlite3ValueText( (sqlite3_value)c2, pColl.enc );
1156
+ n2 = v2 == null ? 0 : c2.n;
1157
+ rc = pColl.xCmp( pColl.pUser, n1, v1, n2, v2 );
1158
+ sqlite3VdbeMemRelease( c1 );
1159
+ sqlite3VdbeMemRelease( c2 );
1160
+ return rc;
1161
+ }
1162
+ }
1163
+ /* If a NULL pointer was passed as the collate function, fall through
1164
+ ** to the blob case and use memcmp(). */
1165
+ }
1166
+
1167
+ /* Both values must be blobs. Compare using memcmp(). */
1168
+ if ( ( pMem1.flags & MEM_Blob ) != 0 )
1169
+ if ( pMem1.zBLOB != null ) rc = memcmp( pMem1.zBLOB, pMem2.zBLOB, ( pMem1.n > pMem2.n ) ? pMem2.n : pMem1.n );
1170
+ else rc = memcmp( pMem1.z, pMem2.zBLOB, ( pMem1.n > pMem2.n ) ? pMem2.n : pMem1.n );
1171
+ else
1172
+ rc = memcmp( pMem1.z, pMem2.z, ( pMem1.n > pMem2.n ) ? pMem2.n : pMem1.n );
1173
+ if ( rc == 0 )
1174
+ {
1175
+ rc = pMem1.n - pMem2.n;
1176
+ }
1177
+ return rc;
1178
+ }
1179
+
1180
+ /*
1181
+ ** Move data out of a btree key or data field and into a Mem structure.
1182
+ ** The data or key is taken from the entry that pCur is currently pointing
1183
+ ** to. offset and amt determine what portion of the data or key to retrieve.
1184
+ ** key is true to get the key or false to get data. The result is written
1185
+ ** into the pMem element.
1186
+ **
1187
+ ** The pMem structure is assumed to be uninitialized. Any prior content
1188
+ ** is overwritten without being freed.
1189
+ **
1190
+ ** If this routine fails for any reason (malloc returns NULL or unable
1191
+ ** to read from the disk) then the pMem is left in an inconsistent state.
1192
+ */
1193
+ static int sqlite3VdbeMemFromBtree(
1194
+ BtCursor pCur, /* Cursor pointing at record to retrieve. */
1195
+ int offset, /* Offset from the start of data to return bytes from. */
1196
+ int amt, /* Number of bytes to return. */
1197
+ bool key, /* If true, retrieve from the btree key, not data. */
1198
+ Mem pMem /* OUT: Return data in this Mem structure. */
1199
+ )
1200
+ {
1201
+ byte[] zData; /* Data from the btree layer */
1202
+ int available = 0; /* Number of bytes available on the local btree page */
1203
+ int rc = SQLITE_OK; /* Return code */
1204
+
1205
+ Debug.Assert( sqlite3BtreeCursorIsValid( pCur ) );
1206
+
1207
+ /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
1208
+ ** that both the BtShared and database handle mutexes are held. */
1209
+ Debug.Assert( ( pMem.flags & MEM_RowSet ) == 0 );
1210
+ int outOffset = -1;
1211
+ if ( key )
1212
+ {
1213
+ zData = sqlite3BtreeKeyFetch( pCur, ref available, ref outOffset );
1214
+ }
1215
+ else
1216
+ {
1217
+ zData = sqlite3BtreeDataFetch( pCur, ref available, ref outOffset );
1218
+ }
1219
+ Debug.Assert( zData != null );
1220
+
1221
+ if ( offset + amt <= available && ( pMem.flags & MEM_Dyn ) == 0 )
1222
+ {
1223
+ sqlite3VdbeMemRelease( pMem );
1224
+ pMem.zBLOB = sqlite3Malloc(amt);
1225
+ Buffer.BlockCopy( zData, offset, pMem.zBLOB, 0, amt );//pMem.z = &zData[offset];
1226
+ pMem.flags = MEM_Blob | MEM_Ephem;
1227
+ }
1228
+ else if ( SQLITE_OK == ( rc = sqlite3VdbeMemGrow( pMem, amt + 2, 0 ) ) )
1229
+ {
1230
+ pMem.enc = 0;
1231
+ pMem.type = SQLITE_BLOB;
1232
+ pMem.z = null;
1233
+ pMem.zBLOB = sqlite3Malloc(amt);
1234
+ pMem.flags = MEM_Blob | MEM_Dyn | MEM_Term;
1235
+ if ( key )
1236
+ {
1237
+ rc = sqlite3BtreeKey( pCur, (u32)offset, (u32)amt, pMem.zBLOB );
1238
+ }
1239
+ else
1240
+ {
1241
+ rc = sqlite3BtreeData( pCur, (u32)offset, (u32)amt, pMem.zBLOB );//pMem.z = pMem_z ;
1242
+ }
1243
+ //pMem.z[amt] = 0;
1244
+ //pMem.z[amt+1] = 0;
1245
+ if ( rc != SQLITE_OK )
1246
+ {
1247
+ sqlite3VdbeMemRelease( pMem );
1248
+ }
1249
+ }
1250
+ pMem.n = amt;
1251
+ sqlite3_free(ref zData);
1252
+
1253
+ return rc;
1254
+ }
1255
+
1256
+ /* This function is only available internally, it is not part of the
1257
+ ** external API. It works in a similar way to sqlite3_value_text(),
1258
+ ** except the data returned is in the encoding specified by the second
1259
+ ** parameter, which must be one of SQLITE_UTF16BE, SQLITE_UTF16LE or
1260
+ ** SQLITE_UTF8.
1261
+ **
1262
+ ** (2006-02-16:) The enc value can be or-ed with SQLITE_UTF16_ALIGNED.
1263
+ ** If that is the case, then the result must be aligned on an even byte
1264
+ ** boundary.
1265
+ */
1266
+ static string sqlite3ValueText( sqlite3_value pVal, int enc )
1267
+ {
1268
+ if ( pVal == null ) return null;
1269
+
1270
+ Debug.Assert( pVal.db == null || sqlite3_mutex_held( pVal.db.mutex ) );
1271
+ Debug.Assert( ( enc & 3 ) == ( enc & ~SQLITE_UTF16_ALIGNED ) );
1272
+ Debug.Assert( ( pVal.flags & MEM_RowSet ) == 0 );
1273
+
1274
+ if ( ( pVal.flags & MEM_Null ) != 0 )
1275
+ {
1276
+ return null;
1277
+ }
1278
+ Debug.Assert( ( MEM_Blob >> 3 ) == MEM_Str );
1279
+ pVal.flags |= (u16)( ( pVal.flags & MEM_Blob ) >> 3 );
1280
+ if ( ( pVal.flags & MEM_Zero ) != 0 ) sqlite3VdbeMemExpandBlob( pVal ); // expandBlob(pVal);
1281
+ if ( ( pVal.flags & MEM_Str ) != 0 )
1282
+ {
1283
+ sqlite3VdbeChangeEncoding( pVal, enc & ~SQLITE_UTF16_ALIGNED );
1284
+ if ( ( enc & SQLITE_UTF16_ALIGNED ) != 0 && 1 == ( 1 & ( pVal.z[0] ) ) ) //1==(1&SQLITE_PTR_TO_INT(pVal.z))
1285
+ {
1286
+ Debug.Assert( ( pVal.flags & ( MEM_Ephem | MEM_Static ) ) != 0 );
1287
+ if ( sqlite3VdbeMemMakeWriteable( pVal ) != SQLITE_OK )
1288
+ {
1289
+ return null;
1290
+ }
1291
+ }
1292
+ sqlite3VdbeMemNulTerminate( pVal );
1293
+ }
1294
+ else
1295
+ {
1296
+ Debug.Assert( ( pVal.flags & MEM_Blob ) == 0 );
1297
+ sqlite3VdbeMemStringify( pVal, enc );
1298
+ // assert( 0==(1&SQLITE_PTR_TO_INT(pVal->z)) );
1299
+ }
1300
+ Debug.Assert( pVal.enc == ( enc & ~SQLITE_UTF16_ALIGNED ) || pVal.db == null
1301
+ //|| pVal.db.mallocFailed != 0
1302
+ );
1303
+ if ( pVal.enc == ( enc & ~SQLITE_UTF16_ALIGNED ) )
1304
+ {
1305
+ return pVal.z;
1306
+ }
1307
+ else
1308
+ {
1309
+ return null;
1310
+ }
1311
+ }
1312
+
1313
+ /*
1314
+ ** Create a new sqlite3_value object.
1315
+ */
1316
+ static sqlite3_value sqlite3ValueNew( sqlite3 db )
1317
+ {
1318
+ Mem p = null;
1319
+ p = sqlite3DbMallocZero( db, p );
1320
+ //if ( p != null )
1321
+ //{
1322
+ p.flags = MEM_Null;
1323
+ p.type = SQLITE_NULL;
1324
+ p.db = db;
1325
+ //}
1326
+ return p;
1327
+ }
1328
+
1329
+ /*
1330
+ ** Create a new sqlite3_value object, containing the value of pExpr.
1331
+ **
1332
+ ** This only works for very simple expressions that consist of one constant
1333
+ ** token (i.e. "5", "5.1", "'a string'"). If the expression can
1334
+ ** be converted directly into a value, then the value is allocated and
1335
+ ** a pointer written to ppVal. The caller is responsible for deallocating
1336
+ ** the value by passing it to sqlite3ValueFree() later on. If the expression
1337
+ ** cannot be converted to a value, then ppVal is set to NULL.
1338
+ */
1339
+ static int sqlite3ValueFromExpr(
1340
+ sqlite3 db, /* The database connection */
1341
+ Expr pExpr, /* The expression to evaluate */
1342
+ int enc, /* Encoding to use */
1343
+ char affinity, /* Affinity to use */
1344
+ ref sqlite3_value ppVal /* Write the new value here */
1345
+ )
1346
+ {
1347
+ int op;
1348
+ string zVal = "";
1349
+ sqlite3_value pVal = null;
1350
+
1351
+ if ( pExpr == null )
1352
+ {
1353
+ ppVal = null;
1354
+ return SQLITE_OK;
1355
+ }
1356
+ op = pExpr.op;
1357
+ if ( op == TK_REGISTER )
1358
+ {
1359
+ op = pExpr.op2; /* This only happens with SQLITE_ENABLE_STAT2 */
1360
+ }
1361
+
1362
+ if ( op == TK_STRING || op == TK_FLOAT || op == TK_INTEGER )
1363
+ {
1364
+ pVal = sqlite3ValueNew( db );
1365
+ if ( pVal == null ) goto no_mem;
1366
+ if ( ExprHasProperty( pExpr, EP_IntValue ) )
1367
+ {
1368
+ sqlite3VdbeMemSetInt64( pVal, (i64)pExpr.u.iValue );
1369
+ }
1370
+ else
1371
+ {
1372
+ zVal = pExpr.u.zToken;// sqlite3DbStrDup( db, pExpr.u.zToken );
1373
+ //if ( zVal == null ) goto no_mem;
1374
+ sqlite3ValueSetStr( pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC );
1375
+ if ( op == TK_FLOAT ) pVal.type = SQLITE_FLOAT;
1376
+ }
1377
+ if ( ( op == TK_INTEGER || op == TK_FLOAT ) && affinity == SQLITE_AFF_NONE )
1378
+ {
1379
+ sqlite3ValueApplyAffinity( pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8 );
1380
+ }
1381
+ else
1382
+ {
1383
+ sqlite3ValueApplyAffinity( pVal, affinity, SQLITE_UTF8 );
1384
+ }
1385
+ if ( enc != SQLITE_UTF8 )
1386
+ {
1387
+ sqlite3VdbeChangeEncoding( pVal, enc );
1388
+ }
1389
+ }
1390
+ if ( enc != SQLITE_UTF8 )
1391
+ {
1392
+ sqlite3VdbeChangeEncoding( pVal, enc );
1393
+ }
1394
+ else if ( op == TK_UMINUS )
1395
+ {
1396
+ if ( SQLITE_OK == sqlite3ValueFromExpr( db, pExpr.pLeft, enc, affinity, ref pVal ) )
1397
+ {
1398
+ pVal.u.i = -1 * pVal.u.i;
1399
+ /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
1400
+ pVal.r = (double)-1 * pVal.r;
1401
+ }
1402
+ }
1403
+ #if !SQLITE_OMIT_BLOB_LITERAL
1404
+ else if ( op == TK_BLOB )
1405
+ {
1406
+ int nVal;
1407
+ Debug.Assert( pExpr.u.zToken[0] == 'x' || pExpr.u.zToken[0] == 'X' );
1408
+ Debug.Assert( pExpr.u.zToken[1] == '\'' );
1409
+ pVal = sqlite3ValueNew( db );
1410
+ if ( null == pVal ) goto no_mem;
1411
+ zVal = pExpr.u.zToken.Substring( 2 );
1412
+ nVal = sqlite3Strlen30( zVal ) - 1;
1413
+ Debug.Assert( zVal[nVal] == '\'' );
1414
+ byte[] blob = sqlite3HexToBlob(db, zVal, nVal);
1415
+ sqlite3VdbeMemSetStr(pVal, Encoding.UTF8.GetString(blob, 0, blob.Length), nVal / 2, 0, SQLITE_DYNAMIC);
1416
+ }
1417
+ #endif
1418
+
1419
+ if ( pVal != null )
1420
+ {
1421
+ sqlite3VdbeMemStoreType( pVal );
1422
+ }
1423
+
1424
+ ppVal = pVal;
1425
+ return SQLITE_OK;
1426
+
1427
+ no_mem:
1428
+ //db.mallocFailed = 1;
1429
+ sqlite3DbFree( db, ref zVal );
1430
+ pVal = null;// sqlite3ValueFree(pVal);
1431
+ ppVal = null;
1432
+ return SQLITE_NOMEM;
1433
+ }
1434
+
1435
+ /*
1436
+ ** Change the string value of an sqlite3_value object
1437
+ */
1438
+ static void sqlite3ValueSetStr(
1439
+ sqlite3_value v, /* Value to be set */
1440
+ int n, /* Length of string z */
1441
+ string z, /* Text of the new string */
1442
+ u8 enc, /* Encoding to use */
1443
+ dxDel xDel//)(void*) /* Destructor for the string */
1444
+ )
1445
+ {
1446
+ if ( v != null ) sqlite3VdbeMemSetStr( v, z, n, enc, xDel );
1447
+ }
1448
+
1449
+ /*
1450
+ ** Free an sqlite3_value object
1451
+ */
1452
+ static void sqlite3ValueFree( ref sqlite3_value v )
1453
+ {
1454
+ if ( v == null ) return;
1455
+ sqlite3VdbeMemRelease( v );
1456
+ sqlite3DbFree( v.db, ref v );
1457
+ }
1458
+
1459
+ /*
1460
+ ** Return the number of bytes in the sqlite3_value object assuming
1461
+ ** that it uses the encoding "enc"
1462
+ */
1463
+ static int sqlite3ValueBytes( sqlite3_value pVal, int enc )
1464
+ {
1465
+ Mem p = (Mem)pVal;
1466
+ if ( ( p.flags & MEM_Blob ) != 0 || sqlite3ValueText( pVal, enc ) != null )
1467
+ {
1468
+ if ( ( p.flags & MEM_Zero ) != 0 )
1469
+ {
1470
+ return p.n + p.u.nZero;
1471
+ }
1472
+ else
1473
+ {
1474
+ return p.z == null ? p.zBLOB.Length : p.n;
1475
+ }
1476
+ }
1477
+ return 0;
1478
+ }
1479
+ }
1480
+ }