Add files using upload-large-folder tool
Browse files- local-test-freerdp-full-01/afc-freerdp/client/iOS/Controllers/EditorSelectionController.h +34 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/FreeRDP/ios_cliprdr.h +34 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/FreeRDP/ios_freerdp.m +443 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/FreeRDP/ios_freerdp_events.h +27 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/FreeRDP/ios_freerdp_events.m +174 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/Bookmark.m +312 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/ConnectionParams.h +46 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/ConnectionParams.m +258 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/GlobalDefaults.h +30 -0
- local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/GlobalDefaults.m +88 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/fts5/fts5.h +739 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/fts5/fts5_storage.c +1512 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/fts5/fts5_test_tok.c +484 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/fts5/mkportersteps.tcl +222 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/dbdata.c +1020 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recover1.test +377 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recoverclobber.test +50 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recovercorrupt.test +67 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recovercorrupt4.test +63 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recoverfault2.test +102 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recoverrowid.test +50 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/test_recover.c +309 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree.c +0 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree.h +30 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree1.test +818 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree4.test +254 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree6.test +183 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree7.test +73 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree8.test +209 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree9.test +129 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeA.test +262 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeC.test +378 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeE.test +143 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeG.test +69 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeH.test +103 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeI.test +74 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeJ.test +273 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree_util.tcl +197 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreecheck.test +204 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreecirc.test +66 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreedoc.test +1593 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreedoc2.test +346 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreedoc3.test +292 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreefuzz001.test +1211 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/test_rtreedoc.c +344 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/tkt3363.test +50 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/viewrtree.tcl +188 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/visual01.txt +602 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/wasm/api/sqlite3-wasm.c +1950 -0
- local-test-sqlite3-delta-03/afc-sqlite3/ext/wasm/sql/001-sudoku.sql +28 -0
local-test-freerdp-full-01/afc-freerdp/client/iOS/Controllers/EditorSelectionController.h
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Generic controller to select a single item from a list of options
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#import "EditorBaseController.h"
|
| 12 |
+
|
| 13 |
+
@class ConnectionParams;
|
| 14 |
+
|
| 15 |
+
@interface EditorSelectionController : EditorBaseController
|
| 16 |
+
{
|
| 17 |
+
ConnectionParams *_params;
|
| 18 |
+
|
| 19 |
+
// array with entries in connection parameters that are altered
|
| 20 |
+
NSArray *_entries;
|
| 21 |
+
|
| 22 |
+
// array with dictionaries containing label/value pairs that represent the available values for
|
| 23 |
+
// each entry
|
| 24 |
+
NSArray *_selections;
|
| 25 |
+
|
| 26 |
+
// current selections
|
| 27 |
+
NSMutableArray *_cur_selections;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
- (id)initWithConnectionParams:(ConnectionParams *)params
|
| 31 |
+
entries:(NSArray *)entries
|
| 32 |
+
selections:(NSArray *)selections;
|
| 33 |
+
|
| 34 |
+
@end
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/FreeRDP/ios_cliprdr.h
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* FreeRDP: A Remote Desktop Protocol Implementation
|
| 3 |
+
* Android Clipboard Redirection
|
| 4 |
+
*
|
| 5 |
+
* Copyright 2013 Felix Long
|
| 6 |
+
* Copyright 2023 Iordan Iordanov
|
| 7 |
+
*
|
| 8 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 9 |
+
* you may not use this file except in compliance with the License.
|
| 10 |
+
* You may obtain a copy of the License at
|
| 11 |
+
*
|
| 12 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 13 |
+
*
|
| 14 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 15 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 16 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 17 |
+
* See the License for the specific language governing permissions and
|
| 18 |
+
* limitations under the License.
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#ifndef FREERDP_CLIENT_IOS_CLIPRDR_H
|
| 22 |
+
#define FREERDP_CLIENT_IOS_CLIPRDR_H
|
| 23 |
+
|
| 24 |
+
#include <freerdp/client/cliprdr.h>
|
| 25 |
+
#include <freerdp/api.h>
|
| 26 |
+
|
| 27 |
+
#include "ios_freerdp.h"
|
| 28 |
+
|
| 29 |
+
FREERDP_LOCAL UINT ios_cliprdr_send_client_format_list(CliprdrClientContext* cliprdr);
|
| 30 |
+
|
| 31 |
+
FREERDP_LOCAL BOOL ios_cliprdr_init(mfContext* context, CliprdrClientContext* cliprdr);
|
| 32 |
+
FREERDP_LOCAL BOOL ios_cliprdr_uninit(mfContext* context, CliprdrClientContext* cliprdr);
|
| 33 |
+
|
| 34 |
+
#endif /* FREERDP_CLIENT_IOS_CLIPRDR_H */
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/FreeRDP/ios_freerdp.m
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
RDP run-loop
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Authors: Martin Fleisz, Dorian Johnson
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <winpr/assert.h>
|
| 12 |
+
#import <winpr/clipboard.h>
|
| 13 |
+
|
| 14 |
+
#import <freerdp/gdi/gdi.h>
|
| 15 |
+
#import <freerdp/channels/channels.h>
|
| 16 |
+
#import <freerdp/client/channels.h>
|
| 17 |
+
#import <freerdp/client/cmdline.h>
|
| 18 |
+
#import <freerdp/freerdp.h>
|
| 19 |
+
#import <freerdp/gdi/gfx.h>
|
| 20 |
+
#import <freerdp/client/cliprdr.h>
|
| 21 |
+
|
| 22 |
+
#import "ios_freerdp.h"
|
| 23 |
+
#import "ios_freerdp_ui.h"
|
| 24 |
+
#import "ios_freerdp_events.h"
|
| 25 |
+
#import "ios_cliprdr.h"
|
| 26 |
+
|
| 27 |
+
#import "RDPSession.h"
|
| 28 |
+
#import "Utils.h"
|
| 29 |
+
|
| 30 |
+
#include <errno.h>
|
| 31 |
+
|
| 32 |
+
#define TAG FREERDP_TAG("iOS")
|
| 33 |
+
|
| 34 |
+
#pragma mark Connection helpers
|
| 35 |
+
|
| 36 |
+
static void ios_OnChannelConnectedEventHandler(void *context, const ChannelConnectedEventArgs *e)
|
| 37 |
+
{
|
| 38 |
+
WLog_INFO(TAG, "ios_OnChannelConnectedEventHandler, channel %s", e->name);
|
| 39 |
+
rdpSettings *settings;
|
| 40 |
+
mfContext *afc;
|
| 41 |
+
|
| 42 |
+
if (!context || !e)
|
| 43 |
+
{
|
| 44 |
+
WLog_FATAL(TAG, "(context=%p, EventArgs=%p", context, (void *)e);
|
| 45 |
+
return;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
afc = (mfContext *)context;
|
| 49 |
+
settings = afc->_p.settings;
|
| 50 |
+
|
| 51 |
+
if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
|
| 52 |
+
{
|
| 53 |
+
if (freerdp_settings_get_bool(settings, FreeRDP_SoftwareGdi))
|
| 54 |
+
{
|
| 55 |
+
gdi_graphics_pipeline_init(afc->_p.gdi, (RdpgfxClientContext *)e->pInterface);
|
| 56 |
+
}
|
| 57 |
+
else
|
| 58 |
+
{
|
| 59 |
+
WLog_WARN(TAG, "GFX without software GDI requested. "
|
| 60 |
+
" This is not supported, add /gdi:sw");
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
|
| 64 |
+
{
|
| 65 |
+
ios_cliprdr_init(afc, (CliprdrClientContext *)e->pInterface);
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
static void ios_OnChannelDisconnectedEventHandler(void *context,
|
| 70 |
+
const ChannelDisconnectedEventArgs *e)
|
| 71 |
+
{
|
| 72 |
+
WLog_INFO(TAG, "ios_OnChannelConnectedEventHandler, channel %s", e->name);
|
| 73 |
+
rdpSettings *settings;
|
| 74 |
+
mfContext *afc;
|
| 75 |
+
|
| 76 |
+
if (!context || !e)
|
| 77 |
+
{
|
| 78 |
+
WLog_FATAL(TAG, "(context=%p, EventArgs=%p", context, (void *)e);
|
| 79 |
+
return;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
afc = (mfContext *)context;
|
| 83 |
+
settings = afc->_p.settings;
|
| 84 |
+
|
| 85 |
+
if (strcmp(e->name, RDPGFX_DVC_CHANNEL_NAME) == 0)
|
| 86 |
+
{
|
| 87 |
+
if (freerdp_settings_get_bool(settings, FreeRDP_SoftwareGdi))
|
| 88 |
+
{
|
| 89 |
+
gdi_graphics_pipeline_uninit(afc->_p.gdi, (RdpgfxClientContext *)e->pInterface);
|
| 90 |
+
}
|
| 91 |
+
else
|
| 92 |
+
{
|
| 93 |
+
WLog_WARN(TAG, "GFX without software GDI requested. "
|
| 94 |
+
" This is not supported, add /gdi:sw");
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
else if (strcmp(e->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
|
| 98 |
+
{
|
| 99 |
+
ios_cliprdr_uninit(afc, (CliprdrClientContext *)e->pInterface);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
static BOOL ios_pre_connect(freerdp *instance)
|
| 104 |
+
{
|
| 105 |
+
int rc;
|
| 106 |
+
rdpSettings *settings;
|
| 107 |
+
|
| 108 |
+
if (!instance || !instance->context)
|
| 109 |
+
return FALSE;
|
| 110 |
+
|
| 111 |
+
settings = instance->context->settings;
|
| 112 |
+
WINPR_ASSERT(settings);
|
| 113 |
+
|
| 114 |
+
const char *Password = freerdp_settings_get_string(settings, FreeRDP_Password);
|
| 115 |
+
if (!freerdp_settings_set_bool(settings, FreeRDP_AutoLogonEnabled,
|
| 116 |
+
Password && (Password && (strlen(Password) > 0))))
|
| 117 |
+
return FALSE;
|
| 118 |
+
|
| 119 |
+
// Verify screen width/height are sane
|
| 120 |
+
if ((freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) < 64) ||
|
| 121 |
+
(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) < 64) ||
|
| 122 |
+
(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) > 4096) ||
|
| 123 |
+
(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) > 4096))
|
| 124 |
+
{
|
| 125 |
+
NSLog(@"%s: invalid dimensions %d %d", __func__,
|
| 126 |
+
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
|
| 127 |
+
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
|
| 128 |
+
return FALSE;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
rc = PubSub_SubscribeChannelConnected(instance->context->pubSub,
|
| 132 |
+
ios_OnChannelConnectedEventHandler);
|
| 133 |
+
|
| 134 |
+
if (rc != CHANNEL_RC_OK)
|
| 135 |
+
{
|
| 136 |
+
WLog_ERR(TAG, "Could not subscribe to connect event handler [%l08X]", rc);
|
| 137 |
+
return FALSE;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
rc = PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
|
| 141 |
+
ios_OnChannelDisconnectedEventHandler);
|
| 142 |
+
|
| 143 |
+
if (rc != CHANNEL_RC_OK)
|
| 144 |
+
{
|
| 145 |
+
WLog_ERR(TAG, "Could not subscribe to disconnect event handler [%l08X]", rc);
|
| 146 |
+
return FALSE;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
if (!freerdp_client_load_addins(instance->context->channels, settings))
|
| 150 |
+
{
|
| 151 |
+
WLog_ERR(TAG, "Failed to load addins [%l08X]", GetLastError());
|
| 152 |
+
return FALSE;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
return TRUE;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
static BOOL ios_Pointer_New(rdpContext *context, rdpPointer *pointer)
|
| 159 |
+
{
|
| 160 |
+
if (!context || !pointer || !context->gdi)
|
| 161 |
+
return FALSE;
|
| 162 |
+
|
| 163 |
+
return TRUE;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
static void ios_Pointer_Free(rdpContext *context, rdpPointer *pointer)
|
| 167 |
+
{
|
| 168 |
+
if (!context || !pointer)
|
| 169 |
+
return;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
static BOOL ios_Pointer_Set(rdpContext *context, rdpPointer *pointer)
|
| 173 |
+
{
|
| 174 |
+
if (!context)
|
| 175 |
+
return FALSE;
|
| 176 |
+
|
| 177 |
+
return TRUE;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
static BOOL ios_Pointer_SetPosition(rdpContext *context, UINT32 x, UINT32 y)
|
| 181 |
+
{
|
| 182 |
+
if (!context)
|
| 183 |
+
return FALSE;
|
| 184 |
+
|
| 185 |
+
return TRUE;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
static BOOL ios_Pointer_SetNull(rdpContext *context)
|
| 189 |
+
{
|
| 190 |
+
if (!context)
|
| 191 |
+
return FALSE;
|
| 192 |
+
|
| 193 |
+
return TRUE;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
static BOOL ios_Pointer_SetDefault(rdpContext *context)
|
| 197 |
+
{
|
| 198 |
+
if (!context)
|
| 199 |
+
return FALSE;
|
| 200 |
+
|
| 201 |
+
return TRUE;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
static BOOL ios_register_pointer(rdpGraphics *graphics)
|
| 205 |
+
{
|
| 206 |
+
rdpPointer pointer = { 0 };
|
| 207 |
+
|
| 208 |
+
if (!graphics)
|
| 209 |
+
return FALSE;
|
| 210 |
+
|
| 211 |
+
pointer.size = sizeof(pointer);
|
| 212 |
+
pointer.New = ios_Pointer_New;
|
| 213 |
+
pointer.Free = ios_Pointer_Free;
|
| 214 |
+
pointer.Set = ios_Pointer_Set;
|
| 215 |
+
pointer.SetNull = ios_Pointer_SetNull;
|
| 216 |
+
pointer.SetDefault = ios_Pointer_SetDefault;
|
| 217 |
+
pointer.SetPosition = ios_Pointer_SetPosition;
|
| 218 |
+
graphics_register_pointer(graphics, &pointer);
|
| 219 |
+
return TRUE;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
static BOOL ios_post_connect(freerdp *instance)
|
| 223 |
+
{
|
| 224 |
+
mfInfo *mfi;
|
| 225 |
+
|
| 226 |
+
if (!instance)
|
| 227 |
+
return FALSE;
|
| 228 |
+
|
| 229 |
+
mfi = MFI_FROM_INSTANCE(instance);
|
| 230 |
+
|
| 231 |
+
if (!mfi)
|
| 232 |
+
return FALSE;
|
| 233 |
+
|
| 234 |
+
if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
|
| 235 |
+
return FALSE;
|
| 236 |
+
|
| 237 |
+
if (!ios_register_pointer(instance->context->graphics))
|
| 238 |
+
return FALSE;
|
| 239 |
+
|
| 240 |
+
ios_allocate_display_buffer(mfi);
|
| 241 |
+
instance->context->update->BeginPaint = ios_ui_begin_paint;
|
| 242 |
+
instance->context->update->EndPaint = ios_ui_end_paint;
|
| 243 |
+
instance->context->update->DesktopResize = ios_ui_resize_window;
|
| 244 |
+
[mfi->session performSelectorOnMainThread:@selector(sessionDidConnect)
|
| 245 |
+
withObject:nil
|
| 246 |
+
waitUntilDone:YES];
|
| 247 |
+
return TRUE;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
static void ios_post_disconnect(freerdp *instance)
|
| 251 |
+
{
|
| 252 |
+
gdi_free(instance);
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
#pragma mark -
|
| 256 |
+
#pragma mark Running the connection
|
| 257 |
+
|
| 258 |
+
int ios_run_freerdp(freerdp *instance)
|
| 259 |
+
{
|
| 260 |
+
mfContext *context = (mfContext *)instance->context;
|
| 261 |
+
mfInfo *mfi = context->mfi;
|
| 262 |
+
rdpChannels *channels = instance->context->channels;
|
| 263 |
+
mfi->connection_state = TSXConnectionConnecting;
|
| 264 |
+
|
| 265 |
+
if (!freerdp_connect(instance))
|
| 266 |
+
{
|
| 267 |
+
NSLog(@"%s: inst->rdp_connect failed", __func__);
|
| 268 |
+
return mfi->unwanted ? MF_EXIT_CONN_CANCELED : MF_EXIT_CONN_FAILED;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
if (mfi->unwanted)
|
| 272 |
+
return MF_EXIT_CONN_CANCELED;
|
| 273 |
+
|
| 274 |
+
mfi->connection_state = TSXConnectionConnected;
|
| 275 |
+
// Connection main loop
|
| 276 |
+
NSAutoreleasePool *pool;
|
| 277 |
+
|
| 278 |
+
while (!freerdp_shall_disconnect_context(instance->context))
|
| 279 |
+
{
|
| 280 |
+
DWORD status;
|
| 281 |
+
DWORD nCount = 0;
|
| 282 |
+
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
|
| 283 |
+
pool = [[NSAutoreleasePool alloc] init];
|
| 284 |
+
|
| 285 |
+
nCount = freerdp_get_event_handles(instance->context, handles, ARRAYSIZE(handles));
|
| 286 |
+
if (nCount == 0)
|
| 287 |
+
{
|
| 288 |
+
NSLog(@"%s: freerdp_get_event_handles failed", __func__);
|
| 289 |
+
break;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
handles[nCount++] = ios_events_get_handle(mfi);
|
| 293 |
+
|
| 294 |
+
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
|
| 295 |
+
|
| 296 |
+
if (WAIT_FAILED == status)
|
| 297 |
+
{
|
| 298 |
+
NSLog(@"%s: WaitForMultipleObjects failed!", __func__);
|
| 299 |
+
break;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
// Check the libfreerdp fds
|
| 303 |
+
if (!freerdp_check_event_handles(instance->context))
|
| 304 |
+
{
|
| 305 |
+
NSLog(@"%s: freerdp_check_event_handles failed.", __func__);
|
| 306 |
+
break;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// Check input event fds
|
| 310 |
+
if (ios_events_check_handle(mfi) != TRUE)
|
| 311 |
+
{
|
| 312 |
+
// This event will fail when the app asks for a disconnect.
|
| 313 |
+
// NSLog(@"%s: ios_events_check_fds failed: terminating connection.", __func__);
|
| 314 |
+
break;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
[pool release];
|
| 318 |
+
pool = nil;
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
CGContextRelease(mfi->bitmap_context);
|
| 322 |
+
mfi->bitmap_context = NULL;
|
| 323 |
+
mfi->connection_state = TSXConnectionDisconnected;
|
| 324 |
+
// Cleanup
|
| 325 |
+
freerdp_disconnect(instance);
|
| 326 |
+
gdi_free(instance);
|
| 327 |
+
cache_free(instance->context->cache);
|
| 328 |
+
[pool release];
|
| 329 |
+
pool = nil;
|
| 330 |
+
return MF_EXIT_SUCCESS;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
#pragma mark -
|
| 334 |
+
#pragma mark Context callbacks
|
| 335 |
+
|
| 336 |
+
static BOOL ios_client_new(freerdp *instance, rdpContext *context)
|
| 337 |
+
{
|
| 338 |
+
mfContext *ctx = (mfContext *)context;
|
| 339 |
+
|
| 340 |
+
if (!instance || !context)
|
| 341 |
+
return FALSE;
|
| 342 |
+
|
| 343 |
+
if ((ctx->mfi = calloc(1, sizeof(mfInfo))) == NULL)
|
| 344 |
+
return FALSE;
|
| 345 |
+
|
| 346 |
+
ctx->mfi->context = (mfContext *)context;
|
| 347 |
+
ctx->mfi->_context = context;
|
| 348 |
+
ctx->mfi->instance = instance;
|
| 349 |
+
|
| 350 |
+
if (!ios_events_create_pipe(ctx->mfi))
|
| 351 |
+
return FALSE;
|
| 352 |
+
|
| 353 |
+
instance->PreConnect = ios_pre_connect;
|
| 354 |
+
instance->PostConnect = ios_post_connect;
|
| 355 |
+
instance->PostDisconnect = ios_post_disconnect;
|
| 356 |
+
instance->Authenticate = ios_ui_authenticate;
|
| 357 |
+
instance->GatewayAuthenticate = ios_ui_gw_authenticate;
|
| 358 |
+
instance->VerifyCertificateEx = ios_ui_verify_certificate_ex;
|
| 359 |
+
instance->VerifyChangedCertificateEx = ios_ui_verify_changed_certificate_ex;
|
| 360 |
+
instance->LogonErrorInfo = NULL;
|
| 361 |
+
return TRUE;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
static void ios_client_free(freerdp *instance, rdpContext *context)
|
| 365 |
+
{
|
| 366 |
+
mfInfo *mfi;
|
| 367 |
+
|
| 368 |
+
if (!context)
|
| 369 |
+
return;
|
| 370 |
+
|
| 371 |
+
mfi = ((mfContext *)context)->mfi;
|
| 372 |
+
ios_events_free_pipe(mfi);
|
| 373 |
+
free(mfi);
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
static int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS *pEntryPoints)
|
| 377 |
+
{
|
| 378 |
+
WINPR_ASSERT(pEntryPoints);
|
| 379 |
+
|
| 380 |
+
ZeroMemory(pEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
|
| 381 |
+
pEntryPoints->Version = RDP_CLIENT_INTERFACE_VERSION;
|
| 382 |
+
pEntryPoints->Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1);
|
| 383 |
+
pEntryPoints->GlobalInit = NULL;
|
| 384 |
+
pEntryPoints->GlobalUninit = NULL;
|
| 385 |
+
pEntryPoints->ContextSize = sizeof(mfContext);
|
| 386 |
+
pEntryPoints->ClientNew = ios_client_new;
|
| 387 |
+
pEntryPoints->ClientFree = ios_client_free;
|
| 388 |
+
pEntryPoints->ClientStart = NULL;
|
| 389 |
+
pEntryPoints->ClientStop = NULL;
|
| 390 |
+
return 0;
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
#pragma mark -
|
| 394 |
+
#pragma mark Initialization and cleanup
|
| 395 |
+
|
| 396 |
+
freerdp *ios_freerdp_new()
|
| 397 |
+
{
|
| 398 |
+
rdpContext *context;
|
| 399 |
+
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
|
| 400 |
+
RdpClientEntry(&clientEntryPoints);
|
| 401 |
+
context = freerdp_client_context_new(&clientEntryPoints);
|
| 402 |
+
|
| 403 |
+
if (!context)
|
| 404 |
+
return NULL;
|
| 405 |
+
|
| 406 |
+
return context->instance;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
void ios_freerdp_free(freerdp *instance)
|
| 410 |
+
{
|
| 411 |
+
if (!instance || !instance->context)
|
| 412 |
+
return;
|
| 413 |
+
|
| 414 |
+
freerdp_client_context_free(instance->context);
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
void ios_init_freerdp()
|
| 418 |
+
{
|
| 419 |
+
signal(SIGPIPE, SIG_IGN);
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
void ios_uninit_freerdp()
|
| 423 |
+
{
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
/* compatibility functions */
|
| 427 |
+
size_t fwrite$UNIX2003(const void *ptr, size_t size, size_t nmemb, FILE *stream)
|
| 428 |
+
{
|
| 429 |
+
return fwrite(ptr, size, nmemb, stream);
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
void ios_send_clipboard_data(void *context, const void *data, UINT32 size)
|
| 433 |
+
{
|
| 434 |
+
mfContext *afc = (mfContext *)context;
|
| 435 |
+
ClipboardLock(afc->clipboard);
|
| 436 |
+
UINT32 formatId = ClipboardRegisterFormat(afc->clipboard, "UTF8_STRING");
|
| 437 |
+
if (size)
|
| 438 |
+
ClipboardSetData(afc->clipboard, formatId, data, size);
|
| 439 |
+
else
|
| 440 |
+
ClipboardEmpty(afc->clipboard);
|
| 441 |
+
ClipboardUnlock(afc->clipboard);
|
| 442 |
+
ios_cliprdr_send_client_format_list(afc->cliprdr);
|
| 443 |
+
}
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/FreeRDP/ios_freerdp_events.h
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
RDP event queuing
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Dorian Johnson
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#ifndef IOS_RDP_EVENT_H
|
| 12 |
+
#define IOS_RDP_EVENT_H
|
| 13 |
+
|
| 14 |
+
#import <Foundation/Foundation.h>
|
| 15 |
+
#import "ios_freerdp.h"
|
| 16 |
+
|
| 17 |
+
// For UI: use to send events
|
| 18 |
+
BOOL ios_events_send(mfInfo *mfi, NSDictionary *event_description);
|
| 19 |
+
|
| 20 |
+
// For connection runloop: use to poll for queued input events
|
| 21 |
+
HANDLE ios_events_get_handle(mfInfo *mfi);
|
| 22 |
+
BOOL ios_events_check_handle(mfInfo *mfi);
|
| 23 |
+
|
| 24 |
+
BOOL ios_events_create_pipe(mfInfo *mfi);
|
| 25 |
+
void ios_events_free_pipe(mfInfo *mfi);
|
| 26 |
+
|
| 27 |
+
#endif /* IOS_RDP_EVENT_H */
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/FreeRDP/ios_freerdp_events.m
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
RDP event queuing
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Dorian Johnson
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <winpr/assert.h>
|
| 12 |
+
|
| 13 |
+
#include "ios_freerdp_events.h"
|
| 14 |
+
|
| 15 |
+
#pragma mark -
|
| 16 |
+
#pragma mark Sending compacted input events (from main thread)
|
| 17 |
+
|
| 18 |
+
// While this function may be called from any thread that has an autorelease pool allocated, it is
|
| 19 |
+
// not threadsafe: caller is responsible for synchronization
|
| 20 |
+
BOOL ios_events_send(mfInfo *mfi, NSDictionary *event_description)
|
| 21 |
+
{
|
| 22 |
+
NSData *encoded_description = [NSKeyedArchiver archivedDataWithRootObject:event_description];
|
| 23 |
+
|
| 24 |
+
WINPR_ASSERT(mfi);
|
| 25 |
+
|
| 26 |
+
if ([encoded_description length] > 32000 || (mfi->event_pipe_producer == -1))
|
| 27 |
+
return FALSE;
|
| 28 |
+
|
| 29 |
+
uint32_t archived_data_len = (uint32_t)[encoded_description length];
|
| 30 |
+
|
| 31 |
+
// NSLog(@"writing %d bytes to input event pipe", archived_data_len);
|
| 32 |
+
|
| 33 |
+
if (write(mfi->event_pipe_producer, &archived_data_len, 4) == -1)
|
| 34 |
+
{
|
| 35 |
+
NSLog(@"%s: Failed to write length descriptor to pipe.", __func__);
|
| 36 |
+
return FALSE;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if (write(mfi->event_pipe_producer, [encoded_description bytes], archived_data_len) == -1)
|
| 40 |
+
{
|
| 41 |
+
NSLog(@"%s: Failed to write %d bytes into the event queue (event type: %@).", __func__,
|
| 42 |
+
(int)[encoded_description length], [event_description objectForKey:@"type"]);
|
| 43 |
+
return FALSE;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return TRUE;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
#pragma mark -
|
| 50 |
+
#pragma mark Processing compacted input events (from connection thread runloop)
|
| 51 |
+
|
| 52 |
+
static BOOL ios_events_handle_event(mfInfo *mfi, NSDictionary *event_description)
|
| 53 |
+
{
|
| 54 |
+
NSString *event_type = [event_description objectForKey:@"type"];
|
| 55 |
+
BOOL should_continue = TRUE;
|
| 56 |
+
rdpInput *input;
|
| 57 |
+
|
| 58 |
+
WINPR_ASSERT(mfi);
|
| 59 |
+
|
| 60 |
+
freerdp *instance = mfi->instance;
|
| 61 |
+
WINPR_ASSERT(instance);
|
| 62 |
+
WINPR_ASSERT(instance->context);
|
| 63 |
+
|
| 64 |
+
input = instance->context->input;
|
| 65 |
+
WINPR_ASSERT(input);
|
| 66 |
+
|
| 67 |
+
if ([event_type isEqualToString:@"mouse"])
|
| 68 |
+
{
|
| 69 |
+
input->MouseEvent(input, [[event_description objectForKey:@"flags"] unsignedShortValue],
|
| 70 |
+
[[event_description objectForKey:@"coord_x"] unsignedShortValue],
|
| 71 |
+
[[event_description objectForKey:@"coord_y"] unsignedShortValue]);
|
| 72 |
+
}
|
| 73 |
+
else if ([event_type isEqualToString:@"keyboard"])
|
| 74 |
+
{
|
| 75 |
+
if ([[event_description objectForKey:@"subtype"] isEqualToString:@"scancode"])
|
| 76 |
+
freerdp_input_send_keyboard_event(
|
| 77 |
+
input, [[event_description objectForKey:@"flags"] unsignedShortValue],
|
| 78 |
+
[[event_description objectForKey:@"scancode"] unsignedShortValue]);
|
| 79 |
+
else if ([[event_description objectForKey:@"subtype"] isEqualToString:@"unicode"])
|
| 80 |
+
freerdp_input_send_unicode_keyboard_event(
|
| 81 |
+
input, [[event_description objectForKey:@"flags"] unsignedShortValue],
|
| 82 |
+
[[event_description objectForKey:@"unicode_char"] unsignedShortValue]);
|
| 83 |
+
else
|
| 84 |
+
NSLog(@"%s: doesn't know how to send keyboard input with subtype %@", __func__,
|
| 85 |
+
[event_description objectForKey:@"subtype"]);
|
| 86 |
+
}
|
| 87 |
+
else if ([event_type isEqualToString:@"disconnect"])
|
| 88 |
+
should_continue = FALSE;
|
| 89 |
+
else
|
| 90 |
+
NSLog(@"%s: unrecognized event type: %@", __func__, event_type);
|
| 91 |
+
|
| 92 |
+
return should_continue;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
BOOL ios_events_check_handle(mfInfo *mfi)
|
| 96 |
+
{
|
| 97 |
+
WINPR_ASSERT(mfi);
|
| 98 |
+
|
| 99 |
+
if (WaitForSingleObject(mfi->handle, 0) != WAIT_OBJECT_0)
|
| 100 |
+
return TRUE;
|
| 101 |
+
|
| 102 |
+
if (mfi->event_pipe_consumer == -1)
|
| 103 |
+
return TRUE;
|
| 104 |
+
|
| 105 |
+
uint32_t archived_data_length = 0;
|
| 106 |
+
ssize_t bytes_read;
|
| 107 |
+
|
| 108 |
+
// First, read the length of the blob
|
| 109 |
+
bytes_read = read(mfi->event_pipe_consumer, &archived_data_length, 4);
|
| 110 |
+
|
| 111 |
+
if (bytes_read == -1 || archived_data_length < 1 || archived_data_length > 32000)
|
| 112 |
+
{
|
| 113 |
+
NSLog(@"%s: just read length descriptor. bytes_read=%ld, archived_data_length=%u", __func__,
|
| 114 |
+
bytes_read, archived_data_length);
|
| 115 |
+
return FALSE;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// NSLog(@"reading %d bytes from input event pipe", archived_data_length);
|
| 119 |
+
|
| 120 |
+
NSMutableData *archived_object_data =
|
| 121 |
+
[[NSMutableData alloc] initWithLength:archived_data_length];
|
| 122 |
+
bytes_read =
|
| 123 |
+
read(mfi->event_pipe_consumer, [archived_object_data mutableBytes], archived_data_length);
|
| 124 |
+
|
| 125 |
+
if (bytes_read != archived_data_length)
|
| 126 |
+
{
|
| 127 |
+
NSLog(@"%s: attempted to read data; read %ld bytes but wanted %d bytes.", __func__,
|
| 128 |
+
bytes_read, archived_data_length);
|
| 129 |
+
[archived_object_data release];
|
| 130 |
+
return FALSE;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
id unarchived_object_data = [NSKeyedUnarchiver unarchiveObjectWithData:archived_object_data];
|
| 134 |
+
[archived_object_data release];
|
| 135 |
+
|
| 136 |
+
return ios_events_handle_event(mfi, unarchived_object_data);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
HANDLE ios_events_get_handle(mfInfo *mfi)
|
| 140 |
+
{
|
| 141 |
+
WINPR_ASSERT(mfi);
|
| 142 |
+
return mfi->handle;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
// Sets up the event pipe
|
| 146 |
+
BOOL ios_events_create_pipe(mfInfo *mfi)
|
| 147 |
+
{
|
| 148 |
+
int pipe_fds[2];
|
| 149 |
+
|
| 150 |
+
WINPR_ASSERT(mfi);
|
| 151 |
+
|
| 152 |
+
if (pipe(pipe_fds) == -1)
|
| 153 |
+
{
|
| 154 |
+
NSLog(@"%s: pipe failed.", __func__);
|
| 155 |
+
return FALSE;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
mfi->event_pipe_consumer = pipe_fds[0];
|
| 159 |
+
mfi->event_pipe_producer = pipe_fds[1];
|
| 160 |
+
mfi->handle = CreateFileDescriptorEvent(NULL, FALSE, FALSE, mfi->event_pipe_consumer,
|
| 161 |
+
WINPR_FD_READ | WINPR_FD_WRITE);
|
| 162 |
+
return TRUE;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
void ios_events_free_pipe(mfInfo *mfi)
|
| 166 |
+
{
|
| 167 |
+
WINPR_ASSERT(mfi);
|
| 168 |
+
int consumer_fd = mfi->event_pipe_consumer, producer_fd = mfi->event_pipe_producer;
|
| 169 |
+
|
| 170 |
+
mfi->event_pipe_consumer = mfi->event_pipe_producer = -1;
|
| 171 |
+
close(producer_fd);
|
| 172 |
+
close(consumer_fd);
|
| 173 |
+
(void)CloseHandle(mfi->handle);
|
| 174 |
+
}
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/Bookmark.m
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Bookmark model abstraction
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Dorian Johnson
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#import "Bookmark.h"
|
| 12 |
+
#import "TSXAdditions.h"
|
| 13 |
+
#import "Utils.h"
|
| 14 |
+
|
| 15 |
+
#import "GlobalDefaults.h"
|
| 16 |
+
|
| 17 |
+
@interface ComputerBookmark (Private)
|
| 18 |
+
- (void)willChangeValueForKeyPath:(NSString *)keyPath;
|
| 19 |
+
- (void)didChangeValueForKeyPath:(NSString *)keyPath;
|
| 20 |
+
@end
|
| 21 |
+
|
| 22 |
+
@implementation ComputerBookmark
|
| 23 |
+
|
| 24 |
+
@synthesize parent = _parent, uuid = _uuid, label = _label, image = _image;
|
| 25 |
+
@synthesize params = _connection_params, conntectedViaWLAN = _connected_via_wlan;
|
| 26 |
+
|
| 27 |
+
- (id)init
|
| 28 |
+
{
|
| 29 |
+
if (!(self = [super init]))
|
| 30 |
+
return nil;
|
| 31 |
+
|
| 32 |
+
_uuid = [[NSString stringWithUUID] retain];
|
| 33 |
+
_label = @"";
|
| 34 |
+
_connected_via_wlan = NO;
|
| 35 |
+
return self;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
// Designated initializer.
|
| 39 |
+
- (id)initWithConnectionParameters:(ConnectionParams *)params
|
| 40 |
+
{
|
| 41 |
+
if (!(self = [self init]))
|
| 42 |
+
return nil;
|
| 43 |
+
|
| 44 |
+
_connection_params = [params copy];
|
| 45 |
+
_connected_via_wlan = NO;
|
| 46 |
+
return self;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
- (id)initWithCoder:(NSCoder *)decoder
|
| 50 |
+
{
|
| 51 |
+
if (!(self = [self init]))
|
| 52 |
+
return nil;
|
| 53 |
+
|
| 54 |
+
if (![decoder allowsKeyedCoding])
|
| 55 |
+
[NSException raise:NSInvalidArgumentException format:@"coder must support keyed archiving"];
|
| 56 |
+
|
| 57 |
+
if ([decoder containsValueForKey:@"uuid"])
|
| 58 |
+
{
|
| 59 |
+
[_uuid release];
|
| 60 |
+
_uuid = [[decoder decodeObjectForKey:@"uuid"] retain];
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
if ([decoder containsValueForKey:@"label"])
|
| 64 |
+
[self setLabel:[decoder decodeObjectForKey:@"label"]];
|
| 65 |
+
|
| 66 |
+
if ([decoder containsValueForKey:@"connectionParams"])
|
| 67 |
+
{
|
| 68 |
+
[_connection_params release];
|
| 69 |
+
_connection_params = [[decoder decodeObjectForKey:@"connectionParams"] retain];
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
return self;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
- (id)initWithBaseDefaultParameters
|
| 76 |
+
{
|
| 77 |
+
return [self initWithConnectionParameters:[[[ConnectionParams alloc]
|
| 78 |
+
initWithBaseDefaultParameters] autorelease]];
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
- (id)copy
|
| 82 |
+
{
|
| 83 |
+
ComputerBookmark *copy = [[[self class] alloc] init];
|
| 84 |
+
[copy setLabel:[self label]];
|
| 85 |
+
copy->_connection_params = [_connection_params copy];
|
| 86 |
+
return copy;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
- (id)copyWithUUID
|
| 90 |
+
{
|
| 91 |
+
ComputerBookmark *copy = [self copy];
|
| 92 |
+
copy->_uuid = [[self uuid] copy];
|
| 93 |
+
return copy;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
- (void)encodeWithCoder:(NSCoder *)coder
|
| 97 |
+
{
|
| 98 |
+
if (![coder allowsKeyedCoding])
|
| 99 |
+
[NSException raise:NSInvalidArgumentException format:@"coder must support keyed archiving"];
|
| 100 |
+
|
| 101 |
+
[coder encodeObject:_uuid forKey:@"uuid"];
|
| 102 |
+
[coder encodeObject:_label forKey:@"label"];
|
| 103 |
+
[coder encodeObject:_connection_params forKey:@"connectionParams"];
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
- (void)dealloc
|
| 107 |
+
{
|
| 108 |
+
_parent = nil;
|
| 109 |
+
[_label release];
|
| 110 |
+
_label = nil;
|
| 111 |
+
[_uuid release];
|
| 112 |
+
_uuid = nil;
|
| 113 |
+
[_connection_params release];
|
| 114 |
+
_connection_params = nil;
|
| 115 |
+
[super dealloc];
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
- (UIImage *)image
|
| 119 |
+
{
|
| 120 |
+
return nil;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
- (BOOL)isEqual:(id)object
|
| 124 |
+
{
|
| 125 |
+
return [object respondsToSelector:@selector(uuid)] && [[object uuid] isEqual:_uuid];
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
- (NSString *)description
|
| 129 |
+
{
|
| 130 |
+
return ([self label] != nil) ? [self label] : _uuid;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
- (BOOL)validateValue:(id *)val forKey:(NSString *)key error:(NSError **)error
|
| 134 |
+
{
|
| 135 |
+
NSString *string_value = *val;
|
| 136 |
+
|
| 137 |
+
if ([key isEqualToString:@"label"])
|
| 138 |
+
{
|
| 139 |
+
if (![[string_value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]
|
| 140 |
+
length])
|
| 141 |
+
{
|
| 142 |
+
if (error)
|
| 143 |
+
*error = [NSError
|
| 144 |
+
errorWithDomain:@""
|
| 145 |
+
code:NSKeyValueValidationError
|
| 146 |
+
userInfo:
|
| 147 |
+
[NSDictionary
|
| 148 |
+
dictionaryWithObjectsAndKeys:
|
| 149 |
+
NSLocalizedString(
|
| 150 |
+
@"Connection labels cannot be blank",
|
| 151 |
+
@"Bookmark data validation: label blank title."),
|
| 152 |
+
NSLocalizedDescriptionKey,
|
| 153 |
+
NSLocalizedString(
|
| 154 |
+
@"Please enter the short description of this Connection "
|
| 155 |
+
@"that will appear in the Connection list.",
|
| 156 |
+
@"Bookmark data validation: label blank message."),
|
| 157 |
+
NSLocalizedRecoverySuggestionErrorKey, nil]];
|
| 158 |
+
return NO;
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
return YES;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
- (BOOL)validateValue:(id *)val forKeyPath:(NSString *)keyPath error:(NSError **)error
|
| 166 |
+
{
|
| 167 |
+
// Could be used to validate params.hostname, params.password, params.port, etc.
|
| 168 |
+
return [super validateValue:val forKeyPath:keyPath error:error];
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
- (BOOL)isDeletable
|
| 172 |
+
{
|
| 173 |
+
return YES;
|
| 174 |
+
}
|
| 175 |
+
- (BOOL)isMovable
|
| 176 |
+
{
|
| 177 |
+
return YES;
|
| 178 |
+
}
|
| 179 |
+
- (BOOL)isRenamable
|
| 180 |
+
{
|
| 181 |
+
return YES;
|
| 182 |
+
}
|
| 183 |
+
- (BOOL)hasImmutableHost
|
| 184 |
+
{
|
| 185 |
+
return NO;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
#pragma mark Custom KVC
|
| 189 |
+
|
| 190 |
+
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath
|
| 191 |
+
{
|
| 192 |
+
if ([keyPath isEqualToString:@"params.resolution"])
|
| 193 |
+
{
|
| 194 |
+
int width, height;
|
| 195 |
+
TSXScreenOptions type;
|
| 196 |
+
if (ScanScreenResolution(value, &width, &height, &type))
|
| 197 |
+
{
|
| 198 |
+
[_connection_params willChangeValueForKey:@"resolution"];
|
| 199 |
+
[[self params] setInt:type forKey:@"screen_resolution_type"];
|
| 200 |
+
|
| 201 |
+
if (type == TSXScreenOptionFixed)
|
| 202 |
+
{
|
| 203 |
+
[[self params] setInt:width forKey:@"width"];
|
| 204 |
+
[[self params] setInt:height forKey:@"height"];
|
| 205 |
+
}
|
| 206 |
+
[_connection_params didChangeValueForKey:@"resolution"];
|
| 207 |
+
}
|
| 208 |
+
else
|
| 209 |
+
[NSException raise:NSInvalidArgumentException
|
| 210 |
+
format:@"%s got invalid screen resolution '%@'", __func__, value];
|
| 211 |
+
}
|
| 212 |
+
else
|
| 213 |
+
{
|
| 214 |
+
[self willChangeValueForKeyPath:keyPath];
|
| 215 |
+
[super setValue:value forKeyPath:keyPath];
|
| 216 |
+
[self didChangeValueForKeyPath:keyPath];
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
- (id)valueForKeyPath:(NSString *)keyPath
|
| 221 |
+
{
|
| 222 |
+
if ([keyPath isEqualToString:@"params.resolution"])
|
| 223 |
+
return ScreenResolutionDescription([[self params] intForKey:@"screen_resolution_type"],
|
| 224 |
+
[[self params] intForKey:@"width"],
|
| 225 |
+
[[self params] intForKey:@"height"]);
|
| 226 |
+
|
| 227 |
+
return [super valueForKeyPath:keyPath];
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
- (void)observeValueForKeyPath:(NSString *)keyPath
|
| 231 |
+
ofObject:(id)object
|
| 232 |
+
change:(NSDictionary *)change
|
| 233 |
+
context:(void *)context
|
| 234 |
+
{
|
| 235 |
+
if ([[change objectForKey:NSKeyValueChangeNotificationIsPriorKey] boolValue])
|
| 236 |
+
[self willChangeValueForKeyPath:keyPath];
|
| 237 |
+
else
|
| 238 |
+
[self didChangeValueForKeyPath:keyPath];
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
- (NSDictionary *)targetForChangeNotificationForKeyPath:(NSString *)keyPath
|
| 242 |
+
{
|
| 243 |
+
NSString *changed_key = keyPath;
|
| 244 |
+
NSObject *changed_object = self;
|
| 245 |
+
|
| 246 |
+
if ([keyPath rangeOfString:@"params."].location == 0)
|
| 247 |
+
{
|
| 248 |
+
changed_key = [keyPath substringFromIndex:[@"params." length]];
|
| 249 |
+
changed_object = _connection_params;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
return [NSDictionary
|
| 253 |
+
dictionaryWithObjectsAndKeys:changed_key, @"key", changed_object, @"object", nil];
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
- (void)willChangeValueForKeyPath:(NSString *)keyPath
|
| 257 |
+
{
|
| 258 |
+
NSDictionary *target = [self targetForChangeNotificationForKeyPath:keyPath];
|
| 259 |
+
[[target objectForKey:@"object"] willChangeValueForKey:[target objectForKey:@"key"]];
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
- (void)didChangeValueForKeyPath:(NSString *)keyPath
|
| 263 |
+
{
|
| 264 |
+
NSDictionary *target = [self targetForChangeNotificationForKeyPath:keyPath];
|
| 265 |
+
[[target objectForKey:@"object"] didChangeValueForKey:[target objectForKey:@"key"]];
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
- (ConnectionParams *)copyMarkedParams
|
| 269 |
+
{
|
| 270 |
+
ConnectionParams *param_copy = [[self params] copy];
|
| 271 |
+
[param_copy setValue:[self uuid] forKey:@"_bookmark_uuid"];
|
| 272 |
+
return param_copy;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
#pragma mark No children
|
| 276 |
+
- (NSUInteger)numberOfChildren
|
| 277 |
+
{
|
| 278 |
+
return 0;
|
| 279 |
+
}
|
| 280 |
+
- (NSUInteger)numberOfDescendants
|
| 281 |
+
{
|
| 282 |
+
return 1;
|
| 283 |
+
}
|
| 284 |
+
- (BookmarkBase *)childAtIndex:(NSUInteger)index
|
| 285 |
+
{
|
| 286 |
+
return nil;
|
| 287 |
+
}
|
| 288 |
+
- (NSUInteger)indexOfChild:(BookmarkBase *)child
|
| 289 |
+
{
|
| 290 |
+
return 0;
|
| 291 |
+
}
|
| 292 |
+
- (void)removeChild:(BookmarkBase *)child
|
| 293 |
+
{
|
| 294 |
+
}
|
| 295 |
+
- (void)addChild:(BookmarkBase *)child
|
| 296 |
+
{
|
| 297 |
+
}
|
| 298 |
+
- (void)addChild:(BookmarkBase *)child afterExistingChild:(BookmarkBase *)existingChild
|
| 299 |
+
{
|
| 300 |
+
}
|
| 301 |
+
- (void)addChild:(BookmarkBase *)child atIndex:(NSInteger)index
|
| 302 |
+
{
|
| 303 |
+
}
|
| 304 |
+
- (BOOL)hasDescendant:(BookmarkBase *)needle
|
| 305 |
+
{
|
| 306 |
+
return NO;
|
| 307 |
+
}
|
| 308 |
+
- (BOOL)canContainChildren
|
| 309 |
+
{
|
| 310 |
+
return NO;
|
| 311 |
+
}
|
| 312 |
+
@end
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/ConnectionParams.h
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Connection Parameters abstraction
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Dorian Johnson
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#import <Foundation/Foundation.h>
|
| 12 |
+
|
| 13 |
+
@interface ConnectionParams : NSObject
|
| 14 |
+
{
|
| 15 |
+
@private
|
| 16 |
+
NSMutableDictionary *_connection_params;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
// Designated initializer.
|
| 20 |
+
- (id)initWithDictionary:(NSDictionary *)dict;
|
| 21 |
+
- (id)initWithBaseDefaultParameters;
|
| 22 |
+
|
| 23 |
+
// Getting/setting values
|
| 24 |
+
- (NSArray *)allKeys;
|
| 25 |
+
- (void)setValue:(id)value forKey:(NSString *)key;
|
| 26 |
+
- (id)valueForKey:(NSString *)key;
|
| 27 |
+
- (BOOL)hasValueForKey:(NSString *)key;
|
| 28 |
+
- (void)setInt:(int)integer forKey:(NSString *)key;
|
| 29 |
+
- (int)intForKey:(NSString *)key;
|
| 30 |
+
- (void)setBool:(BOOL)v forKey:(NSString *)key;
|
| 31 |
+
- (BOOL)boolForKey:(NSString *)key;
|
| 32 |
+
- (const char *)UTF8StringForKey:(NSString *)key;
|
| 33 |
+
- (NSString *)StringForKey:(NSString *)key;
|
| 34 |
+
|
| 35 |
+
- (BOOL)hasValueForKeyPath:(NSString *)key;
|
| 36 |
+
- (void)setInt:(int)integer forKeyPath:(NSString *)key;
|
| 37 |
+
- (int)intForKeyPath:(NSString *)key;
|
| 38 |
+
- (void)setBool:(BOOL)v forKeyPath:(NSString *)key;
|
| 39 |
+
- (BOOL)boolForKeyPath:(NSString *)key;
|
| 40 |
+
- (const char *)UTF8StringForKeyPath:(NSString *)key;
|
| 41 |
+
- (NSString *)StringForKeyPath:(NSString *)key;
|
| 42 |
+
|
| 43 |
+
- (int)intForKey:(NSString *)key with3GEnabled:(BOOL)enabled;
|
| 44 |
+
- (BOOL)boolForKey:(NSString *)key with3GEnabled:(BOOL)enabled;
|
| 45 |
+
|
| 46 |
+
@end
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/ConnectionParams.m
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Connection Parameters abstraction
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Dorian Johnson
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#import "ConnectionParams.h"
|
| 12 |
+
#import "GlobalDefaults.h"
|
| 13 |
+
#import "EncryptionController.h"
|
| 14 |
+
#import "Utils.h"
|
| 15 |
+
#import "TSXAdditions.h"
|
| 16 |
+
|
| 17 |
+
@interface ConnectionParams (Private)
|
| 18 |
+
- (id)initWithConnectionParams:(ConnectionParams *)params;
|
| 19 |
+
@end
|
| 20 |
+
|
| 21 |
+
@implementation ConnectionParams
|
| 22 |
+
|
| 23 |
+
// Designated initializer.
|
| 24 |
+
- (id)initWithDictionary:(NSDictionary *)dict
|
| 25 |
+
{
|
| 26 |
+
if (!(self = [super init]))
|
| 27 |
+
return nil;
|
| 28 |
+
|
| 29 |
+
_connection_params = [dict mutableDeepCopy];
|
| 30 |
+
|
| 31 |
+
[self decryptPasswordForKey:@"password"];
|
| 32 |
+
[self decryptPasswordForKey:@"tsg_password"];
|
| 33 |
+
|
| 34 |
+
return self;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
- (void)decryptPasswordForKey:(NSString *)key
|
| 38 |
+
{
|
| 39 |
+
if ([[_connection_params objectForKey:key] isKindOfClass:[NSData class]])
|
| 40 |
+
{
|
| 41 |
+
NSString *plaintext_password = [[[EncryptionController sharedEncryptionController]
|
| 42 |
+
decryptor] decryptString:[_connection_params objectForKey:key]];
|
| 43 |
+
[self setValue:plaintext_password forKey:key];
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
- (id)initWithBaseDefaultParameters
|
| 48 |
+
{
|
| 49 |
+
return [self initWithDictionary:[[NSUserDefaults standardUserDefaults]
|
| 50 |
+
dictionaryForKey:@"TSXDefaultComputerBookmarkSettings"]];
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
- (id)init
|
| 54 |
+
{
|
| 55 |
+
return [self initWithDictionary:[NSDictionary dictionary]];
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
- (id)initWithConnectionParams:(ConnectionParams *)params
|
| 59 |
+
{
|
| 60 |
+
return [self initWithDictionary:params->_connection_params];
|
| 61 |
+
}
|
| 62 |
+
- (void)dealloc
|
| 63 |
+
{
|
| 64 |
+
[_connection_params release];
|
| 65 |
+
_connection_params = nil;
|
| 66 |
+
[super dealloc];
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
- (id)copyWithZone:(NSZone *)zone
|
| 70 |
+
{
|
| 71 |
+
return [[ConnectionParams alloc] initWithDictionary:_connection_params];
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
- (NSString *)description
|
| 75 |
+
{
|
| 76 |
+
return [NSString stringWithFormat:@"ConnectionParams: %@", [_connection_params description]];
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
#pragma mark -
|
| 80 |
+
#pragma mark NSCoder
|
| 81 |
+
|
| 82 |
+
- (id)initWithCoder:(NSCoder *)decoder
|
| 83 |
+
{
|
| 84 |
+
if ([decoder containsValueForKey:@"connectionParams"])
|
| 85 |
+
return [self initWithDictionary:[decoder decodeObjectForKey:@"connectionParams"]];
|
| 86 |
+
|
| 87 |
+
return [self init];
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
- (void)encodeWithCoder:(NSCoder *)coder
|
| 91 |
+
{
|
| 92 |
+
NSSet *unserializable_keys = [NSSet setWithObjects:@"view", nil];
|
| 93 |
+
NSMutableDictionary *serializable_params =
|
| 94 |
+
[[NSMutableDictionary alloc] initWithCapacity:[_connection_params count]];
|
| 95 |
+
|
| 96 |
+
for (NSString *k in _connection_params)
|
| 97 |
+
if (([k characterAtIndex:0] != '_') && ![unserializable_keys containsObject:k])
|
| 98 |
+
[serializable_params setObject:[_connection_params objectForKey:k] forKey:k];
|
| 99 |
+
|
| 100 |
+
if ([serializable_params objectForKey:@"password"] != nil)
|
| 101 |
+
[self serializeDecryptedForKey:@"password" forParams:serializable_params];
|
| 102 |
+
if ([serializable_params objectForKey:@"tsg_password"] != nil)
|
| 103 |
+
[self serializeDecryptedForKey:@"tsg_password" forParams:serializable_params];
|
| 104 |
+
|
| 105 |
+
[coder encodeObject:serializable_params forKey:@"connectionParams"];
|
| 106 |
+
[serializable_params release];
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
- (void)serializeDecryptedForKey:(NSString *)key forParams:(NSMutableDictionary *)params
|
| 110 |
+
{
|
| 111 |
+
NSData *encrypted_password = [[[EncryptionController sharedEncryptionController] encryptor]
|
| 112 |
+
encryptString:[params objectForKey:key]];
|
| 113 |
+
|
| 114 |
+
if (encrypted_password)
|
| 115 |
+
[params setObject:encrypted_password forKey:key];
|
| 116 |
+
else
|
| 117 |
+
[params removeObjectForKey:key];
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
#pragma mark -
|
| 121 |
+
#pragma mark NSKeyValueCoding
|
| 122 |
+
|
| 123 |
+
- (void)setValue:(id)value forKey:(NSString *)key
|
| 124 |
+
{
|
| 125 |
+
[self willChangeValueForKey:key];
|
| 126 |
+
|
| 127 |
+
if (value == nil)
|
| 128 |
+
[self setNilValueForKey:key];
|
| 129 |
+
else
|
| 130 |
+
[_connection_params setValue:value forKey:key];
|
| 131 |
+
|
| 132 |
+
[self didChangeValueForKey:key];
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
- (void)setValue:(id)value forKeyPath:(NSString *)key
|
| 136 |
+
{
|
| 137 |
+
[self willChangeValueForKey:key];
|
| 138 |
+
|
| 139 |
+
if (value == nil)
|
| 140 |
+
[self setNilValueForKey:key];
|
| 141 |
+
else
|
| 142 |
+
[_connection_params setValue:value forKeyPath:key];
|
| 143 |
+
|
| 144 |
+
[self didChangeValueForKey:key];
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
- (void)setNilValueForKey:(NSString *)key
|
| 148 |
+
{
|
| 149 |
+
[_connection_params removeObjectForKey:key];
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
- (id)valueForKey:(NSString *)key
|
| 153 |
+
{
|
| 154 |
+
return [_connection_params valueForKey:key];
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
- (NSArray *)allKeys
|
| 158 |
+
{
|
| 159 |
+
return [_connection_params allKeys];
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
#pragma mark -
|
| 163 |
+
#pragma mark KV convenience
|
| 164 |
+
|
| 165 |
+
- (BOOL)hasValueForKey:(NSString *)key
|
| 166 |
+
{
|
| 167 |
+
return [_connection_params objectForKey:key] != nil;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
- (void)setInt:(int)integer forKey:(NSString *)key
|
| 171 |
+
{
|
| 172 |
+
[self setValue:[NSNumber numberWithInteger:integer] forKey:key];
|
| 173 |
+
}
|
| 174 |
+
- (int)intForKey:(NSString *)key
|
| 175 |
+
{
|
| 176 |
+
return [[self valueForKey:key] intValue];
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
- (void)setBool:(BOOL)v forKey:(NSString *)key
|
| 180 |
+
{
|
| 181 |
+
[self setValue:[NSNumber numberWithBool:v] forKey:key];
|
| 182 |
+
}
|
| 183 |
+
- (BOOL)boolForKey:(NSString *)key
|
| 184 |
+
{
|
| 185 |
+
return [[_connection_params objectForKey:key] boolValue];
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
- (const char *)UTF8StringForKey:(NSString *)key
|
| 189 |
+
{
|
| 190 |
+
id val = [self valueForKey:key];
|
| 191 |
+
const char *str;
|
| 192 |
+
|
| 193 |
+
if ([val respondsToSelector:@selector(UTF8String)] && (str = [val UTF8String]))
|
| 194 |
+
return str;
|
| 195 |
+
|
| 196 |
+
return "";
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
- (NSString *)StringForKey:(NSString *)key
|
| 200 |
+
{
|
| 201 |
+
return [self valueForKey:key];
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
- (BOOL)hasValueForKeyPath:(NSString *)key
|
| 205 |
+
{
|
| 206 |
+
return [_connection_params valueForKeyPath:key] != nil;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
- (void)setInt:(int)integer forKeyPath:(NSString *)key
|
| 210 |
+
{
|
| 211 |
+
[self setValue:[NSNumber numberWithInteger:integer] forKeyPath:key];
|
| 212 |
+
}
|
| 213 |
+
- (int)intForKeyPath:(NSString *)key
|
| 214 |
+
{
|
| 215 |
+
return [[self valueForKeyPath:key] intValue];
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
- (void)setBool:(BOOL)v forKeyPath:(NSString *)key
|
| 219 |
+
{
|
| 220 |
+
[self setValue:[NSNumber numberWithBool:v] forKeyPath:key];
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
- (BOOL)boolForKeyPath:(NSString *)key
|
| 224 |
+
{
|
| 225 |
+
return [[self valueForKeyPath:key] boolValue];
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
- (const char *)UTF8StringForKeyPath:(NSString *)key
|
| 229 |
+
{
|
| 230 |
+
id val = [self valueForKeyPath:key];
|
| 231 |
+
const char *str;
|
| 232 |
+
|
| 233 |
+
if ([val respondsToSelector:@selector(UTF8String)] && (str = [val UTF8String]))
|
| 234 |
+
return str;
|
| 235 |
+
|
| 236 |
+
return "";
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
- (NSString *)StringForKeyPath:(NSString *)key
|
| 240 |
+
{
|
| 241 |
+
return [self valueForKeyPath:key];
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
- (int)intForKey:(NSString *)key with3GEnabled:(BOOL)enabled
|
| 245 |
+
{
|
| 246 |
+
if (enabled && [self boolForKey:@"enable_3g_settings"])
|
| 247 |
+
return [self intForKeyPath:[NSString stringWithFormat:@"settings_3g.%@", key]];
|
| 248 |
+
return [self intForKeyPath:key];
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
- (BOOL)boolForKey:(NSString *)key with3GEnabled:(BOOL)enabled
|
| 252 |
+
{
|
| 253 |
+
if (enabled && [self boolForKey:@"enable_3g_settings"])
|
| 254 |
+
return [self boolForKeyPath:[NSString stringWithFormat:@"settings_3g.%@", key]];
|
| 255 |
+
return [self boolForKeyPath:key];
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
@end
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/GlobalDefaults.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Global default bookmark settings
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Dorian Johnson
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#import <Foundation/Foundation.h>
|
| 12 |
+
|
| 13 |
+
@class ConnectionParams, ComputerBookmark;
|
| 14 |
+
|
| 15 |
+
@interface GlobalDefaults : NSObject
|
| 16 |
+
{
|
| 17 |
+
@private
|
| 18 |
+
ComputerBookmark *_default_bookmark;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
+ (GlobalDefaults *)sharedGlobalDefaults;
|
| 22 |
+
|
| 23 |
+
// The same object is always returned from this method.
|
| 24 |
+
@property(readonly, nonatomic) ComputerBookmark *bookmark;
|
| 25 |
+
|
| 26 |
+
- (ConnectionParams *)newParams;
|
| 27 |
+
- (ComputerBookmark *)newBookmark;
|
| 28 |
+
- (ComputerBookmark *)newTestServerBookmark;
|
| 29 |
+
|
| 30 |
+
@end
|
local-test-freerdp-full-01/afc-freerdp/client/iOS/Models/GlobalDefaults.m
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Global default bookmark settings
|
| 3 |
+
|
| 4 |
+
Copyright 2013 Thincast Technologies GmbH, Author: Dorian Johnson
|
| 5 |
+
|
| 6 |
+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
| 7 |
+
If a copy of the MPL was not distributed with this file, You can obtain one at
|
| 8 |
+
http://mozilla.org/MPL/2.0/.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#import "GlobalDefaults.h"
|
| 12 |
+
#import "Bookmark.h"
|
| 13 |
+
#import "ConnectionParams.h"
|
| 14 |
+
|
| 15 |
+
@implementation GlobalDefaults
|
| 16 |
+
|
| 17 |
+
+ (GlobalDefaults *)sharedGlobalDefaults
|
| 18 |
+
{
|
| 19 |
+
static GlobalDefaults *_shared_global_defaults = nil;
|
| 20 |
+
|
| 21 |
+
if (_shared_global_defaults == nil)
|
| 22 |
+
{
|
| 23 |
+
@synchronized(self)
|
| 24 |
+
{
|
| 25 |
+
if (_shared_global_defaults == nil)
|
| 26 |
+
_shared_global_defaults = [[GlobalDefaults alloc] init];
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
return _shared_global_defaults;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
- (id)init
|
| 34 |
+
{
|
| 35 |
+
if (!(self = [super init]))
|
| 36 |
+
return nil;
|
| 37 |
+
|
| 38 |
+
ComputerBookmark *bookmark = nil;
|
| 39 |
+
NSData *bookmark_data =
|
| 40 |
+
[[NSUserDefaults standardUserDefaults] objectForKey:@"TSXSharedGlobalDefaultBookmark"];
|
| 41 |
+
|
| 42 |
+
if (bookmark_data && [bookmark_data length])
|
| 43 |
+
bookmark = [NSKeyedUnarchiver unarchiveObjectWithData:bookmark_data];
|
| 44 |
+
|
| 45 |
+
if (!bookmark)
|
| 46 |
+
bookmark = [[[ComputerBookmark alloc] initWithBaseDefaultParameters] autorelease];
|
| 47 |
+
|
| 48 |
+
_default_bookmark = [bookmark retain];
|
| 49 |
+
return self;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
- (void)dealloc
|
| 53 |
+
{
|
| 54 |
+
[_default_bookmark release];
|
| 55 |
+
[super dealloc];
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
#pragma mark -
|
| 59 |
+
|
| 60 |
+
@synthesize bookmark = _default_bookmark;
|
| 61 |
+
|
| 62 |
+
- (ComputerBookmark *)newBookmark
|
| 63 |
+
{
|
| 64 |
+
return [[ComputerBookmark alloc] initWithConnectionParameters:[[self newParams] autorelease]];
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
- (ConnectionParams *)newParams
|
| 68 |
+
{
|
| 69 |
+
ConnectionParams *param_copy = [[[self bookmark] params] copy];
|
| 70 |
+
return param_copy;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
- (ComputerBookmark *)newTestServerBookmark
|
| 74 |
+
{
|
| 75 |
+
ComputerBookmark *bm = [self newBookmark];
|
| 76 |
+
[bm setLabel:@"Test Server"];
|
| 77 |
+
[[bm params] setValue:@"testservice.ifreerdp.com" forKey:@"hostname"];
|
| 78 |
+
[[bm params] setInt:0 forKey:@"screen_resolution_type"];
|
| 79 |
+
[[bm params] setInt:1024 forKey:@"width"];
|
| 80 |
+
[[bm params] setInt:768 forKey:@"height"];
|
| 81 |
+
[[bm params] setInt:32 forKey:@"colors"];
|
| 82 |
+
[[bm params] setBool:YES forKey:@"perf_remotefx"];
|
| 83 |
+
[[bm params] setBool:YES forKey:@"perf_gfx"];
|
| 84 |
+
[[bm params] setBool:YES forKey:@"perf_h264"];
|
| 85 |
+
return bm;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
@end
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/fts5/fts5.h
ADDED
|
@@ -0,0 +1,739 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** 2014 May 31
|
| 3 |
+
**
|
| 4 |
+
** The author disclaims copyright to this source code. In place of
|
| 5 |
+
** a legal notice, here is a blessing:
|
| 6 |
+
**
|
| 7 |
+
** May you do good and not evil.
|
| 8 |
+
** May you find forgiveness for yourself and forgive others.
|
| 9 |
+
** May you share freely, never taking more than you give.
|
| 10 |
+
**
|
| 11 |
+
******************************************************************************
|
| 12 |
+
**
|
| 13 |
+
** Interfaces to extend FTS5. Using the interfaces defined in this file,
|
| 14 |
+
** FTS5 may be extended with:
|
| 15 |
+
**
|
| 16 |
+
** * custom tokenizers, and
|
| 17 |
+
** * custom auxiliary functions.
|
| 18 |
+
*/
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
#ifndef _FTS5_H
|
| 22 |
+
#define _FTS5_H
|
| 23 |
+
|
| 24 |
+
#include "sqlite3.h"
|
| 25 |
+
|
| 26 |
+
#ifdef __cplusplus
|
| 27 |
+
extern "C" {
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
/*************************************************************************
|
| 31 |
+
** CUSTOM AUXILIARY FUNCTIONS
|
| 32 |
+
**
|
| 33 |
+
** Virtual table implementations may overload SQL functions by implementing
|
| 34 |
+
** the sqlite3_module.xFindFunction() method.
|
| 35 |
+
*/
|
| 36 |
+
|
| 37 |
+
typedef struct Fts5ExtensionApi Fts5ExtensionApi;
|
| 38 |
+
typedef struct Fts5Context Fts5Context;
|
| 39 |
+
typedef struct Fts5PhraseIter Fts5PhraseIter;
|
| 40 |
+
|
| 41 |
+
typedef void (*fts5_extension_function)(
|
| 42 |
+
const Fts5ExtensionApi *pApi, /* API offered by current FTS version */
|
| 43 |
+
Fts5Context *pFts, /* First arg to pass to pApi functions */
|
| 44 |
+
sqlite3_context *pCtx, /* Context for returning result/error */
|
| 45 |
+
int nVal, /* Number of values in apVal[] array */
|
| 46 |
+
sqlite3_value **apVal /* Array of trailing arguments */
|
| 47 |
+
);
|
| 48 |
+
|
| 49 |
+
struct Fts5PhraseIter {
|
| 50 |
+
const unsigned char *a;
|
| 51 |
+
const unsigned char *b;
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
/*
|
| 55 |
+
** EXTENSION API FUNCTIONS
|
| 56 |
+
**
|
| 57 |
+
** xUserData(pFts):
|
| 58 |
+
** Return a copy of the pUserData pointer passed to the xCreateFunction()
|
| 59 |
+
** API when the extension function was registered.
|
| 60 |
+
**
|
| 61 |
+
** xColumnTotalSize(pFts, iCol, pnToken):
|
| 62 |
+
** If parameter iCol is less than zero, set output variable *pnToken
|
| 63 |
+
** to the total number of tokens in the FTS5 table. Or, if iCol is
|
| 64 |
+
** non-negative but less than the number of columns in the table, return
|
| 65 |
+
** the total number of tokens in column iCol, considering all rows in
|
| 66 |
+
** the FTS5 table.
|
| 67 |
+
**
|
| 68 |
+
** If parameter iCol is greater than or equal to the number of columns
|
| 69 |
+
** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
|
| 70 |
+
** an OOM condition or IO error), an appropriate SQLite error code is
|
| 71 |
+
** returned.
|
| 72 |
+
**
|
| 73 |
+
** xColumnCount(pFts):
|
| 74 |
+
** Return the number of columns in the table.
|
| 75 |
+
**
|
| 76 |
+
** xColumnSize(pFts, iCol, pnToken):
|
| 77 |
+
** If parameter iCol is less than zero, set output variable *pnToken
|
| 78 |
+
** to the total number of tokens in the current row. Or, if iCol is
|
| 79 |
+
** non-negative but less than the number of columns in the table, set
|
| 80 |
+
** *pnToken to the number of tokens in column iCol of the current row.
|
| 81 |
+
**
|
| 82 |
+
** If parameter iCol is greater than or equal to the number of columns
|
| 83 |
+
** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
|
| 84 |
+
** an OOM condition or IO error), an appropriate SQLite error code is
|
| 85 |
+
** returned.
|
| 86 |
+
**
|
| 87 |
+
** This function may be quite inefficient if used with an FTS5 table
|
| 88 |
+
** created with the "columnsize=0" option.
|
| 89 |
+
**
|
| 90 |
+
** xColumnText:
|
| 91 |
+
** If parameter iCol is less than zero, or greater than or equal to the
|
| 92 |
+
** number of columns in the table, SQLITE_RANGE is returned.
|
| 93 |
+
**
|
| 94 |
+
** Otherwise, this function attempts to retrieve the text of column iCol of
|
| 95 |
+
** the current document. If successful, (*pz) is set to point to a buffer
|
| 96 |
+
** containing the text in utf-8 encoding, (*pn) is set to the size in bytes
|
| 97 |
+
** (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
|
| 98 |
+
** if an error occurs, an SQLite error code is returned and the final values
|
| 99 |
+
** of (*pz) and (*pn) are undefined.
|
| 100 |
+
**
|
| 101 |
+
** xPhraseCount:
|
| 102 |
+
** Returns the number of phrases in the current query expression.
|
| 103 |
+
**
|
| 104 |
+
** xPhraseSize:
|
| 105 |
+
** If parameter iCol is less than zero, or greater than or equal to the
|
| 106 |
+
** number of phrases in the current query, as returned by xPhraseCount,
|
| 107 |
+
** 0 is returned. Otherwise, this function returns the number of tokens in
|
| 108 |
+
** phrase iPhrase of the query. Phrases are numbered starting from zero.
|
| 109 |
+
**
|
| 110 |
+
** xInstCount:
|
| 111 |
+
** Set *pnInst to the total number of occurrences of all phrases within
|
| 112 |
+
** the query within the current row. Return SQLITE_OK if successful, or
|
| 113 |
+
** an error code (i.e. SQLITE_NOMEM) if an error occurs.
|
| 114 |
+
**
|
| 115 |
+
** This API can be quite slow if used with an FTS5 table created with the
|
| 116 |
+
** "detail=none" or "detail=column" option. If the FTS5 table is created
|
| 117 |
+
** with either "detail=none" or "detail=column" and "content=" option
|
| 118 |
+
** (i.e. if it is a contentless table), then this API always returns 0.
|
| 119 |
+
**
|
| 120 |
+
** xInst:
|
| 121 |
+
** Query for the details of phrase match iIdx within the current row.
|
| 122 |
+
** Phrase matches are numbered starting from zero, so the iIdx argument
|
| 123 |
+
** should be greater than or equal to zero and smaller than the value
|
| 124 |
+
** output by xInstCount(). If iIdx is less than zero or greater than
|
| 125 |
+
** or equal to the value returned by xInstCount(), SQLITE_RANGE is returned.
|
| 126 |
+
**
|
| 127 |
+
** Otherwise, output parameter *piPhrase is set to the phrase number, *piCol
|
| 128 |
+
** to the column in which it occurs and *piOff the token offset of the
|
| 129 |
+
** first token of the phrase. SQLITE_OK is returned if successful, or an
|
| 130 |
+
** error code (i.e. SQLITE_NOMEM) if an error occurs.
|
| 131 |
+
**
|
| 132 |
+
** This API can be quite slow if used with an FTS5 table created with the
|
| 133 |
+
** "detail=none" or "detail=column" option.
|
| 134 |
+
**
|
| 135 |
+
** xRowid:
|
| 136 |
+
** Returns the rowid of the current row.
|
| 137 |
+
**
|
| 138 |
+
** xTokenize:
|
| 139 |
+
** Tokenize text using the tokenizer belonging to the FTS5 table.
|
| 140 |
+
**
|
| 141 |
+
** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
|
| 142 |
+
** This API function is used to query the FTS table for phrase iPhrase
|
| 143 |
+
** of the current query. Specifically, a query equivalent to:
|
| 144 |
+
**
|
| 145 |
+
** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
|
| 146 |
+
**
|
| 147 |
+
** with $p set to a phrase equivalent to the phrase iPhrase of the
|
| 148 |
+
** current query is executed. Any column filter that applies to
|
| 149 |
+
** phrase iPhrase of the current query is included in $p. For each
|
| 150 |
+
** row visited, the callback function passed as the fourth argument
|
| 151 |
+
** is invoked. The context and API objects passed to the callback
|
| 152 |
+
** function may be used to access the properties of each matched row.
|
| 153 |
+
** Invoking Api.xUserData() returns a copy of the pointer passed as
|
| 154 |
+
** the third argument to pUserData.
|
| 155 |
+
**
|
| 156 |
+
** If parameter iPhrase is less than zero, or greater than or equal to
|
| 157 |
+
** the number of phrases in the query, as returned by xPhraseCount(),
|
| 158 |
+
** this function returns SQLITE_RANGE.
|
| 159 |
+
**
|
| 160 |
+
** If the callback function returns any value other than SQLITE_OK, the
|
| 161 |
+
** query is abandoned and the xQueryPhrase function returns immediately.
|
| 162 |
+
** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
|
| 163 |
+
** Otherwise, the error code is propagated upwards.
|
| 164 |
+
**
|
| 165 |
+
** If the query runs to completion without incident, SQLITE_OK is returned.
|
| 166 |
+
** Or, if some error occurs before the query completes or is aborted by
|
| 167 |
+
** the callback, an SQLite error code is returned.
|
| 168 |
+
**
|
| 169 |
+
**
|
| 170 |
+
** xSetAuxdata(pFts5, pAux, xDelete)
|
| 171 |
+
**
|
| 172 |
+
** Save the pointer passed as the second argument as the extension function's
|
| 173 |
+
** "auxiliary data". The pointer may then be retrieved by the current or any
|
| 174 |
+
** future invocation of the same fts5 extension function made as part of
|
| 175 |
+
** the same MATCH query using the xGetAuxdata() API.
|
| 176 |
+
**
|
| 177 |
+
** Each extension function is allocated a single auxiliary data slot for
|
| 178 |
+
** each FTS query (MATCH expression). If the extension function is invoked
|
| 179 |
+
** more than once for a single FTS query, then all invocations share a
|
| 180 |
+
** single auxiliary data context.
|
| 181 |
+
**
|
| 182 |
+
** If there is already an auxiliary data pointer when this function is
|
| 183 |
+
** invoked, then it is replaced by the new pointer. If an xDelete callback
|
| 184 |
+
** was specified along with the original pointer, it is invoked at this
|
| 185 |
+
** point.
|
| 186 |
+
**
|
| 187 |
+
** The xDelete callback, if one is specified, is also invoked on the
|
| 188 |
+
** auxiliary data pointer after the FTS5 query has finished.
|
| 189 |
+
**
|
| 190 |
+
** If an error (e.g. an OOM condition) occurs within this function,
|
| 191 |
+
** the auxiliary data is set to NULL and an error code returned. If the
|
| 192 |
+
** xDelete parameter was not NULL, it is invoked on the auxiliary data
|
| 193 |
+
** pointer before returning.
|
| 194 |
+
**
|
| 195 |
+
**
|
| 196 |
+
** xGetAuxdata(pFts5, bClear)
|
| 197 |
+
**
|
| 198 |
+
** Returns the current auxiliary data pointer for the fts5 extension
|
| 199 |
+
** function. See the xSetAuxdata() method for details.
|
| 200 |
+
**
|
| 201 |
+
** If the bClear argument is non-zero, then the auxiliary data is cleared
|
| 202 |
+
** (set to NULL) before this function returns. In this case the xDelete,
|
| 203 |
+
** if any, is not invoked.
|
| 204 |
+
**
|
| 205 |
+
**
|
| 206 |
+
** xRowCount(pFts5, pnRow)
|
| 207 |
+
**
|
| 208 |
+
** This function is used to retrieve the total number of rows in the table.
|
| 209 |
+
** In other words, the same value that would be returned by:
|
| 210 |
+
**
|
| 211 |
+
** SELECT count(*) FROM ftstable;
|
| 212 |
+
**
|
| 213 |
+
** xPhraseFirst()
|
| 214 |
+
** This function is used, along with type Fts5PhraseIter and the xPhraseNext
|
| 215 |
+
** method, to iterate through all instances of a single query phrase within
|
| 216 |
+
** the current row. This is the same information as is accessible via the
|
| 217 |
+
** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
|
| 218 |
+
** to use, this API may be faster under some circumstances. To iterate
|
| 219 |
+
** through instances of phrase iPhrase, use the following code:
|
| 220 |
+
**
|
| 221 |
+
** Fts5PhraseIter iter;
|
| 222 |
+
** int iCol, iOff;
|
| 223 |
+
** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);
|
| 224 |
+
** iCol>=0;
|
| 225 |
+
** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
|
| 226 |
+
** ){
|
| 227 |
+
** // An instance of phrase iPhrase at offset iOff of column iCol
|
| 228 |
+
** }
|
| 229 |
+
**
|
| 230 |
+
** The Fts5PhraseIter structure is defined above. Applications should not
|
| 231 |
+
** modify this structure directly - it should only be used as shown above
|
| 232 |
+
** with the xPhraseFirst() and xPhraseNext() API methods (and by
|
| 233 |
+
** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
|
| 234 |
+
**
|
| 235 |
+
** This API can be quite slow if used with an FTS5 table created with the
|
| 236 |
+
** "detail=none" or "detail=column" option. If the FTS5 table is created
|
| 237 |
+
** with either "detail=none" or "detail=column" and "content=" option
|
| 238 |
+
** (i.e. if it is a contentless table), then this API always iterates
|
| 239 |
+
** through an empty set (all calls to xPhraseFirst() set iCol to -1).
|
| 240 |
+
**
|
| 241 |
+
** In all cases, matches are visited in (column ASC, offset ASC) order.
|
| 242 |
+
** i.e. all those in column 0, sorted by offset, followed by those in
|
| 243 |
+
** column 1, etc.
|
| 244 |
+
**
|
| 245 |
+
** xPhraseNext()
|
| 246 |
+
** See xPhraseFirst above.
|
| 247 |
+
**
|
| 248 |
+
** xPhraseFirstColumn()
|
| 249 |
+
** This function and xPhraseNextColumn() are similar to the xPhraseFirst()
|
| 250 |
+
** and xPhraseNext() APIs described above. The difference is that instead
|
| 251 |
+
** of iterating through all instances of a phrase in the current row, these
|
| 252 |
+
** APIs are used to iterate through the set of columns in the current row
|
| 253 |
+
** that contain one or more instances of a specified phrase. For example:
|
| 254 |
+
**
|
| 255 |
+
** Fts5PhraseIter iter;
|
| 256 |
+
** int iCol;
|
| 257 |
+
** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);
|
| 258 |
+
** iCol>=0;
|
| 259 |
+
** pApi->xPhraseNextColumn(pFts, &iter, &iCol)
|
| 260 |
+
** ){
|
| 261 |
+
** // Column iCol contains at least one instance of phrase iPhrase
|
| 262 |
+
** }
|
| 263 |
+
**
|
| 264 |
+
** This API can be quite slow if used with an FTS5 table created with the
|
| 265 |
+
** "detail=none" option. If the FTS5 table is created with either
|
| 266 |
+
** "detail=none" "content=" option (i.e. if it is a contentless table),
|
| 267 |
+
** then this API always iterates through an empty set (all calls to
|
| 268 |
+
** xPhraseFirstColumn() set iCol to -1).
|
| 269 |
+
**
|
| 270 |
+
** The information accessed using this API and its companion
|
| 271 |
+
** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
|
| 272 |
+
** (or xInst/xInstCount). The chief advantage of this API is that it is
|
| 273 |
+
** significantly more efficient than those alternatives when used with
|
| 274 |
+
** "detail=column" tables.
|
| 275 |
+
**
|
| 276 |
+
** xPhraseNextColumn()
|
| 277 |
+
** See xPhraseFirstColumn above.
|
| 278 |
+
**
|
| 279 |
+
** xQueryToken(pFts5, iPhrase, iToken, ppToken, pnToken)
|
| 280 |
+
** This is used to access token iToken of phrase iPhrase of the current
|
| 281 |
+
** query. Before returning, output parameter *ppToken is set to point
|
| 282 |
+
** to a buffer containing the requested token, and *pnToken to the
|
| 283 |
+
** size of this buffer in bytes.
|
| 284 |
+
**
|
| 285 |
+
** If iPhrase or iToken are less than zero, or if iPhrase is greater than
|
| 286 |
+
** or equal to the number of phrases in the query as reported by
|
| 287 |
+
** xPhraseCount(), or if iToken is equal to or greater than the number of
|
| 288 |
+
** tokens in the phrase, SQLITE_RANGE is returned and *ppToken and *pnToken
|
| 289 |
+
are both zeroed.
|
| 290 |
+
**
|
| 291 |
+
** The output text is not a copy of the query text that specified the
|
| 292 |
+
** token. It is the output of the tokenizer module. For tokendata=1
|
| 293 |
+
** tables, this includes any embedded 0x00 and trailing data.
|
| 294 |
+
**
|
| 295 |
+
** xInstToken(pFts5, iIdx, iToken, ppToken, pnToken)
|
| 296 |
+
** This is used to access token iToken of phrase hit iIdx within the
|
| 297 |
+
** current row. If iIdx is less than zero or greater than or equal to the
|
| 298 |
+
** value returned by xInstCount(), SQLITE_RANGE is returned. Otherwise,
|
| 299 |
+
** output variable (*ppToken) is set to point to a buffer containing the
|
| 300 |
+
** matching document token, and (*pnToken) to the size of that buffer in
|
| 301 |
+
** bytes. This API is not available if the specified token matches a
|
| 302 |
+
** prefix query term. In that case both output variables are always set
|
| 303 |
+
** to 0.
|
| 304 |
+
**
|
| 305 |
+
** The output text is not a copy of the document text that was tokenized.
|
| 306 |
+
** It is the output of the tokenizer module. For tokendata=1 tables, this
|
| 307 |
+
** includes any embedded 0x00 and trailing data.
|
| 308 |
+
**
|
| 309 |
+
** This API can be quite slow if used with an FTS5 table created with the
|
| 310 |
+
** "detail=none" or "detail=column" option.
|
| 311 |
+
**
|
| 312 |
+
** xColumnLocale(pFts5, iIdx, pzLocale, pnLocale)
|
| 313 |
+
** If parameter iCol is less than zero, or greater than or equal to the
|
| 314 |
+
** number of columns in the table, SQLITE_RANGE is returned.
|
| 315 |
+
**
|
| 316 |
+
** Otherwise, this function attempts to retrieve the locale associated
|
| 317 |
+
** with column iCol of the current row. Usually, there is no associated
|
| 318 |
+
** locale, and output parameters (*pzLocale) and (*pnLocale) are set
|
| 319 |
+
** to NULL and 0, respectively. However, if the fts5_locale() function
|
| 320 |
+
** was used to associate a locale with the value when it was inserted
|
| 321 |
+
** into the fts5 table, then (*pzLocale) is set to point to a nul-terminated
|
| 322 |
+
** buffer containing the name of the locale in utf-8 encoding. (*pnLocale)
|
| 323 |
+
** is set to the size in bytes of the buffer, not including the
|
| 324 |
+
** nul-terminator.
|
| 325 |
+
**
|
| 326 |
+
** If successful, SQLITE_OK is returned. Or, if an error occurs, an
|
| 327 |
+
** SQLite error code is returned. The final value of the output parameters
|
| 328 |
+
** is undefined in this case.
|
| 329 |
+
**
|
| 330 |
+
** xTokenize_v2:
|
| 331 |
+
** Tokenize text using the tokenizer belonging to the FTS5 table. This
|
| 332 |
+
** API is the same as the xTokenize() API, except that it allows a tokenizer
|
| 333 |
+
** locale to be specified.
|
| 334 |
+
*/
|
| 335 |
+
struct Fts5ExtensionApi {
|
| 336 |
+
int iVersion; /* Currently always set to 4 */
|
| 337 |
+
|
| 338 |
+
void *(*xUserData)(Fts5Context*);
|
| 339 |
+
|
| 340 |
+
int (*xColumnCount)(Fts5Context*);
|
| 341 |
+
int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
|
| 342 |
+
int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);
|
| 343 |
+
|
| 344 |
+
int (*xTokenize)(Fts5Context*,
|
| 345 |
+
const char *pText, int nText, /* Text to tokenize */
|
| 346 |
+
void *pCtx, /* Context passed to xToken() */
|
| 347 |
+
int (*xToken)(void*, int, const char*, int, int, int) /* Callback */
|
| 348 |
+
);
|
| 349 |
+
|
| 350 |
+
int (*xPhraseCount)(Fts5Context*);
|
| 351 |
+
int (*xPhraseSize)(Fts5Context*, int iPhrase);
|
| 352 |
+
|
| 353 |
+
int (*xInstCount)(Fts5Context*, int *pnInst);
|
| 354 |
+
int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);
|
| 355 |
+
|
| 356 |
+
sqlite3_int64 (*xRowid)(Fts5Context*);
|
| 357 |
+
int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);
|
| 358 |
+
int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken);
|
| 359 |
+
|
| 360 |
+
int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,
|
| 361 |
+
int(*)(const Fts5ExtensionApi*,Fts5Context*,void*)
|
| 362 |
+
);
|
| 363 |
+
int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));
|
| 364 |
+
void *(*xGetAuxdata)(Fts5Context*, int bClear);
|
| 365 |
+
|
| 366 |
+
int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);
|
| 367 |
+
void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);
|
| 368 |
+
|
| 369 |
+
int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);
|
| 370 |
+
void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);
|
| 371 |
+
|
| 372 |
+
/* Below this point are iVersion>=3 only */
|
| 373 |
+
int (*xQueryToken)(Fts5Context*,
|
| 374 |
+
int iPhrase, int iToken,
|
| 375 |
+
const char **ppToken, int *pnToken
|
| 376 |
+
);
|
| 377 |
+
int (*xInstToken)(Fts5Context*, int iIdx, int iToken, const char**, int*);
|
| 378 |
+
|
| 379 |
+
/* Below this point are iVersion>=4 only */
|
| 380 |
+
int (*xColumnLocale)(Fts5Context*, int iCol, const char **pz, int *pn);
|
| 381 |
+
int (*xTokenize_v2)(Fts5Context*,
|
| 382 |
+
const char *pText, int nText, /* Text to tokenize */
|
| 383 |
+
const char *pLocale, int nLocale, /* Locale to pass to tokenizer */
|
| 384 |
+
void *pCtx, /* Context passed to xToken() */
|
| 385 |
+
int (*xToken)(void*, int, const char*, int, int, int) /* Callback */
|
| 386 |
+
);
|
| 387 |
+
};
|
| 388 |
+
|
| 389 |
+
/*
|
| 390 |
+
** CUSTOM AUXILIARY FUNCTIONS
|
| 391 |
+
*************************************************************************/
|
| 392 |
+
|
| 393 |
+
/*************************************************************************
|
| 394 |
+
** CUSTOM TOKENIZERS
|
| 395 |
+
**
|
| 396 |
+
** Applications may also register custom tokenizer types. A tokenizer
|
| 397 |
+
** is registered by providing fts5 with a populated instance of the
|
| 398 |
+
** following structure. All structure methods must be defined, setting
|
| 399 |
+
** any member of the fts5_tokenizer struct to NULL leads to undefined
|
| 400 |
+
** behaviour. The structure methods are expected to function as follows:
|
| 401 |
+
**
|
| 402 |
+
** xCreate:
|
| 403 |
+
** This function is used to allocate and initialize a tokenizer instance.
|
| 404 |
+
** A tokenizer instance is required to actually tokenize text.
|
| 405 |
+
**
|
| 406 |
+
** The first argument passed to this function is a copy of the (void*)
|
| 407 |
+
** pointer provided by the application when the fts5_tokenizer_v2 object
|
| 408 |
+
** was registered with FTS5 (the third argument to xCreateTokenizer()).
|
| 409 |
+
** The second and third arguments are an array of nul-terminated strings
|
| 410 |
+
** containing the tokenizer arguments, if any, specified following the
|
| 411 |
+
** tokenizer name as part of the CREATE VIRTUAL TABLE statement used
|
| 412 |
+
** to create the FTS5 table.
|
| 413 |
+
**
|
| 414 |
+
** The final argument is an output variable. If successful, (*ppOut)
|
| 415 |
+
** should be set to point to the new tokenizer handle and SQLITE_OK
|
| 416 |
+
** returned. If an error occurs, some value other than SQLITE_OK should
|
| 417 |
+
** be returned. In this case, fts5 assumes that the final value of *ppOut
|
| 418 |
+
** is undefined.
|
| 419 |
+
**
|
| 420 |
+
** xDelete:
|
| 421 |
+
** This function is invoked to delete a tokenizer handle previously
|
| 422 |
+
** allocated using xCreate(). Fts5 guarantees that this function will
|
| 423 |
+
** be invoked exactly once for each successful call to xCreate().
|
| 424 |
+
**
|
| 425 |
+
** xTokenize:
|
| 426 |
+
** This function is expected to tokenize the nText byte string indicated
|
| 427 |
+
** by argument pText. pText may or may not be nul-terminated. The first
|
| 428 |
+
** argument passed to this function is a pointer to an Fts5Tokenizer object
|
| 429 |
+
** returned by an earlier call to xCreate().
|
| 430 |
+
**
|
| 431 |
+
** The third argument indicates the reason that FTS5 is requesting
|
| 432 |
+
** tokenization of the supplied text. This is always one of the following
|
| 433 |
+
** four values:
|
| 434 |
+
**
|
| 435 |
+
** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into
|
| 436 |
+
** or removed from the FTS table. The tokenizer is being invoked to
|
| 437 |
+
** determine the set of tokens to add to (or delete from) the
|
| 438 |
+
** FTS index.
|
| 439 |
+
**
|
| 440 |
+
** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
|
| 441 |
+
** against the FTS index. The tokenizer is being called to tokenize
|
| 442 |
+
** a bareword or quoted string specified as part of the query.
|
| 443 |
+
**
|
| 444 |
+
** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
|
| 445 |
+
** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is
|
| 446 |
+
** followed by a "*" character, indicating that the last token
|
| 447 |
+
** returned by the tokenizer will be treated as a token prefix.
|
| 448 |
+
**
|
| 449 |
+
** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
|
| 450 |
+
** satisfy an fts5_api.xTokenize() request made by an auxiliary
|
| 451 |
+
** function. Or an fts5_api.xColumnSize() request made by the same
|
| 452 |
+
** on a columnsize=0 database.
|
| 453 |
+
** </ul>
|
| 454 |
+
**
|
| 455 |
+
** The sixth and seventh arguments passed to xTokenize() - pLocale and
|
| 456 |
+
** nLocale - are a pointer to a buffer containing the locale to use for
|
| 457 |
+
** tokenization (e.g. "en_US") and its size in bytes, respectively. The
|
| 458 |
+
** pLocale buffer is not nul-terminated. pLocale may be passed NULL (in
|
| 459 |
+
** which case nLocale is always 0) to indicate that the tokenizer should
|
| 460 |
+
** use its default locale.
|
| 461 |
+
**
|
| 462 |
+
** For each token in the input string, the supplied callback xToken() must
|
| 463 |
+
** be invoked. The first argument to it should be a copy of the pointer
|
| 464 |
+
** passed as the second argument to xTokenize(). The third and fourth
|
| 465 |
+
** arguments are a pointer to a buffer containing the token text, and the
|
| 466 |
+
** size of the token in bytes. The 4th and 5th arguments are the byte offsets
|
| 467 |
+
** of the first byte of and first byte immediately following the text from
|
| 468 |
+
** which the token is derived within the input.
|
| 469 |
+
**
|
| 470 |
+
** The second argument passed to the xToken() callback ("tflags") should
|
| 471 |
+
** normally be set to 0. The exception is if the tokenizer supports
|
| 472 |
+
** synonyms. In this case see the discussion below for details.
|
| 473 |
+
**
|
| 474 |
+
** FTS5 assumes the xToken() callback is invoked for each token in the
|
| 475 |
+
** order that they occur within the input text.
|
| 476 |
+
**
|
| 477 |
+
** If an xToken() callback returns any value other than SQLITE_OK, then
|
| 478 |
+
** the tokenization should be abandoned and the xTokenize() method should
|
| 479 |
+
** immediately return a copy of the xToken() return value. Or, if the
|
| 480 |
+
** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,
|
| 481 |
+
** if an error occurs with the xTokenize() implementation itself, it
|
| 482 |
+
** may abandon the tokenization and return any error code other than
|
| 483 |
+
** SQLITE_OK or SQLITE_DONE.
|
| 484 |
+
**
|
| 485 |
+
** If the tokenizer is registered using an fts5_tokenizer_v2 object,
|
| 486 |
+
** then the xTokenize() method has two additional arguments - pLocale
|
| 487 |
+
** and nLocale. These specify the locale that the tokenizer should use
|
| 488 |
+
** for the current request. If pLocale and nLocale are both 0, then the
|
| 489 |
+
** tokenizer should use its default locale. Otherwise, pLocale points to
|
| 490 |
+
** an nLocale byte buffer containing the name of the locale to use as utf-8
|
| 491 |
+
** text. pLocale is not nul-terminated.
|
| 492 |
+
**
|
| 493 |
+
** FTS5_TOKENIZER
|
| 494 |
+
**
|
| 495 |
+
** There is also an fts5_tokenizer object. This is an older, deprecated,
|
| 496 |
+
** version of fts5_tokenizer_v2. It is similar except that:
|
| 497 |
+
**
|
| 498 |
+
** <ul>
|
| 499 |
+
** <li> There is no "iVersion" field, and
|
| 500 |
+
** <li> The xTokenize() method does not take a locale argument.
|
| 501 |
+
** </ul>
|
| 502 |
+
**
|
| 503 |
+
** Legacy fts5_tokenizer tokenizers must be registered using the
|
| 504 |
+
** legacy xCreateTokenizer() function, instead of xCreateTokenizer_v2().
|
| 505 |
+
**
|
| 506 |
+
** Tokenizer implementations registered using either API may be retrieved
|
| 507 |
+
** using both xFindTokenizer() and xFindTokenizer_v2().
|
| 508 |
+
**
|
| 509 |
+
** SYNONYM SUPPORT
|
| 510 |
+
**
|
| 511 |
+
** Custom tokenizers may also support synonyms. Consider a case in which a
|
| 512 |
+
** user wishes to query for a phrase such as "first place". Using the
|
| 513 |
+
** built-in tokenizers, the FTS5 query 'first + place' will match instances
|
| 514 |
+
** of "first place" within the document set, but not alternative forms
|
| 515 |
+
** such as "1st place". In some applications, it would be better to match
|
| 516 |
+
** all instances of "first place" or "1st place" regardless of which form
|
| 517 |
+
** the user specified in the MATCH query text.
|
| 518 |
+
**
|
| 519 |
+
** There are several ways to approach this in FTS5:
|
| 520 |
+
**
|
| 521 |
+
** <ol><li> By mapping all synonyms to a single token. In this case, using
|
| 522 |
+
** the above example, this means that the tokenizer returns the
|
| 523 |
+
** same token for inputs "first" and "1st". Say that token is in
|
| 524 |
+
** fact "first", so that when the user inserts the document "I won
|
| 525 |
+
** 1st place" entries are added to the index for tokens "i", "won",
|
| 526 |
+
** "first" and "place". If the user then queries for '1st + place',
|
| 527 |
+
** the tokenizer substitutes "first" for "1st" and the query works
|
| 528 |
+
** as expected.
|
| 529 |
+
**
|
| 530 |
+
** <li> By querying the index for all synonyms of each query term
|
| 531 |
+
** separately. In this case, when tokenizing query text, the
|
| 532 |
+
** tokenizer may provide multiple synonyms for a single term
|
| 533 |
+
** within the document. FTS5 then queries the index for each
|
| 534 |
+
** synonym individually. For example, faced with the query:
|
| 535 |
+
**
|
| 536 |
+
** <codeblock>
|
| 537 |
+
** ... MATCH 'first place'</codeblock>
|
| 538 |
+
**
|
| 539 |
+
** the tokenizer offers both "1st" and "first" as synonyms for the
|
| 540 |
+
** first token in the MATCH query and FTS5 effectively runs a query
|
| 541 |
+
** similar to:
|
| 542 |
+
**
|
| 543 |
+
** <codeblock>
|
| 544 |
+
** ... MATCH '(first OR 1st) place'</codeblock>
|
| 545 |
+
**
|
| 546 |
+
** except that, for the purposes of auxiliary functions, the query
|
| 547 |
+
** still appears to contain just two phrases - "(first OR 1st)"
|
| 548 |
+
** being treated as a single phrase.
|
| 549 |
+
**
|
| 550 |
+
** <li> By adding multiple synonyms for a single term to the FTS index.
|
| 551 |
+
** Using this method, when tokenizing document text, the tokenizer
|
| 552 |
+
** provides multiple synonyms for each token. So that when a
|
| 553 |
+
** document such as "I won first place" is tokenized, entries are
|
| 554 |
+
** added to the FTS index for "i", "won", "first", "1st" and
|
| 555 |
+
** "place".
|
| 556 |
+
**
|
| 557 |
+
** This way, even if the tokenizer does not provide synonyms
|
| 558 |
+
** when tokenizing query text (it should not - to do so would be
|
| 559 |
+
** inefficient), it doesn't matter if the user queries for
|
| 560 |
+
** 'first + place' or '1st + place', as there are entries in the
|
| 561 |
+
** FTS index corresponding to both forms of the first token.
|
| 562 |
+
** </ol>
|
| 563 |
+
**
|
| 564 |
+
** Whether it is parsing document or query text, any call to xToken that
|
| 565 |
+
** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit
|
| 566 |
+
** is considered to supply a synonym for the previous token. For example,
|
| 567 |
+
** when parsing the document "I won first place", a tokenizer that supports
|
| 568 |
+
** synonyms would call xToken() 5 times, as follows:
|
| 569 |
+
**
|
| 570 |
+
** <codeblock>
|
| 571 |
+
** xToken(pCtx, 0, "i", 1, 0, 1);
|
| 572 |
+
** xToken(pCtx, 0, "won", 3, 2, 5);
|
| 573 |
+
** xToken(pCtx, 0, "first", 5, 6, 11);
|
| 574 |
+
** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11);
|
| 575 |
+
** xToken(pCtx, 0, "place", 5, 12, 17);
|
| 576 |
+
**</codeblock>
|
| 577 |
+
**
|
| 578 |
+
** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
|
| 579 |
+
** xToken() is called. Multiple synonyms may be specified for a single token
|
| 580 |
+
** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
|
| 581 |
+
** There is no limit to the number of synonyms that may be provided for a
|
| 582 |
+
** single token.
|
| 583 |
+
**
|
| 584 |
+
** In many cases, method (1) above is the best approach. It does not add
|
| 585 |
+
** extra data to the FTS index or require FTS5 to query for multiple terms,
|
| 586 |
+
** so it is efficient in terms of disk space and query speed. However, it
|
| 587 |
+
** does not support prefix queries very well. If, as suggested above, the
|
| 588 |
+
** token "first" is substituted for "1st" by the tokenizer, then the query:
|
| 589 |
+
**
|
| 590 |
+
** <codeblock>
|
| 591 |
+
** ... MATCH '1s*'</codeblock>
|
| 592 |
+
**
|
| 593 |
+
** will not match documents that contain the token "1st" (as the tokenizer
|
| 594 |
+
** will probably not map "1s" to any prefix of "first").
|
| 595 |
+
**
|
| 596 |
+
** For full prefix support, method (3) may be preferred. In this case,
|
| 597 |
+
** because the index contains entries for both "first" and "1st", prefix
|
| 598 |
+
** queries such as 'fi*' or '1s*' will match correctly. However, because
|
| 599 |
+
** extra entries are added to the FTS index, this method uses more space
|
| 600 |
+
** within the database.
|
| 601 |
+
**
|
| 602 |
+
** Method (2) offers a midpoint between (1) and (3). Using this method,
|
| 603 |
+
** a query such as '1s*' will match documents that contain the literal
|
| 604 |
+
** token "1st", but not "first" (assuming the tokenizer is not able to
|
| 605 |
+
** provide synonyms for prefixes). However, a non-prefix query like '1st'
|
| 606 |
+
** will match against "1st" and "first". This method does not require
|
| 607 |
+
** extra disk space, as no extra entries are added to the FTS index.
|
| 608 |
+
** On the other hand, it may require more CPU cycles to run MATCH queries,
|
| 609 |
+
** as separate queries of the FTS index are required for each synonym.
|
| 610 |
+
**
|
| 611 |
+
** When using methods (2) or (3), it is important that the tokenizer only
|
| 612 |
+
** provide synonyms when tokenizing document text (method (3)) or query
|
| 613 |
+
** text (method (2)), not both. Doing so will not cause any errors, but is
|
| 614 |
+
** inefficient.
|
| 615 |
+
*/
|
| 616 |
+
typedef struct Fts5Tokenizer Fts5Tokenizer;
|
| 617 |
+
typedef struct fts5_tokenizer_v2 fts5_tokenizer_v2;
|
| 618 |
+
struct fts5_tokenizer_v2 {
|
| 619 |
+
int iVersion; /* Currently always 2 */
|
| 620 |
+
|
| 621 |
+
int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
|
| 622 |
+
void (*xDelete)(Fts5Tokenizer*);
|
| 623 |
+
int (*xTokenize)(Fts5Tokenizer*,
|
| 624 |
+
void *pCtx,
|
| 625 |
+
int flags, /* Mask of FTS5_TOKENIZE_* flags */
|
| 626 |
+
const char *pText, int nText,
|
| 627 |
+
const char *pLocale, int nLocale,
|
| 628 |
+
int (*xToken)(
|
| 629 |
+
void *pCtx, /* Copy of 2nd argument to xTokenize() */
|
| 630 |
+
int tflags, /* Mask of FTS5_TOKEN_* flags */
|
| 631 |
+
const char *pToken, /* Pointer to buffer containing token */
|
| 632 |
+
int nToken, /* Size of token in bytes */
|
| 633 |
+
int iStart, /* Byte offset of token within input text */
|
| 634 |
+
int iEnd /* Byte offset of end of token within input text */
|
| 635 |
+
)
|
| 636 |
+
);
|
| 637 |
+
};
|
| 638 |
+
|
| 639 |
+
/*
|
| 640 |
+
** New code should use the fts5_tokenizer_v2 type to define tokenizer
|
| 641 |
+
** implementations. The following type is included for legacy applications
|
| 642 |
+
** that still use it.
|
| 643 |
+
*/
|
| 644 |
+
typedef struct fts5_tokenizer fts5_tokenizer;
|
| 645 |
+
struct fts5_tokenizer {
|
| 646 |
+
int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
|
| 647 |
+
void (*xDelete)(Fts5Tokenizer*);
|
| 648 |
+
int (*xTokenize)(Fts5Tokenizer*,
|
| 649 |
+
void *pCtx,
|
| 650 |
+
int flags, /* Mask of FTS5_TOKENIZE_* flags */
|
| 651 |
+
const char *pText, int nText,
|
| 652 |
+
int (*xToken)(
|
| 653 |
+
void *pCtx, /* Copy of 2nd argument to xTokenize() */
|
| 654 |
+
int tflags, /* Mask of FTS5_TOKEN_* flags */
|
| 655 |
+
const char *pToken, /* Pointer to buffer containing token */
|
| 656 |
+
int nToken, /* Size of token in bytes */
|
| 657 |
+
int iStart, /* Byte offset of token within input text */
|
| 658 |
+
int iEnd /* Byte offset of end of token within input text */
|
| 659 |
+
)
|
| 660 |
+
);
|
| 661 |
+
};
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
/* Flags that may be passed as the third argument to xTokenize() */
|
| 665 |
+
#define FTS5_TOKENIZE_QUERY 0x0001
|
| 666 |
+
#define FTS5_TOKENIZE_PREFIX 0x0002
|
| 667 |
+
#define FTS5_TOKENIZE_DOCUMENT 0x0004
|
| 668 |
+
#define FTS5_TOKENIZE_AUX 0x0008
|
| 669 |
+
|
| 670 |
+
/* Flags that may be passed by the tokenizer implementation back to FTS5
|
| 671 |
+
** as the third argument to the supplied xToken callback. */
|
| 672 |
+
#define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */
|
| 673 |
+
|
| 674 |
+
/*
|
| 675 |
+
** END OF CUSTOM TOKENIZERS
|
| 676 |
+
*************************************************************************/
|
| 677 |
+
|
| 678 |
+
/*************************************************************************
|
| 679 |
+
** FTS5 EXTENSION REGISTRATION API
|
| 680 |
+
*/
|
| 681 |
+
typedef struct fts5_api fts5_api;
|
| 682 |
+
struct fts5_api {
|
| 683 |
+
int iVersion; /* Currently always set to 3 */
|
| 684 |
+
|
| 685 |
+
/* Create a new tokenizer */
|
| 686 |
+
int (*xCreateTokenizer)(
|
| 687 |
+
fts5_api *pApi,
|
| 688 |
+
const char *zName,
|
| 689 |
+
void *pUserData,
|
| 690 |
+
fts5_tokenizer *pTokenizer,
|
| 691 |
+
void (*xDestroy)(void*)
|
| 692 |
+
);
|
| 693 |
+
|
| 694 |
+
/* Find an existing tokenizer */
|
| 695 |
+
int (*xFindTokenizer)(
|
| 696 |
+
fts5_api *pApi,
|
| 697 |
+
const char *zName,
|
| 698 |
+
void **ppUserData,
|
| 699 |
+
fts5_tokenizer *pTokenizer
|
| 700 |
+
);
|
| 701 |
+
|
| 702 |
+
/* Create a new auxiliary function */
|
| 703 |
+
int (*xCreateFunction)(
|
| 704 |
+
fts5_api *pApi,
|
| 705 |
+
const char *zName,
|
| 706 |
+
void *pUserData,
|
| 707 |
+
fts5_extension_function xFunction,
|
| 708 |
+
void (*xDestroy)(void*)
|
| 709 |
+
);
|
| 710 |
+
|
| 711 |
+
/* APIs below this point are only available if iVersion>=3 */
|
| 712 |
+
|
| 713 |
+
/* Create a new tokenizer */
|
| 714 |
+
int (*xCreateTokenizer_v2)(
|
| 715 |
+
fts5_api *pApi,
|
| 716 |
+
const char *zName,
|
| 717 |
+
void *pUserData,
|
| 718 |
+
fts5_tokenizer_v2 *pTokenizer,
|
| 719 |
+
void (*xDestroy)(void*)
|
| 720 |
+
);
|
| 721 |
+
|
| 722 |
+
/* Find an existing tokenizer */
|
| 723 |
+
int (*xFindTokenizer_v2)(
|
| 724 |
+
fts5_api *pApi,
|
| 725 |
+
const char *zName,
|
| 726 |
+
void **ppUserData,
|
| 727 |
+
fts5_tokenizer_v2 **ppTokenizer
|
| 728 |
+
);
|
| 729 |
+
};
|
| 730 |
+
|
| 731 |
+
/*
|
| 732 |
+
** END OF REGISTRATION API
|
| 733 |
+
*************************************************************************/
|
| 734 |
+
|
| 735 |
+
#ifdef __cplusplus
|
| 736 |
+
} /* end of the 'extern "C"' block */
|
| 737 |
+
#endif
|
| 738 |
+
|
| 739 |
+
#endif /* _FTS5_H */
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/fts5/fts5_storage.c
ADDED
|
@@ -0,0 +1,1512 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** 2014 May 31
|
| 3 |
+
**
|
| 4 |
+
** The author disclaims copyright to this source code. In place of
|
| 5 |
+
** a legal notice, here is a blessing:
|
| 6 |
+
**
|
| 7 |
+
** May you do good and not evil.
|
| 8 |
+
** May you find forgiveness for yourself and forgive others.
|
| 9 |
+
** May you share freely, never taking more than you give.
|
| 10 |
+
**
|
| 11 |
+
******************************************************************************
|
| 12 |
+
**
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
#include "fts5Int.h"
|
| 18 |
+
|
| 19 |
+
/*
|
| 20 |
+
** pSavedRow:
|
| 21 |
+
** SQL statement FTS5_STMT_LOOKUP2 is a copy of FTS5_STMT_LOOKUP, it
|
| 22 |
+
** does a by-rowid lookup to retrieve a single row from the %_content
|
| 23 |
+
** table or equivalent external-content table/view.
|
| 24 |
+
**
|
| 25 |
+
** However, FTS5_STMT_LOOKUP2 is only used when retrieving the original
|
| 26 |
+
** values for a row being UPDATEd. In that case, the SQL statement is
|
| 27 |
+
** not reset and pSavedRow is set to point at it. This is so that the
|
| 28 |
+
** insert operation that follows the delete may access the original
|
| 29 |
+
** row values for any new values for which sqlite3_value_nochange() returns
|
| 30 |
+
** true. i.e. if the user executes:
|
| 31 |
+
**
|
| 32 |
+
** CREATE VIRTUAL TABLE ft USING fts5(a, b, c, locale=1);
|
| 33 |
+
** ...
|
| 34 |
+
** UPDATE fts SET a=?, b=? WHERE rowid=?;
|
| 35 |
+
**
|
| 36 |
+
** then the value passed to the xUpdate() method of this table as the
|
| 37 |
+
** new.c value is an sqlite3_value_nochange() value. So in this case it
|
| 38 |
+
** must be read from the saved row stored in Fts5Storage.pSavedRow.
|
| 39 |
+
**
|
| 40 |
+
** This is necessary - using sqlite3_value_nochange() instead of just having
|
| 41 |
+
** SQLite pass the original value back via xUpdate() - so as not to discard
|
| 42 |
+
** any locale information associated with such values.
|
| 43 |
+
**
|
| 44 |
+
*/
|
| 45 |
+
struct Fts5Storage {
|
| 46 |
+
Fts5Config *pConfig;
|
| 47 |
+
Fts5Index *pIndex;
|
| 48 |
+
int bTotalsValid; /* True if nTotalRow/aTotalSize[] are valid */
|
| 49 |
+
i64 nTotalRow; /* Total number of rows in FTS table */
|
| 50 |
+
i64 *aTotalSize; /* Total sizes of each column */
|
| 51 |
+
sqlite3_stmt *pSavedRow;
|
| 52 |
+
sqlite3_stmt *aStmt[12];
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
#if FTS5_STMT_SCAN_ASC!=0
|
| 57 |
+
# error "FTS5_STMT_SCAN_ASC mismatch"
|
| 58 |
+
#endif
|
| 59 |
+
#if FTS5_STMT_SCAN_DESC!=1
|
| 60 |
+
# error "FTS5_STMT_SCAN_DESC mismatch"
|
| 61 |
+
#endif
|
| 62 |
+
#if FTS5_STMT_LOOKUP!=2
|
| 63 |
+
# error "FTS5_STMT_LOOKUP mismatch"
|
| 64 |
+
#endif
|
| 65 |
+
|
| 66 |
+
#define FTS5_STMT_LOOKUP2 3
|
| 67 |
+
#define FTS5_STMT_INSERT_CONTENT 4
|
| 68 |
+
#define FTS5_STMT_REPLACE_CONTENT 5
|
| 69 |
+
#define FTS5_STMT_DELETE_CONTENT 6
|
| 70 |
+
#define FTS5_STMT_REPLACE_DOCSIZE 7
|
| 71 |
+
#define FTS5_STMT_DELETE_DOCSIZE 8
|
| 72 |
+
#define FTS5_STMT_LOOKUP_DOCSIZE 9
|
| 73 |
+
#define FTS5_STMT_REPLACE_CONFIG 10
|
| 74 |
+
#define FTS5_STMT_SCAN 11
|
| 75 |
+
|
| 76 |
+
/*
|
| 77 |
+
** Prepare the two insert statements - Fts5Storage.pInsertContent and
|
| 78 |
+
** Fts5Storage.pInsertDocsize - if they have not already been prepared.
|
| 79 |
+
** Return SQLITE_OK if successful, or an SQLite error code if an error
|
| 80 |
+
** occurs.
|
| 81 |
+
*/
|
| 82 |
+
static int fts5StorageGetStmt(
|
| 83 |
+
Fts5Storage *p, /* Storage handle */
|
| 84 |
+
int eStmt, /* FTS5_STMT_XXX constant */
|
| 85 |
+
sqlite3_stmt **ppStmt, /* OUT: Prepared statement handle */
|
| 86 |
+
char **pzErrMsg /* OUT: Error message (if any) */
|
| 87 |
+
){
|
| 88 |
+
int rc = SQLITE_OK;
|
| 89 |
+
|
| 90 |
+
/* If there is no %_docsize table, there should be no requests for
|
| 91 |
+
** statements to operate on it. */
|
| 92 |
+
assert( p->pConfig->bColumnsize || (
|
| 93 |
+
eStmt!=FTS5_STMT_REPLACE_DOCSIZE
|
| 94 |
+
&& eStmt!=FTS5_STMT_DELETE_DOCSIZE
|
| 95 |
+
&& eStmt!=FTS5_STMT_LOOKUP_DOCSIZE
|
| 96 |
+
));
|
| 97 |
+
|
| 98 |
+
assert( eStmt>=0 && eStmt<ArraySize(p->aStmt) );
|
| 99 |
+
if( p->aStmt[eStmt]==0 ){
|
| 100 |
+
const char *azStmt[] = {
|
| 101 |
+
"SELECT %s FROM %s T WHERE T.%Q >= ? AND T.%Q <= ? ORDER BY T.%Q ASC",
|
| 102 |
+
"SELECT %s FROM %s T WHERE T.%Q <= ? AND T.%Q >= ? ORDER BY T.%Q DESC",
|
| 103 |
+
"SELECT %s FROM %s T WHERE T.%Q=?", /* LOOKUP */
|
| 104 |
+
"SELECT %s FROM %s T WHERE T.%Q=?", /* LOOKUP2 */
|
| 105 |
+
|
| 106 |
+
"INSERT INTO %Q.'%q_content' VALUES(%s)", /* INSERT_CONTENT */
|
| 107 |
+
"REPLACE INTO %Q.'%q_content' VALUES(%s)", /* REPLACE_CONTENT */
|
| 108 |
+
"DELETE FROM %Q.'%q_content' WHERE id=?", /* DELETE_CONTENT */
|
| 109 |
+
"REPLACE INTO %Q.'%q_docsize' VALUES(?,?%s)", /* REPLACE_DOCSIZE */
|
| 110 |
+
"DELETE FROM %Q.'%q_docsize' WHERE id=?", /* DELETE_DOCSIZE */
|
| 111 |
+
|
| 112 |
+
"SELECT sz%s FROM %Q.'%q_docsize' WHERE id=?", /* LOOKUP_DOCSIZE */
|
| 113 |
+
|
| 114 |
+
"REPLACE INTO %Q.'%q_config' VALUES(?,?)", /* REPLACE_CONFIG */
|
| 115 |
+
"SELECT %s FROM %s AS T", /* SCAN */
|
| 116 |
+
};
|
| 117 |
+
Fts5Config *pC = p->pConfig;
|
| 118 |
+
char *zSql = 0;
|
| 119 |
+
|
| 120 |
+
assert( ArraySize(azStmt)==ArraySize(p->aStmt) );
|
| 121 |
+
|
| 122 |
+
switch( eStmt ){
|
| 123 |
+
case FTS5_STMT_SCAN:
|
| 124 |
+
zSql = sqlite3_mprintf(azStmt[eStmt],
|
| 125 |
+
pC->zContentExprlist, pC->zContent
|
| 126 |
+
);
|
| 127 |
+
break;
|
| 128 |
+
|
| 129 |
+
case FTS5_STMT_SCAN_ASC:
|
| 130 |
+
case FTS5_STMT_SCAN_DESC:
|
| 131 |
+
zSql = sqlite3_mprintf(azStmt[eStmt], pC->zContentExprlist,
|
| 132 |
+
pC->zContent, pC->zContentRowid, pC->zContentRowid,
|
| 133 |
+
pC->zContentRowid
|
| 134 |
+
);
|
| 135 |
+
break;
|
| 136 |
+
|
| 137 |
+
case FTS5_STMT_LOOKUP:
|
| 138 |
+
case FTS5_STMT_LOOKUP2:
|
| 139 |
+
zSql = sqlite3_mprintf(azStmt[eStmt],
|
| 140 |
+
pC->zContentExprlist, pC->zContent, pC->zContentRowid
|
| 141 |
+
);
|
| 142 |
+
break;
|
| 143 |
+
|
| 144 |
+
case FTS5_STMT_INSERT_CONTENT:
|
| 145 |
+
case FTS5_STMT_REPLACE_CONTENT: {
|
| 146 |
+
char *zBind = 0;
|
| 147 |
+
int i;
|
| 148 |
+
|
| 149 |
+
assert( pC->eContent==FTS5_CONTENT_NORMAL
|
| 150 |
+
|| pC->eContent==FTS5_CONTENT_UNINDEXED
|
| 151 |
+
);
|
| 152 |
+
|
| 153 |
+
/* Add bindings for the "c*" columns - those that store the actual
|
| 154 |
+
** table content. If eContent==NORMAL, then there is one binding
|
| 155 |
+
** for each column. Or, if eContent==UNINDEXED, then there are only
|
| 156 |
+
** bindings for the UNINDEXED columns. */
|
| 157 |
+
for(i=0; rc==SQLITE_OK && i<(pC->nCol+1); i++){
|
| 158 |
+
if( !i || pC->eContent==FTS5_CONTENT_NORMAL || pC->abUnindexed[i-1] ){
|
| 159 |
+
zBind = sqlite3Fts5Mprintf(&rc, "%z%s?%d", zBind, zBind?",":"",i+1);
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/* Add bindings for any "l*" columns. Only non-UNINDEXED columns
|
| 164 |
+
** require these. */
|
| 165 |
+
if( pC->bLocale && pC->eContent==FTS5_CONTENT_NORMAL ){
|
| 166 |
+
for(i=0; rc==SQLITE_OK && i<pC->nCol; i++){
|
| 167 |
+
if( pC->abUnindexed[i]==0 ){
|
| 168 |
+
zBind = sqlite3Fts5Mprintf(&rc, "%z,?%d", zBind, pC->nCol+i+2);
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
zSql = sqlite3Fts5Mprintf(&rc, azStmt[eStmt], pC->zDb, pC->zName,zBind);
|
| 174 |
+
sqlite3_free(zBind);
|
| 175 |
+
break;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
case FTS5_STMT_REPLACE_DOCSIZE:
|
| 179 |
+
zSql = sqlite3_mprintf(azStmt[eStmt], pC->zDb, pC->zName,
|
| 180 |
+
(pC->bContentlessDelete ? ",?" : "")
|
| 181 |
+
);
|
| 182 |
+
break;
|
| 183 |
+
|
| 184 |
+
case FTS5_STMT_LOOKUP_DOCSIZE:
|
| 185 |
+
zSql = sqlite3_mprintf(azStmt[eStmt],
|
| 186 |
+
(pC->bContentlessDelete ? ",origin" : ""),
|
| 187 |
+
pC->zDb, pC->zName
|
| 188 |
+
);
|
| 189 |
+
break;
|
| 190 |
+
|
| 191 |
+
default:
|
| 192 |
+
zSql = sqlite3_mprintf(azStmt[eStmt], pC->zDb, pC->zName);
|
| 193 |
+
break;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
if( zSql==0 ){
|
| 197 |
+
rc = SQLITE_NOMEM;
|
| 198 |
+
}else{
|
| 199 |
+
int f = SQLITE_PREPARE_PERSISTENT;
|
| 200 |
+
if( eStmt>FTS5_STMT_LOOKUP2 ) f |= SQLITE_PREPARE_NO_VTAB;
|
| 201 |
+
p->pConfig->bLock++;
|
| 202 |
+
rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
|
| 203 |
+
p->pConfig->bLock--;
|
| 204 |
+
sqlite3_free(zSql);
|
| 205 |
+
if( rc!=SQLITE_OK && pzErrMsg ){
|
| 206 |
+
*pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
*ppStmt = p->aStmt[eStmt];
|
| 212 |
+
sqlite3_reset(*ppStmt);
|
| 213 |
+
return rc;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
static int fts5ExecPrintf(
|
| 218 |
+
sqlite3 *db,
|
| 219 |
+
char **pzErr,
|
| 220 |
+
const char *zFormat,
|
| 221 |
+
...
|
| 222 |
+
){
|
| 223 |
+
int rc;
|
| 224 |
+
va_list ap; /* ... printf arguments */
|
| 225 |
+
char *zSql;
|
| 226 |
+
|
| 227 |
+
va_start(ap, zFormat);
|
| 228 |
+
zSql = sqlite3_vmprintf(zFormat, ap);
|
| 229 |
+
|
| 230 |
+
if( zSql==0 ){
|
| 231 |
+
rc = SQLITE_NOMEM;
|
| 232 |
+
}else{
|
| 233 |
+
rc = sqlite3_exec(db, zSql, 0, 0, pzErr);
|
| 234 |
+
sqlite3_free(zSql);
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
va_end(ap);
|
| 238 |
+
return rc;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
/*
|
| 242 |
+
** Drop all shadow tables. Return SQLITE_OK if successful or an SQLite error
|
| 243 |
+
** code otherwise.
|
| 244 |
+
*/
|
| 245 |
+
int sqlite3Fts5DropAll(Fts5Config *pConfig){
|
| 246 |
+
int rc = fts5ExecPrintf(pConfig->db, 0,
|
| 247 |
+
"DROP TABLE IF EXISTS %Q.'%q_data';"
|
| 248 |
+
"DROP TABLE IF EXISTS %Q.'%q_idx';"
|
| 249 |
+
"DROP TABLE IF EXISTS %Q.'%q_config';",
|
| 250 |
+
pConfig->zDb, pConfig->zName,
|
| 251 |
+
pConfig->zDb, pConfig->zName,
|
| 252 |
+
pConfig->zDb, pConfig->zName
|
| 253 |
+
);
|
| 254 |
+
if( rc==SQLITE_OK && pConfig->bColumnsize ){
|
| 255 |
+
rc = fts5ExecPrintf(pConfig->db, 0,
|
| 256 |
+
"DROP TABLE IF EXISTS %Q.'%q_docsize';",
|
| 257 |
+
pConfig->zDb, pConfig->zName
|
| 258 |
+
);
|
| 259 |
+
}
|
| 260 |
+
if( rc==SQLITE_OK && pConfig->eContent==FTS5_CONTENT_NORMAL ){
|
| 261 |
+
rc = fts5ExecPrintf(pConfig->db, 0,
|
| 262 |
+
"DROP TABLE IF EXISTS %Q.'%q_content';",
|
| 263 |
+
pConfig->zDb, pConfig->zName
|
| 264 |
+
);
|
| 265 |
+
}
|
| 266 |
+
return rc;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
static void fts5StorageRenameOne(
|
| 270 |
+
Fts5Config *pConfig, /* Current FTS5 configuration */
|
| 271 |
+
int *pRc, /* IN/OUT: Error code */
|
| 272 |
+
const char *zTail, /* Tail of table name e.g. "data", "config" */
|
| 273 |
+
const char *zName /* New name of FTS5 table */
|
| 274 |
+
){
|
| 275 |
+
if( *pRc==SQLITE_OK ){
|
| 276 |
+
*pRc = fts5ExecPrintf(pConfig->db, 0,
|
| 277 |
+
"ALTER TABLE %Q.'%q_%s' RENAME TO '%q_%s';",
|
| 278 |
+
pConfig->zDb, pConfig->zName, zTail, zName, zTail
|
| 279 |
+
);
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
|
| 284 |
+
Fts5Config *pConfig = pStorage->pConfig;
|
| 285 |
+
int rc = sqlite3Fts5StorageSync(pStorage);
|
| 286 |
+
|
| 287 |
+
fts5StorageRenameOne(pConfig, &rc, "data", zName);
|
| 288 |
+
fts5StorageRenameOne(pConfig, &rc, "idx", zName);
|
| 289 |
+
fts5StorageRenameOne(pConfig, &rc, "config", zName);
|
| 290 |
+
if( pConfig->bColumnsize ){
|
| 291 |
+
fts5StorageRenameOne(pConfig, &rc, "docsize", zName);
|
| 292 |
+
}
|
| 293 |
+
if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
|
| 294 |
+
fts5StorageRenameOne(pConfig, &rc, "content", zName);
|
| 295 |
+
}
|
| 296 |
+
return rc;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
/*
|
| 300 |
+
** Create the shadow table named zPost, with definition zDefn. Return
|
| 301 |
+
** SQLITE_OK if successful, or an SQLite error code otherwise.
|
| 302 |
+
*/
|
| 303 |
+
int sqlite3Fts5CreateTable(
|
| 304 |
+
Fts5Config *pConfig, /* FTS5 configuration */
|
| 305 |
+
const char *zPost, /* Shadow table to create (e.g. "content") */
|
| 306 |
+
const char *zDefn, /* Columns etc. for shadow table */
|
| 307 |
+
int bWithout, /* True for without rowid */
|
| 308 |
+
char **pzErr /* OUT: Error message */
|
| 309 |
+
){
|
| 310 |
+
int rc;
|
| 311 |
+
char *zErr = 0;
|
| 312 |
+
|
| 313 |
+
rc = fts5ExecPrintf(pConfig->db, &zErr, "CREATE TABLE %Q.'%q_%q'(%s)%s",
|
| 314 |
+
pConfig->zDb, pConfig->zName, zPost, zDefn,
|
| 315 |
+
#ifndef SQLITE_FTS5_NO_WITHOUT_ROWID
|
| 316 |
+
bWithout?" WITHOUT ROWID":
|
| 317 |
+
#endif
|
| 318 |
+
""
|
| 319 |
+
);
|
| 320 |
+
if( zErr ){
|
| 321 |
+
*pzErr = sqlite3_mprintf(
|
| 322 |
+
"fts5: error creating shadow table %q_%s: %s",
|
| 323 |
+
pConfig->zName, zPost, zErr
|
| 324 |
+
);
|
| 325 |
+
sqlite3_free(zErr);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
return rc;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
/*
|
| 332 |
+
** Open a new Fts5Index handle. If the bCreate argument is true, create
|
| 333 |
+
** and initialize the underlying tables
|
| 334 |
+
**
|
| 335 |
+
** If successful, set *pp to point to the new object and return SQLITE_OK.
|
| 336 |
+
** Otherwise, set *pp to NULL and return an SQLite error code.
|
| 337 |
+
*/
|
| 338 |
+
int sqlite3Fts5StorageOpen(
|
| 339 |
+
Fts5Config *pConfig,
|
| 340 |
+
Fts5Index *pIndex,
|
| 341 |
+
int bCreate,
|
| 342 |
+
Fts5Storage **pp,
|
| 343 |
+
char **pzErr /* OUT: Error message */
|
| 344 |
+
){
|
| 345 |
+
int rc = SQLITE_OK;
|
| 346 |
+
Fts5Storage *p; /* New object */
|
| 347 |
+
sqlite3_int64 nByte; /* Bytes of space to allocate */
|
| 348 |
+
|
| 349 |
+
nByte = sizeof(Fts5Storage) /* Fts5Storage object */
|
| 350 |
+
+ pConfig->nCol * sizeof(i64); /* Fts5Storage.aTotalSize[] */
|
| 351 |
+
*pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
|
| 352 |
+
if( !p ) return SQLITE_NOMEM;
|
| 353 |
+
|
| 354 |
+
memset(p, 0, (size_t)nByte);
|
| 355 |
+
p->aTotalSize = (i64*)&p[1];
|
| 356 |
+
p->pConfig = pConfig;
|
| 357 |
+
p->pIndex = pIndex;
|
| 358 |
+
|
| 359 |
+
if( bCreate ){
|
| 360 |
+
if( pConfig->eContent==FTS5_CONTENT_NORMAL
|
| 361 |
+
|| pConfig->eContent==FTS5_CONTENT_UNINDEXED
|
| 362 |
+
){
|
| 363 |
+
int nDefn = 32 + pConfig->nCol*10;
|
| 364 |
+
char *zDefn = sqlite3_malloc64(32 + (sqlite3_int64)pConfig->nCol * 20);
|
| 365 |
+
if( zDefn==0 ){
|
| 366 |
+
rc = SQLITE_NOMEM;
|
| 367 |
+
}else{
|
| 368 |
+
int i;
|
| 369 |
+
int iOff;
|
| 370 |
+
sqlite3_snprintf(nDefn, zDefn, "id INTEGER PRIMARY KEY");
|
| 371 |
+
iOff = (int)strlen(zDefn);
|
| 372 |
+
for(i=0; i<pConfig->nCol; i++){
|
| 373 |
+
if( pConfig->eContent==FTS5_CONTENT_NORMAL
|
| 374 |
+
|| pConfig->abUnindexed[i]
|
| 375 |
+
){
|
| 376 |
+
sqlite3_snprintf(nDefn-iOff, &zDefn[iOff], ", c%d", i);
|
| 377 |
+
iOff += (int)strlen(&zDefn[iOff]);
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
if( pConfig->bLocale ){
|
| 381 |
+
for(i=0; i<pConfig->nCol; i++){
|
| 382 |
+
if( pConfig->abUnindexed[i]==0 ){
|
| 383 |
+
sqlite3_snprintf(nDefn-iOff, &zDefn[iOff], ", l%d", i);
|
| 384 |
+
iOff += (int)strlen(&zDefn[iOff]);
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
rc = sqlite3Fts5CreateTable(pConfig, "content", zDefn, 0, pzErr);
|
| 389 |
+
}
|
| 390 |
+
sqlite3_free(zDefn);
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
if( rc==SQLITE_OK && pConfig->bColumnsize ){
|
| 394 |
+
const char *zCols = "id INTEGER PRIMARY KEY, sz BLOB";
|
| 395 |
+
if( pConfig->bContentlessDelete ){
|
| 396 |
+
zCols = "id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER";
|
| 397 |
+
}
|
| 398 |
+
rc = sqlite3Fts5CreateTable(pConfig, "docsize", zCols, 0, pzErr);
|
| 399 |
+
}
|
| 400 |
+
if( rc==SQLITE_OK ){
|
| 401 |
+
rc = sqlite3Fts5CreateTable(
|
| 402 |
+
pConfig, "config", "k PRIMARY KEY, v", 1, pzErr
|
| 403 |
+
);
|
| 404 |
+
}
|
| 405 |
+
if( rc==SQLITE_OK ){
|
| 406 |
+
rc = sqlite3Fts5StorageConfigValue(p, "version", 0, FTS5_CURRENT_VERSION);
|
| 407 |
+
}
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
if( rc ){
|
| 411 |
+
sqlite3Fts5StorageClose(p);
|
| 412 |
+
*pp = 0;
|
| 413 |
+
}
|
| 414 |
+
return rc;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
/*
|
| 418 |
+
** Close a handle opened by an earlier call to sqlite3Fts5StorageOpen().
|
| 419 |
+
*/
|
| 420 |
+
int sqlite3Fts5StorageClose(Fts5Storage *p){
|
| 421 |
+
int rc = SQLITE_OK;
|
| 422 |
+
if( p ){
|
| 423 |
+
int i;
|
| 424 |
+
|
| 425 |
+
/* Finalize all SQL statements */
|
| 426 |
+
for(i=0; i<ArraySize(p->aStmt); i++){
|
| 427 |
+
sqlite3_finalize(p->aStmt[i]);
|
| 428 |
+
}
|
| 429 |
+
|
| 430 |
+
sqlite3_free(p);
|
| 431 |
+
}
|
| 432 |
+
return rc;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
typedef struct Fts5InsertCtx Fts5InsertCtx;
|
| 436 |
+
struct Fts5InsertCtx {
|
| 437 |
+
Fts5Storage *pStorage;
|
| 438 |
+
int iCol;
|
| 439 |
+
int szCol; /* Size of column value in tokens */
|
| 440 |
+
};
|
| 441 |
+
|
| 442 |
+
/*
|
| 443 |
+
** Tokenization callback used when inserting tokens into the FTS index.
|
| 444 |
+
*/
|
| 445 |
+
static int fts5StorageInsertCallback(
|
| 446 |
+
void *pContext, /* Pointer to Fts5InsertCtx object */
|
| 447 |
+
int tflags,
|
| 448 |
+
const char *pToken, /* Buffer containing token */
|
| 449 |
+
int nToken, /* Size of token in bytes */
|
| 450 |
+
int iUnused1, /* Start offset of token */
|
| 451 |
+
int iUnused2 /* End offset of token */
|
| 452 |
+
){
|
| 453 |
+
Fts5InsertCtx *pCtx = (Fts5InsertCtx*)pContext;
|
| 454 |
+
Fts5Index *pIdx = pCtx->pStorage->pIndex;
|
| 455 |
+
UNUSED_PARAM2(iUnused1, iUnused2);
|
| 456 |
+
if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
|
| 457 |
+
if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
|
| 458 |
+
pCtx->szCol++;
|
| 459 |
+
}
|
| 460 |
+
return sqlite3Fts5IndexWrite(pIdx, pCtx->iCol, pCtx->szCol-1, pToken, nToken);
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
/*
|
| 464 |
+
** This function is used as part of an UPDATE statement that modifies the
|
| 465 |
+
** rowid of a row. In that case, this function is called first to set
|
| 466 |
+
** Fts5Storage.pSavedRow to point to a statement that may be used to
|
| 467 |
+
** access the original values of the row being deleted - iDel.
|
| 468 |
+
**
|
| 469 |
+
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
|
| 470 |
+
** It is not considered an error if row iDel does not exist. In this case
|
| 471 |
+
** pSavedRow is not set and SQLITE_OK returned.
|
| 472 |
+
*/
|
| 473 |
+
int sqlite3Fts5StorageFindDeleteRow(Fts5Storage *p, i64 iDel){
|
| 474 |
+
int rc = SQLITE_OK;
|
| 475 |
+
sqlite3_stmt *pSeek = 0;
|
| 476 |
+
|
| 477 |
+
assert( p->pSavedRow==0 );
|
| 478 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP+1, &pSeek, 0);
|
| 479 |
+
if( rc==SQLITE_OK ){
|
| 480 |
+
sqlite3_bind_int64(pSeek, 1, iDel);
|
| 481 |
+
if( sqlite3_step(pSeek)!=SQLITE_ROW ){
|
| 482 |
+
rc = sqlite3_reset(pSeek);
|
| 483 |
+
}else{
|
| 484 |
+
p->pSavedRow = pSeek;
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
return rc;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
/*
|
| 492 |
+
** If a row with rowid iDel is present in the %_content table, add the
|
| 493 |
+
** delete-markers to the FTS index necessary to delete it. Do not actually
|
| 494 |
+
** remove the %_content row at this time though.
|
| 495 |
+
**
|
| 496 |
+
** If parameter bSaveRow is true, then Fts5Storage.pSavedRow is left
|
| 497 |
+
** pointing to a statement (FTS5_STMT_LOOKUP2) that may be used to access
|
| 498 |
+
** the original values of the row being deleted. This is used by UPDATE
|
| 499 |
+
** statements.
|
| 500 |
+
*/
|
| 501 |
+
static int fts5StorageDeleteFromIndex(
|
| 502 |
+
Fts5Storage *p,
|
| 503 |
+
i64 iDel,
|
| 504 |
+
sqlite3_value **apVal,
|
| 505 |
+
int bSaveRow /* True to set pSavedRow */
|
| 506 |
+
){
|
| 507 |
+
Fts5Config *pConfig = p->pConfig;
|
| 508 |
+
sqlite3_stmt *pSeek = 0; /* SELECT to read row iDel from %_data */
|
| 509 |
+
int rc = SQLITE_OK; /* Return code */
|
| 510 |
+
int rc2; /* sqlite3_reset() return code */
|
| 511 |
+
int iCol;
|
| 512 |
+
Fts5InsertCtx ctx;
|
| 513 |
+
|
| 514 |
+
assert( bSaveRow==0 || apVal==0 );
|
| 515 |
+
assert( bSaveRow==0 || bSaveRow==1 );
|
| 516 |
+
assert( FTS5_STMT_LOOKUP2==FTS5_STMT_LOOKUP+1 );
|
| 517 |
+
|
| 518 |
+
if( apVal==0 ){
|
| 519 |
+
if( p->pSavedRow && bSaveRow ){
|
| 520 |
+
pSeek = p->pSavedRow;
|
| 521 |
+
p->pSavedRow = 0;
|
| 522 |
+
}else{
|
| 523 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP+bSaveRow, &pSeek, 0);
|
| 524 |
+
if( rc!=SQLITE_OK ) return rc;
|
| 525 |
+
sqlite3_bind_int64(pSeek, 1, iDel);
|
| 526 |
+
if( sqlite3_step(pSeek)!=SQLITE_ROW ){
|
| 527 |
+
return sqlite3_reset(pSeek);
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
ctx.pStorage = p;
|
| 533 |
+
ctx.iCol = -1;
|
| 534 |
+
for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
|
| 535 |
+
if( pConfig->abUnindexed[iCol-1]==0 ){
|
| 536 |
+
sqlite3_value *pVal = 0;
|
| 537 |
+
const char *pText = 0;
|
| 538 |
+
int nText = 0;
|
| 539 |
+
const char *pLoc = 0;
|
| 540 |
+
int nLoc = 0;
|
| 541 |
+
|
| 542 |
+
assert( pSeek==0 || apVal==0 );
|
| 543 |
+
assert( pSeek!=0 || apVal!=0 );
|
| 544 |
+
if( pSeek ){
|
| 545 |
+
pVal = sqlite3_column_value(pSeek, iCol);
|
| 546 |
+
}else{
|
| 547 |
+
pVal = apVal[iCol-1];
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
|
| 551 |
+
rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
|
| 552 |
+
}else{
|
| 553 |
+
pText = (const char*)sqlite3_value_text(pVal);
|
| 554 |
+
nText = sqlite3_value_bytes(pVal);
|
| 555 |
+
if( pConfig->bLocale && pSeek ){
|
| 556 |
+
pLoc = (const char*)sqlite3_column_text(pSeek, iCol + pConfig->nCol);
|
| 557 |
+
nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol);
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
if( rc==SQLITE_OK ){
|
| 562 |
+
sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
|
| 563 |
+
ctx.szCol = 0;
|
| 564 |
+
rc = sqlite3Fts5Tokenize(pConfig, FTS5_TOKENIZE_DOCUMENT,
|
| 565 |
+
pText, nText, (void*)&ctx, fts5StorageInsertCallback
|
| 566 |
+
);
|
| 567 |
+
p->aTotalSize[iCol-1] -= (i64)ctx.szCol;
|
| 568 |
+
if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){
|
| 569 |
+
rc = FTS5_CORRUPT;
|
| 570 |
+
}
|
| 571 |
+
sqlite3Fts5ClearLocale(pConfig);
|
| 572 |
+
}
|
| 573 |
+
}
|
| 574 |
+
}
|
| 575 |
+
if( rc==SQLITE_OK && p->nTotalRow<1 ){
|
| 576 |
+
rc = FTS5_CORRUPT;
|
| 577 |
+
}else{
|
| 578 |
+
p->nTotalRow--;
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
if( rc==SQLITE_OK && bSaveRow ){
|
| 582 |
+
assert( p->pSavedRow==0 );
|
| 583 |
+
p->pSavedRow = pSeek;
|
| 584 |
+
}else{
|
| 585 |
+
rc2 = sqlite3_reset(pSeek);
|
| 586 |
+
if( rc==SQLITE_OK ) rc = rc2;
|
| 587 |
+
}
|
| 588 |
+
return rc;
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
/*
|
| 592 |
+
** Reset any saved statement pSavedRow. Zero pSavedRow as well. This
|
| 593 |
+
** should be called by the xUpdate() method of the fts5 table before
|
| 594 |
+
** returning from any operation that may have set Fts5Storage.pSavedRow.
|
| 595 |
+
*/
|
| 596 |
+
void sqlite3Fts5StorageReleaseDeleteRow(Fts5Storage *pStorage){
|
| 597 |
+
assert( pStorage->pSavedRow==0
|
| 598 |
+
|| pStorage->pSavedRow==pStorage->aStmt[FTS5_STMT_LOOKUP2]
|
| 599 |
+
);
|
| 600 |
+
sqlite3_reset(pStorage->pSavedRow);
|
| 601 |
+
pStorage->pSavedRow = 0;
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
/*
|
| 605 |
+
** This function is called to process a DELETE on a contentless_delete=1
|
| 606 |
+
** table. It adds the tombstone required to delete the entry with rowid
|
| 607 |
+
** iDel. If successful, SQLITE_OK is returned. Or, if an error occurs,
|
| 608 |
+
** an SQLite error code.
|
| 609 |
+
*/
|
| 610 |
+
static int fts5StorageContentlessDelete(Fts5Storage *p, i64 iDel){
|
| 611 |
+
i64 iOrigin = 0;
|
| 612 |
+
sqlite3_stmt *pLookup = 0;
|
| 613 |
+
int rc = SQLITE_OK;
|
| 614 |
+
|
| 615 |
+
assert( p->pConfig->bContentlessDelete );
|
| 616 |
+
assert( p->pConfig->eContent==FTS5_CONTENT_NONE
|
| 617 |
+
|| p->pConfig->eContent==FTS5_CONTENT_UNINDEXED
|
| 618 |
+
);
|
| 619 |
+
|
| 620 |
+
/* Look up the origin of the document in the %_docsize table. Store
|
| 621 |
+
** this in stack variable iOrigin. */
|
| 622 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
|
| 623 |
+
if( rc==SQLITE_OK ){
|
| 624 |
+
sqlite3_bind_int64(pLookup, 1, iDel);
|
| 625 |
+
if( SQLITE_ROW==sqlite3_step(pLookup) ){
|
| 626 |
+
iOrigin = sqlite3_column_int64(pLookup, 1);
|
| 627 |
+
}
|
| 628 |
+
rc = sqlite3_reset(pLookup);
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
if( rc==SQLITE_OK && iOrigin!=0 ){
|
| 632 |
+
rc = sqlite3Fts5IndexContentlessDelete(p->pIndex, iOrigin, iDel);
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
return rc;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
/*
|
| 639 |
+
** Insert a record into the %_docsize table. Specifically, do:
|
| 640 |
+
**
|
| 641 |
+
** INSERT OR REPLACE INTO %_docsize(id, sz) VALUES(iRowid, pBuf);
|
| 642 |
+
**
|
| 643 |
+
** If there is no %_docsize table (as happens if the columnsize=0 option
|
| 644 |
+
** is specified when the FTS5 table is created), this function is a no-op.
|
| 645 |
+
*/
|
| 646 |
+
static int fts5StorageInsertDocsize(
|
| 647 |
+
Fts5Storage *p, /* Storage module to write to */
|
| 648 |
+
i64 iRowid, /* id value */
|
| 649 |
+
Fts5Buffer *pBuf /* sz value */
|
| 650 |
+
){
|
| 651 |
+
int rc = SQLITE_OK;
|
| 652 |
+
if( p->pConfig->bColumnsize ){
|
| 653 |
+
sqlite3_stmt *pReplace = 0;
|
| 654 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
|
| 655 |
+
if( rc==SQLITE_OK ){
|
| 656 |
+
sqlite3_bind_int64(pReplace, 1, iRowid);
|
| 657 |
+
if( p->pConfig->bContentlessDelete ){
|
| 658 |
+
i64 iOrigin = 0;
|
| 659 |
+
rc = sqlite3Fts5IndexGetOrigin(p->pIndex, &iOrigin);
|
| 660 |
+
sqlite3_bind_int64(pReplace, 3, iOrigin);
|
| 661 |
+
}
|
| 662 |
+
}
|
| 663 |
+
if( rc==SQLITE_OK ){
|
| 664 |
+
sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC);
|
| 665 |
+
sqlite3_step(pReplace);
|
| 666 |
+
rc = sqlite3_reset(pReplace);
|
| 667 |
+
sqlite3_bind_null(pReplace, 2);
|
| 668 |
+
}
|
| 669 |
+
}
|
| 670 |
+
return rc;
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
/*
|
| 674 |
+
** Load the contents of the "averages" record from disk into the
|
| 675 |
+
** p->nTotalRow and p->aTotalSize[] variables. If successful, and if
|
| 676 |
+
** argument bCache is true, set the p->bTotalsValid flag to indicate
|
| 677 |
+
** that the contents of aTotalSize[] and nTotalRow are valid until
|
| 678 |
+
** further notice.
|
| 679 |
+
**
|
| 680 |
+
** Return SQLITE_OK if successful, or an SQLite error code if an error
|
| 681 |
+
** occurs.
|
| 682 |
+
*/
|
| 683 |
+
static int fts5StorageLoadTotals(Fts5Storage *p, int bCache){
|
| 684 |
+
int rc = SQLITE_OK;
|
| 685 |
+
if( p->bTotalsValid==0 ){
|
| 686 |
+
rc = sqlite3Fts5IndexGetAverages(p->pIndex, &p->nTotalRow, p->aTotalSize);
|
| 687 |
+
p->bTotalsValid = bCache;
|
| 688 |
+
}
|
| 689 |
+
return rc;
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
/*
|
| 693 |
+
** Store the current contents of the p->nTotalRow and p->aTotalSize[]
|
| 694 |
+
** variables in the "averages" record on disk.
|
| 695 |
+
**
|
| 696 |
+
** Return SQLITE_OK if successful, or an SQLite error code if an error
|
| 697 |
+
** occurs.
|
| 698 |
+
*/
|
| 699 |
+
static int fts5StorageSaveTotals(Fts5Storage *p){
|
| 700 |
+
int nCol = p->pConfig->nCol;
|
| 701 |
+
int i;
|
| 702 |
+
Fts5Buffer buf;
|
| 703 |
+
int rc = SQLITE_OK;
|
| 704 |
+
memset(&buf, 0, sizeof(buf));
|
| 705 |
+
|
| 706 |
+
sqlite3Fts5BufferAppendVarint(&rc, &buf, p->nTotalRow);
|
| 707 |
+
for(i=0; i<nCol; i++){
|
| 708 |
+
sqlite3Fts5BufferAppendVarint(&rc, &buf, p->aTotalSize[i]);
|
| 709 |
+
}
|
| 710 |
+
if( rc==SQLITE_OK ){
|
| 711 |
+
rc = sqlite3Fts5IndexSetAverages(p->pIndex, buf.p, buf.n);
|
| 712 |
+
}
|
| 713 |
+
sqlite3_free(buf.p);
|
| 714 |
+
|
| 715 |
+
return rc;
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
/*
|
| 719 |
+
** Remove a row from the FTS table.
|
| 720 |
+
*/
|
| 721 |
+
int sqlite3Fts5StorageDelete(
|
| 722 |
+
Fts5Storage *p, /* Storage object */
|
| 723 |
+
i64 iDel, /* Rowid to delete from table */
|
| 724 |
+
sqlite3_value **apVal, /* Optional - values to remove from index */
|
| 725 |
+
int bSaveRow /* If true, set pSavedRow for deleted row */
|
| 726 |
+
){
|
| 727 |
+
Fts5Config *pConfig = p->pConfig;
|
| 728 |
+
int rc;
|
| 729 |
+
sqlite3_stmt *pDel = 0;
|
| 730 |
+
|
| 731 |
+
assert( pConfig->eContent!=FTS5_CONTENT_NORMAL || apVal==0 );
|
| 732 |
+
rc = fts5StorageLoadTotals(p, 1);
|
| 733 |
+
|
| 734 |
+
/* Delete the index records */
|
| 735 |
+
if( rc==SQLITE_OK ){
|
| 736 |
+
rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel);
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
if( rc==SQLITE_OK ){
|
| 740 |
+
if( p->pConfig->bContentlessDelete ){
|
| 741 |
+
rc = fts5StorageContentlessDelete(p, iDel);
|
| 742 |
+
if( rc==SQLITE_OK
|
| 743 |
+
&& bSaveRow
|
| 744 |
+
&& p->pConfig->eContent==FTS5_CONTENT_UNINDEXED
|
| 745 |
+
){
|
| 746 |
+
rc = sqlite3Fts5StorageFindDeleteRow(p, iDel);
|
| 747 |
+
}
|
| 748 |
+
}else{
|
| 749 |
+
rc = fts5StorageDeleteFromIndex(p, iDel, apVal, bSaveRow);
|
| 750 |
+
}
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
/* Delete the %_docsize record */
|
| 754 |
+
if( rc==SQLITE_OK && pConfig->bColumnsize ){
|
| 755 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_DOCSIZE, &pDel, 0);
|
| 756 |
+
if( rc==SQLITE_OK ){
|
| 757 |
+
sqlite3_bind_int64(pDel, 1, iDel);
|
| 758 |
+
sqlite3_step(pDel);
|
| 759 |
+
rc = sqlite3_reset(pDel);
|
| 760 |
+
}
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
/* Delete the %_content record */
|
| 764 |
+
if( pConfig->eContent==FTS5_CONTENT_NORMAL
|
| 765 |
+
|| pConfig->eContent==FTS5_CONTENT_UNINDEXED
|
| 766 |
+
){
|
| 767 |
+
if( rc==SQLITE_OK ){
|
| 768 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_DELETE_CONTENT, &pDel, 0);
|
| 769 |
+
}
|
| 770 |
+
if( rc==SQLITE_OK ){
|
| 771 |
+
sqlite3_bind_int64(pDel, 1, iDel);
|
| 772 |
+
sqlite3_step(pDel);
|
| 773 |
+
rc = sqlite3_reset(pDel);
|
| 774 |
+
}
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
return rc;
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
/*
|
| 781 |
+
** Delete all entries in the FTS5 index.
|
| 782 |
+
*/
|
| 783 |
+
int sqlite3Fts5StorageDeleteAll(Fts5Storage *p){
|
| 784 |
+
Fts5Config *pConfig = p->pConfig;
|
| 785 |
+
int rc;
|
| 786 |
+
|
| 787 |
+
p->bTotalsValid = 0;
|
| 788 |
+
|
| 789 |
+
/* Delete the contents of the %_data and %_docsize tables. */
|
| 790 |
+
rc = fts5ExecPrintf(pConfig->db, 0,
|
| 791 |
+
"DELETE FROM %Q.'%q_data';"
|
| 792 |
+
"DELETE FROM %Q.'%q_idx';",
|
| 793 |
+
pConfig->zDb, pConfig->zName,
|
| 794 |
+
pConfig->zDb, pConfig->zName
|
| 795 |
+
);
|
| 796 |
+
if( rc==SQLITE_OK && pConfig->bColumnsize ){
|
| 797 |
+
rc = fts5ExecPrintf(pConfig->db, 0,
|
| 798 |
+
"DELETE FROM %Q.'%q_docsize';", pConfig->zDb, pConfig->zName
|
| 799 |
+
);
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
if( rc==SQLITE_OK && pConfig->eContent==FTS5_CONTENT_UNINDEXED ){
|
| 803 |
+
rc = fts5ExecPrintf(pConfig->db, 0,
|
| 804 |
+
"DELETE FROM %Q.'%q_content';", pConfig->zDb, pConfig->zName
|
| 805 |
+
);
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
/* Reinitialize the %_data table. This call creates the initial structure
|
| 809 |
+
** and averages records. */
|
| 810 |
+
if( rc==SQLITE_OK ){
|
| 811 |
+
rc = sqlite3Fts5IndexReinit(p->pIndex);
|
| 812 |
+
}
|
| 813 |
+
if( rc==SQLITE_OK ){
|
| 814 |
+
rc = sqlite3Fts5StorageConfigValue(p, "version", 0, FTS5_CURRENT_VERSION);
|
| 815 |
+
}
|
| 816 |
+
return rc;
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
int sqlite3Fts5StorageRebuild(Fts5Storage *p){
|
| 820 |
+
Fts5Buffer buf = {0,0,0};
|
| 821 |
+
Fts5Config *pConfig = p->pConfig;
|
| 822 |
+
sqlite3_stmt *pScan = 0;
|
| 823 |
+
Fts5InsertCtx ctx;
|
| 824 |
+
int rc, rc2;
|
| 825 |
+
|
| 826 |
+
memset(&ctx, 0, sizeof(Fts5InsertCtx));
|
| 827 |
+
ctx.pStorage = p;
|
| 828 |
+
rc = sqlite3Fts5StorageDeleteAll(p);
|
| 829 |
+
if( rc==SQLITE_OK ){
|
| 830 |
+
rc = fts5StorageLoadTotals(p, 1);
|
| 831 |
+
}
|
| 832 |
+
|
| 833 |
+
if( rc==SQLITE_OK ){
|
| 834 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_SCAN, &pScan, pConfig->pzErrmsg);
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pScan) ){
|
| 838 |
+
i64 iRowid = sqlite3_column_int64(pScan, 0);
|
| 839 |
+
|
| 840 |
+
sqlite3Fts5BufferZero(&buf);
|
| 841 |
+
rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
|
| 842 |
+
for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
|
| 843 |
+
ctx.szCol = 0;
|
| 844 |
+
if( pConfig->abUnindexed[ctx.iCol]==0 ){
|
| 845 |
+
int nText = 0; /* Size of pText in bytes */
|
| 846 |
+
const char *pText = 0; /* Pointer to buffer containing text value */
|
| 847 |
+
int nLoc = 0; /* Size of pLoc in bytes */
|
| 848 |
+
const char *pLoc = 0; /* Pointer to buffer containing text value */
|
| 849 |
+
|
| 850 |
+
sqlite3_value *pVal = sqlite3_column_value(pScan, ctx.iCol+1);
|
| 851 |
+
if( pConfig->eContent==FTS5_CONTENT_EXTERNAL
|
| 852 |
+
&& sqlite3Fts5IsLocaleValue(pConfig, pVal)
|
| 853 |
+
){
|
| 854 |
+
rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
|
| 855 |
+
}else{
|
| 856 |
+
pText = (const char*)sqlite3_value_text(pVal);
|
| 857 |
+
nText = sqlite3_value_bytes(pVal);
|
| 858 |
+
if( pConfig->bLocale ){
|
| 859 |
+
int iCol = ctx.iCol + 1 + pConfig->nCol;
|
| 860 |
+
pLoc = (const char*)sqlite3_column_text(pScan, iCol);
|
| 861 |
+
nLoc = sqlite3_column_bytes(pScan, iCol);
|
| 862 |
+
}
|
| 863 |
+
}
|
| 864 |
+
|
| 865 |
+
if( rc==SQLITE_OK ){
|
| 866 |
+
sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
|
| 867 |
+
rc = sqlite3Fts5Tokenize(pConfig,
|
| 868 |
+
FTS5_TOKENIZE_DOCUMENT,
|
| 869 |
+
pText, nText,
|
| 870 |
+
(void*)&ctx,
|
| 871 |
+
fts5StorageInsertCallback
|
| 872 |
+
);
|
| 873 |
+
sqlite3Fts5ClearLocale(pConfig);
|
| 874 |
+
}
|
| 875 |
+
}
|
| 876 |
+
sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
|
| 877 |
+
p->aTotalSize[ctx.iCol] += (i64)ctx.szCol;
|
| 878 |
+
}
|
| 879 |
+
p->nTotalRow++;
|
| 880 |
+
|
| 881 |
+
if( rc==SQLITE_OK ){
|
| 882 |
+
rc = fts5StorageInsertDocsize(p, iRowid, &buf);
|
| 883 |
+
}
|
| 884 |
+
}
|
| 885 |
+
sqlite3_free(buf.p);
|
| 886 |
+
rc2 = sqlite3_reset(pScan);
|
| 887 |
+
if( rc==SQLITE_OK ) rc = rc2;
|
| 888 |
+
|
| 889 |
+
/* Write the averages record */
|
| 890 |
+
if( rc==SQLITE_OK ){
|
| 891 |
+
rc = fts5StorageSaveTotals(p);
|
| 892 |
+
}
|
| 893 |
+
return rc;
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
int sqlite3Fts5StorageOptimize(Fts5Storage *p){
|
| 897 |
+
return sqlite3Fts5IndexOptimize(p->pIndex);
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
int sqlite3Fts5StorageMerge(Fts5Storage *p, int nMerge){
|
| 901 |
+
return sqlite3Fts5IndexMerge(p->pIndex, nMerge);
|
| 902 |
+
}
|
| 903 |
+
|
| 904 |
+
int sqlite3Fts5StorageReset(Fts5Storage *p){
|
| 905 |
+
return sqlite3Fts5IndexReset(p->pIndex);
|
| 906 |
+
}
|
| 907 |
+
|
| 908 |
+
/*
|
| 909 |
+
** Allocate a new rowid. This is used for "external content" tables when
|
| 910 |
+
** a NULL value is inserted into the rowid column. The new rowid is allocated
|
| 911 |
+
** by inserting a dummy row into the %_docsize table. The dummy will be
|
| 912 |
+
** overwritten later.
|
| 913 |
+
**
|
| 914 |
+
** If the %_docsize table does not exist, SQLITE_MISMATCH is returned. In
|
| 915 |
+
** this case the user is required to provide a rowid explicitly.
|
| 916 |
+
*/
|
| 917 |
+
static int fts5StorageNewRowid(Fts5Storage *p, i64 *piRowid){
|
| 918 |
+
int rc = SQLITE_MISMATCH;
|
| 919 |
+
if( p->pConfig->bColumnsize ){
|
| 920 |
+
sqlite3_stmt *pReplace = 0;
|
| 921 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
|
| 922 |
+
if( rc==SQLITE_OK ){
|
| 923 |
+
sqlite3_bind_null(pReplace, 1);
|
| 924 |
+
sqlite3_bind_null(pReplace, 2);
|
| 925 |
+
sqlite3_step(pReplace);
|
| 926 |
+
rc = sqlite3_reset(pReplace);
|
| 927 |
+
}
|
| 928 |
+
if( rc==SQLITE_OK ){
|
| 929 |
+
*piRowid = sqlite3_last_insert_rowid(p->pConfig->db);
|
| 930 |
+
}
|
| 931 |
+
}
|
| 932 |
+
return rc;
|
| 933 |
+
}
|
| 934 |
+
|
| 935 |
+
/*
|
| 936 |
+
** Insert a new row into the FTS content table.
|
| 937 |
+
*/
|
| 938 |
+
int sqlite3Fts5StorageContentInsert(
|
| 939 |
+
Fts5Storage *p,
|
| 940 |
+
int bReplace, /* True to use REPLACE instead of INSERT */
|
| 941 |
+
sqlite3_value **apVal,
|
| 942 |
+
i64 *piRowid
|
| 943 |
+
){
|
| 944 |
+
Fts5Config *pConfig = p->pConfig;
|
| 945 |
+
int rc = SQLITE_OK;
|
| 946 |
+
|
| 947 |
+
/* Insert the new row into the %_content table. */
|
| 948 |
+
if( pConfig->eContent!=FTS5_CONTENT_NORMAL
|
| 949 |
+
&& pConfig->eContent!=FTS5_CONTENT_UNINDEXED
|
| 950 |
+
){
|
| 951 |
+
if( sqlite3_value_type(apVal[1])==SQLITE_INTEGER ){
|
| 952 |
+
*piRowid = sqlite3_value_int64(apVal[1]);
|
| 953 |
+
}else{
|
| 954 |
+
rc = fts5StorageNewRowid(p, piRowid);
|
| 955 |
+
}
|
| 956 |
+
}else{
|
| 957 |
+
sqlite3_stmt *pInsert = 0; /* Statement to write %_content table */
|
| 958 |
+
int i; /* Counter variable */
|
| 959 |
+
|
| 960 |
+
assert( FTS5_STMT_INSERT_CONTENT+1==FTS5_STMT_REPLACE_CONTENT );
|
| 961 |
+
assert( bReplace==0 || bReplace==1 );
|
| 962 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_INSERT_CONTENT+bReplace, &pInsert, 0);
|
| 963 |
+
if( pInsert ) sqlite3_clear_bindings(pInsert);
|
| 964 |
+
|
| 965 |
+
/* Bind the rowid value */
|
| 966 |
+
sqlite3_bind_value(pInsert, 1, apVal[1]);
|
| 967 |
+
|
| 968 |
+
/* Loop through values for user-defined columns. i=2 is the leftmost
|
| 969 |
+
** user-defined column. As is column 1 of pSavedRow. */
|
| 970 |
+
for(i=2; rc==SQLITE_OK && i<=pConfig->nCol+1; i++){
|
| 971 |
+
int bUnindexed = pConfig->abUnindexed[i-2];
|
| 972 |
+
if( pConfig->eContent==FTS5_CONTENT_NORMAL || bUnindexed ){
|
| 973 |
+
sqlite3_value *pVal = apVal[i];
|
| 974 |
+
|
| 975 |
+
if( sqlite3_value_nochange(pVal) && p->pSavedRow ){
|
| 976 |
+
/* This is an UPDATE statement, and user-defined column (i-2) was not
|
| 977 |
+
** modified. Retrieve the value from Fts5Storage.pSavedRow. */
|
| 978 |
+
pVal = sqlite3_column_value(p->pSavedRow, i-1);
|
| 979 |
+
if( pConfig->bLocale && bUnindexed==0 ){
|
| 980 |
+
sqlite3_bind_value(pInsert, pConfig->nCol + i,
|
| 981 |
+
sqlite3_column_value(p->pSavedRow, pConfig->nCol + i - 1)
|
| 982 |
+
);
|
| 983 |
+
}
|
| 984 |
+
}else if( sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
|
| 985 |
+
const char *pText = 0;
|
| 986 |
+
const char *pLoc = 0;
|
| 987 |
+
int nText = 0;
|
| 988 |
+
int nLoc = 0;
|
| 989 |
+
assert( pConfig->bLocale );
|
| 990 |
+
|
| 991 |
+
rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
|
| 992 |
+
if( rc==SQLITE_OK ){
|
| 993 |
+
sqlite3_bind_text(pInsert, i, pText, nText, SQLITE_TRANSIENT);
|
| 994 |
+
if( bUnindexed==0 ){
|
| 995 |
+
int iLoc = pConfig->nCol + i;
|
| 996 |
+
sqlite3_bind_text(pInsert, iLoc, pLoc, nLoc, SQLITE_TRANSIENT);
|
| 997 |
+
}
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
continue;
|
| 1001 |
+
}
|
| 1002 |
+
|
| 1003 |
+
rc = sqlite3_bind_value(pInsert, i, pVal);
|
| 1004 |
+
}
|
| 1005 |
+
}
|
| 1006 |
+
if( rc==SQLITE_OK ){
|
| 1007 |
+
sqlite3_step(pInsert);
|
| 1008 |
+
rc = sqlite3_reset(pInsert);
|
| 1009 |
+
}
|
| 1010 |
+
*piRowid = sqlite3_last_insert_rowid(pConfig->db);
|
| 1011 |
+
}
|
| 1012 |
+
|
| 1013 |
+
return rc;
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
/*
|
| 1017 |
+
** Insert new entries into the FTS index and %_docsize table.
|
| 1018 |
+
*/
|
| 1019 |
+
int sqlite3Fts5StorageIndexInsert(
|
| 1020 |
+
Fts5Storage *p,
|
| 1021 |
+
sqlite3_value **apVal,
|
| 1022 |
+
i64 iRowid
|
| 1023 |
+
){
|
| 1024 |
+
Fts5Config *pConfig = p->pConfig;
|
| 1025 |
+
int rc = SQLITE_OK; /* Return code */
|
| 1026 |
+
Fts5InsertCtx ctx; /* Tokenization callback context object */
|
| 1027 |
+
Fts5Buffer buf; /* Buffer used to build up %_docsize blob */
|
| 1028 |
+
|
| 1029 |
+
memset(&buf, 0, sizeof(Fts5Buffer));
|
| 1030 |
+
ctx.pStorage = p;
|
| 1031 |
+
rc = fts5StorageLoadTotals(p, 1);
|
| 1032 |
+
|
| 1033 |
+
if( rc==SQLITE_OK ){
|
| 1034 |
+
rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 0, iRowid);
|
| 1035 |
+
}
|
| 1036 |
+
for(ctx.iCol=0; rc==SQLITE_OK && ctx.iCol<pConfig->nCol; ctx.iCol++){
|
| 1037 |
+
ctx.szCol = 0;
|
| 1038 |
+
if( pConfig->abUnindexed[ctx.iCol]==0 ){
|
| 1039 |
+
int nText = 0; /* Size of pText in bytes */
|
| 1040 |
+
const char *pText = 0; /* Pointer to buffer containing text value */
|
| 1041 |
+
int nLoc = 0; /* Size of pText in bytes */
|
| 1042 |
+
const char *pLoc = 0; /* Pointer to buffer containing text value */
|
| 1043 |
+
|
| 1044 |
+
sqlite3_value *pVal = apVal[ctx.iCol+2];
|
| 1045 |
+
if( p->pSavedRow && sqlite3_value_nochange(pVal) ){
|
| 1046 |
+
pVal = sqlite3_column_value(p->pSavedRow, ctx.iCol+1);
|
| 1047 |
+
if( pConfig->eContent==FTS5_CONTENT_NORMAL && pConfig->bLocale ){
|
| 1048 |
+
int iCol = ctx.iCol + 1 + pConfig->nCol;
|
| 1049 |
+
pLoc = (const char*)sqlite3_column_text(p->pSavedRow, iCol);
|
| 1050 |
+
nLoc = sqlite3_column_bytes(p->pSavedRow, iCol);
|
| 1051 |
+
}
|
| 1052 |
+
}else{
|
| 1053 |
+
pVal = apVal[ctx.iCol+2];
|
| 1054 |
+
}
|
| 1055 |
+
|
| 1056 |
+
if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){
|
| 1057 |
+
rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc);
|
| 1058 |
+
}else{
|
| 1059 |
+
pText = (const char*)sqlite3_value_text(pVal);
|
| 1060 |
+
nText = sqlite3_value_bytes(pVal);
|
| 1061 |
+
}
|
| 1062 |
+
|
| 1063 |
+
if( rc==SQLITE_OK ){
|
| 1064 |
+
sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
|
| 1065 |
+
rc = sqlite3Fts5Tokenize(pConfig,
|
| 1066 |
+
FTS5_TOKENIZE_DOCUMENT, pText, nText, (void*)&ctx,
|
| 1067 |
+
fts5StorageInsertCallback
|
| 1068 |
+
);
|
| 1069 |
+
sqlite3Fts5ClearLocale(pConfig);
|
| 1070 |
+
}
|
| 1071 |
+
}
|
| 1072 |
+
sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol);
|
| 1073 |
+
p->aTotalSize[ctx.iCol] += (i64)ctx.szCol;
|
| 1074 |
+
}
|
| 1075 |
+
p->nTotalRow++;
|
| 1076 |
+
|
| 1077 |
+
/* Write the %_docsize record */
|
| 1078 |
+
if( rc==SQLITE_OK ){
|
| 1079 |
+
rc = fts5StorageInsertDocsize(p, iRowid, &buf);
|
| 1080 |
+
}
|
| 1081 |
+
sqlite3_free(buf.p);
|
| 1082 |
+
|
| 1083 |
+
return rc;
|
| 1084 |
+
}
|
| 1085 |
+
|
| 1086 |
+
static int fts5StorageCount(Fts5Storage *p, const char *zSuffix, i64 *pnRow){
|
| 1087 |
+
Fts5Config *pConfig = p->pConfig;
|
| 1088 |
+
char *zSql;
|
| 1089 |
+
int rc;
|
| 1090 |
+
|
| 1091 |
+
zSql = sqlite3_mprintf("SELECT count(*) FROM %Q.'%q_%s'",
|
| 1092 |
+
pConfig->zDb, pConfig->zName, zSuffix
|
| 1093 |
+
);
|
| 1094 |
+
if( zSql==0 ){
|
| 1095 |
+
rc = SQLITE_NOMEM;
|
| 1096 |
+
}else{
|
| 1097 |
+
sqlite3_stmt *pCnt = 0;
|
| 1098 |
+
rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pCnt, 0);
|
| 1099 |
+
if( rc==SQLITE_OK ){
|
| 1100 |
+
if( SQLITE_ROW==sqlite3_step(pCnt) ){
|
| 1101 |
+
*pnRow = sqlite3_column_int64(pCnt, 0);
|
| 1102 |
+
}
|
| 1103 |
+
rc = sqlite3_finalize(pCnt);
|
| 1104 |
+
}
|
| 1105 |
+
}
|
| 1106 |
+
|
| 1107 |
+
sqlite3_free(zSql);
|
| 1108 |
+
return rc;
|
| 1109 |
+
}
|
| 1110 |
+
|
| 1111 |
+
/*
|
| 1112 |
+
** Context object used by sqlite3Fts5StorageIntegrity().
|
| 1113 |
+
*/
|
| 1114 |
+
typedef struct Fts5IntegrityCtx Fts5IntegrityCtx;
|
| 1115 |
+
struct Fts5IntegrityCtx {
|
| 1116 |
+
i64 iRowid;
|
| 1117 |
+
int iCol;
|
| 1118 |
+
int szCol;
|
| 1119 |
+
u64 cksum;
|
| 1120 |
+
Fts5Termset *pTermset;
|
| 1121 |
+
Fts5Config *pConfig;
|
| 1122 |
+
};
|
| 1123 |
+
|
| 1124 |
+
|
| 1125 |
+
/*
|
| 1126 |
+
** Tokenization callback used by integrity check.
|
| 1127 |
+
*/
|
| 1128 |
+
static int fts5StorageIntegrityCallback(
|
| 1129 |
+
void *pContext, /* Pointer to Fts5IntegrityCtx object */
|
| 1130 |
+
int tflags,
|
| 1131 |
+
const char *pToken, /* Buffer containing token */
|
| 1132 |
+
int nToken, /* Size of token in bytes */
|
| 1133 |
+
int iUnused1, /* Start offset of token */
|
| 1134 |
+
int iUnused2 /* End offset of token */
|
| 1135 |
+
){
|
| 1136 |
+
Fts5IntegrityCtx *pCtx = (Fts5IntegrityCtx*)pContext;
|
| 1137 |
+
Fts5Termset *pTermset = pCtx->pTermset;
|
| 1138 |
+
int bPresent;
|
| 1139 |
+
int ii;
|
| 1140 |
+
int rc = SQLITE_OK;
|
| 1141 |
+
int iPos;
|
| 1142 |
+
int iCol;
|
| 1143 |
+
|
| 1144 |
+
UNUSED_PARAM2(iUnused1, iUnused2);
|
| 1145 |
+
if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
|
| 1146 |
+
|
| 1147 |
+
if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
|
| 1148 |
+
pCtx->szCol++;
|
| 1149 |
+
}
|
| 1150 |
+
|
| 1151 |
+
switch( pCtx->pConfig->eDetail ){
|
| 1152 |
+
case FTS5_DETAIL_FULL:
|
| 1153 |
+
iPos = pCtx->szCol-1;
|
| 1154 |
+
iCol = pCtx->iCol;
|
| 1155 |
+
break;
|
| 1156 |
+
|
| 1157 |
+
case FTS5_DETAIL_COLUMNS:
|
| 1158 |
+
iPos = pCtx->iCol;
|
| 1159 |
+
iCol = 0;
|
| 1160 |
+
break;
|
| 1161 |
+
|
| 1162 |
+
default:
|
| 1163 |
+
assert( pCtx->pConfig->eDetail==FTS5_DETAIL_NONE );
|
| 1164 |
+
iPos = 0;
|
| 1165 |
+
iCol = 0;
|
| 1166 |
+
break;
|
| 1167 |
+
}
|
| 1168 |
+
|
| 1169 |
+
rc = sqlite3Fts5TermsetAdd(pTermset, 0, pToken, nToken, &bPresent);
|
| 1170 |
+
if( rc==SQLITE_OK && bPresent==0 ){
|
| 1171 |
+
pCtx->cksum ^= sqlite3Fts5IndexEntryCksum(
|
| 1172 |
+
pCtx->iRowid, iCol, iPos, 0, pToken, nToken
|
| 1173 |
+
);
|
| 1174 |
+
}
|
| 1175 |
+
|
| 1176 |
+
for(ii=0; rc==SQLITE_OK && ii<pCtx->pConfig->nPrefix; ii++){
|
| 1177 |
+
const int nChar = pCtx->pConfig->aPrefix[ii];
|
| 1178 |
+
int nByte = sqlite3Fts5IndexCharlenToBytelen(pToken, nToken, nChar);
|
| 1179 |
+
if( nByte ){
|
| 1180 |
+
rc = sqlite3Fts5TermsetAdd(pTermset, ii+1, pToken, nByte, &bPresent);
|
| 1181 |
+
if( bPresent==0 ){
|
| 1182 |
+
pCtx->cksum ^= sqlite3Fts5IndexEntryCksum(
|
| 1183 |
+
pCtx->iRowid, iCol, iPos, ii+1, pToken, nByte
|
| 1184 |
+
);
|
| 1185 |
+
}
|
| 1186 |
+
}
|
| 1187 |
+
}
|
| 1188 |
+
|
| 1189 |
+
return rc;
|
| 1190 |
+
}
|
| 1191 |
+
|
| 1192 |
+
/*
|
| 1193 |
+
** Check that the contents of the FTS index match that of the %_content
|
| 1194 |
+
** table. Return SQLITE_OK if they do, or SQLITE_CORRUPT if not. Return
|
| 1195 |
+
** some other SQLite error code if an error occurs while attempting to
|
| 1196 |
+
** determine this.
|
| 1197 |
+
*/
|
| 1198 |
+
int sqlite3Fts5StorageIntegrity(Fts5Storage *p, int iArg){
|
| 1199 |
+
Fts5Config *pConfig = p->pConfig;
|
| 1200 |
+
int rc = SQLITE_OK; /* Return code */
|
| 1201 |
+
int *aColSize; /* Array of size pConfig->nCol */
|
| 1202 |
+
i64 *aTotalSize; /* Array of size pConfig->nCol */
|
| 1203 |
+
Fts5IntegrityCtx ctx;
|
| 1204 |
+
sqlite3_stmt *pScan;
|
| 1205 |
+
int bUseCksum;
|
| 1206 |
+
|
| 1207 |
+
memset(&ctx, 0, sizeof(Fts5IntegrityCtx));
|
| 1208 |
+
ctx.pConfig = p->pConfig;
|
| 1209 |
+
aTotalSize = (i64*)sqlite3_malloc64(pConfig->nCol*(sizeof(int)+sizeof(i64)));
|
| 1210 |
+
if( !aTotalSize ) return SQLITE_NOMEM;
|
| 1211 |
+
aColSize = (int*)&aTotalSize[pConfig->nCol];
|
| 1212 |
+
memset(aTotalSize, 0, sizeof(i64) * pConfig->nCol);
|
| 1213 |
+
|
| 1214 |
+
bUseCksum = (pConfig->eContent==FTS5_CONTENT_NORMAL
|
| 1215 |
+
|| (pConfig->eContent==FTS5_CONTENT_EXTERNAL && iArg)
|
| 1216 |
+
);
|
| 1217 |
+
if( bUseCksum ){
|
| 1218 |
+
/* Generate the expected index checksum based on the contents of the
|
| 1219 |
+
** %_content table. This block stores the checksum in ctx.cksum. */
|
| 1220 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_SCAN, &pScan, 0);
|
| 1221 |
+
if( rc==SQLITE_OK ){
|
| 1222 |
+
int rc2;
|
| 1223 |
+
while( SQLITE_ROW==sqlite3_step(pScan) ){
|
| 1224 |
+
int i;
|
| 1225 |
+
ctx.iRowid = sqlite3_column_int64(pScan, 0);
|
| 1226 |
+
ctx.szCol = 0;
|
| 1227 |
+
if( pConfig->bColumnsize ){
|
| 1228 |
+
rc = sqlite3Fts5StorageDocsize(p, ctx.iRowid, aColSize);
|
| 1229 |
+
}
|
| 1230 |
+
if( rc==SQLITE_OK && pConfig->eDetail==FTS5_DETAIL_NONE ){
|
| 1231 |
+
rc = sqlite3Fts5TermsetNew(&ctx.pTermset);
|
| 1232 |
+
}
|
| 1233 |
+
for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
|
| 1234 |
+
if( pConfig->abUnindexed[i]==0 ){
|
| 1235 |
+
const char *pText = 0;
|
| 1236 |
+
int nText = 0;
|
| 1237 |
+
const char *pLoc = 0;
|
| 1238 |
+
int nLoc = 0;
|
| 1239 |
+
sqlite3_value *pVal = sqlite3_column_value(pScan, i+1);
|
| 1240 |
+
|
| 1241 |
+
if( pConfig->eContent==FTS5_CONTENT_EXTERNAL
|
| 1242 |
+
&& sqlite3Fts5IsLocaleValue(pConfig, pVal)
|
| 1243 |
+
){
|
| 1244 |
+
rc = sqlite3Fts5DecodeLocaleValue(
|
| 1245 |
+
pVal, &pText, &nText, &pLoc, &nLoc
|
| 1246 |
+
);
|
| 1247 |
+
}else{
|
| 1248 |
+
if( pConfig->eContent==FTS5_CONTENT_NORMAL && pConfig->bLocale ){
|
| 1249 |
+
int iCol = i + 1 + pConfig->nCol;
|
| 1250 |
+
pLoc = (const char*)sqlite3_column_text(pScan, iCol);
|
| 1251 |
+
nLoc = sqlite3_column_bytes(pScan, iCol);
|
| 1252 |
+
}
|
| 1253 |
+
pText = (const char*)sqlite3_value_text(pVal);
|
| 1254 |
+
nText = sqlite3_value_bytes(pVal);
|
| 1255 |
+
}
|
| 1256 |
+
|
| 1257 |
+
ctx.iCol = i;
|
| 1258 |
+
ctx.szCol = 0;
|
| 1259 |
+
|
| 1260 |
+
if( rc==SQLITE_OK && pConfig->eDetail==FTS5_DETAIL_COLUMNS ){
|
| 1261 |
+
rc = sqlite3Fts5TermsetNew(&ctx.pTermset);
|
| 1262 |
+
}
|
| 1263 |
+
|
| 1264 |
+
if( rc==SQLITE_OK ){
|
| 1265 |
+
sqlite3Fts5SetLocale(pConfig, pLoc, nLoc);
|
| 1266 |
+
rc = sqlite3Fts5Tokenize(pConfig,
|
| 1267 |
+
FTS5_TOKENIZE_DOCUMENT,
|
| 1268 |
+
pText, nText,
|
| 1269 |
+
(void*)&ctx,
|
| 1270 |
+
fts5StorageIntegrityCallback
|
| 1271 |
+
);
|
| 1272 |
+
sqlite3Fts5ClearLocale(pConfig);
|
| 1273 |
+
}
|
| 1274 |
+
|
| 1275 |
+
/* If this is not a columnsize=0 database, check that the number
|
| 1276 |
+
** of tokens in the value matches the aColSize[] value read from
|
| 1277 |
+
** the %_docsize table. */
|
| 1278 |
+
if( rc==SQLITE_OK
|
| 1279 |
+
&& pConfig->bColumnsize
|
| 1280 |
+
&& ctx.szCol!=aColSize[i]
|
| 1281 |
+
){
|
| 1282 |
+
rc = FTS5_CORRUPT;
|
| 1283 |
+
}
|
| 1284 |
+
aTotalSize[i] += ctx.szCol;
|
| 1285 |
+
if( pConfig->eDetail==FTS5_DETAIL_COLUMNS ){
|
| 1286 |
+
sqlite3Fts5TermsetFree(ctx.pTermset);
|
| 1287 |
+
ctx.pTermset = 0;
|
| 1288 |
+
}
|
| 1289 |
+
}
|
| 1290 |
+
}
|
| 1291 |
+
sqlite3Fts5TermsetFree(ctx.pTermset);
|
| 1292 |
+
ctx.pTermset = 0;
|
| 1293 |
+
|
| 1294 |
+
if( rc!=SQLITE_OK ) break;
|
| 1295 |
+
}
|
| 1296 |
+
rc2 = sqlite3_reset(pScan);
|
| 1297 |
+
if( rc==SQLITE_OK ) rc = rc2;
|
| 1298 |
+
}
|
| 1299 |
+
|
| 1300 |
+
/* Test that the "totals" (sometimes called "averages") record looks Ok */
|
| 1301 |
+
if( rc==SQLITE_OK ){
|
| 1302 |
+
int i;
|
| 1303 |
+
rc = fts5StorageLoadTotals(p, 0);
|
| 1304 |
+
for(i=0; rc==SQLITE_OK && i<pConfig->nCol; i++){
|
| 1305 |
+
if( p->aTotalSize[i]!=aTotalSize[i] ) rc = FTS5_CORRUPT;
|
| 1306 |
+
}
|
| 1307 |
+
}
|
| 1308 |
+
|
| 1309 |
+
/* Check that the %_docsize and %_content tables contain the expected
|
| 1310 |
+
** number of rows. */
|
| 1311 |
+
if( rc==SQLITE_OK && pConfig->eContent==FTS5_CONTENT_NORMAL ){
|
| 1312 |
+
i64 nRow = 0;
|
| 1313 |
+
rc = fts5StorageCount(p, "content", &nRow);
|
| 1314 |
+
if( rc==SQLITE_OK && nRow!=p->nTotalRow ) rc = FTS5_CORRUPT;
|
| 1315 |
+
}
|
| 1316 |
+
if( rc==SQLITE_OK && pConfig->bColumnsize ){
|
| 1317 |
+
i64 nRow = 0;
|
| 1318 |
+
rc = fts5StorageCount(p, "docsize", &nRow);
|
| 1319 |
+
if( rc==SQLITE_OK && nRow!=p->nTotalRow ) rc = FTS5_CORRUPT;
|
| 1320 |
+
}
|
| 1321 |
+
}
|
| 1322 |
+
|
| 1323 |
+
/* Pass the expected checksum down to the FTS index module. It will
|
| 1324 |
+
** verify, amongst other things, that it matches the checksum generated by
|
| 1325 |
+
** inspecting the index itself. */
|
| 1326 |
+
if( rc==SQLITE_OK ){
|
| 1327 |
+
rc = sqlite3Fts5IndexIntegrityCheck(p->pIndex, ctx.cksum, bUseCksum);
|
| 1328 |
+
}
|
| 1329 |
+
|
| 1330 |
+
sqlite3_free(aTotalSize);
|
| 1331 |
+
return rc;
|
| 1332 |
+
}
|
| 1333 |
+
|
| 1334 |
+
/*
|
| 1335 |
+
** Obtain an SQLite statement handle that may be used to read data from the
|
| 1336 |
+
** %_content table.
|
| 1337 |
+
*/
|
| 1338 |
+
int sqlite3Fts5StorageStmt(
|
| 1339 |
+
Fts5Storage *p,
|
| 1340 |
+
int eStmt,
|
| 1341 |
+
sqlite3_stmt **pp,
|
| 1342 |
+
char **pzErrMsg
|
| 1343 |
+
){
|
| 1344 |
+
int rc;
|
| 1345 |
+
assert( eStmt==FTS5_STMT_SCAN_ASC
|
| 1346 |
+
|| eStmt==FTS5_STMT_SCAN_DESC
|
| 1347 |
+
|| eStmt==FTS5_STMT_LOOKUP
|
| 1348 |
+
);
|
| 1349 |
+
rc = fts5StorageGetStmt(p, eStmt, pp, pzErrMsg);
|
| 1350 |
+
if( rc==SQLITE_OK ){
|
| 1351 |
+
assert( p->aStmt[eStmt]==*pp );
|
| 1352 |
+
p->aStmt[eStmt] = 0;
|
| 1353 |
+
}
|
| 1354 |
+
return rc;
|
| 1355 |
+
}
|
| 1356 |
+
|
| 1357 |
+
/*
|
| 1358 |
+
** Release an SQLite statement handle obtained via an earlier call to
|
| 1359 |
+
** sqlite3Fts5StorageStmt(). The eStmt parameter passed to this function
|
| 1360 |
+
** must match that passed to the sqlite3Fts5StorageStmt() call.
|
| 1361 |
+
*/
|
| 1362 |
+
void sqlite3Fts5StorageStmtRelease(
|
| 1363 |
+
Fts5Storage *p,
|
| 1364 |
+
int eStmt,
|
| 1365 |
+
sqlite3_stmt *pStmt
|
| 1366 |
+
){
|
| 1367 |
+
assert( eStmt==FTS5_STMT_SCAN_ASC
|
| 1368 |
+
|| eStmt==FTS5_STMT_SCAN_DESC
|
| 1369 |
+
|| eStmt==FTS5_STMT_LOOKUP
|
| 1370 |
+
);
|
| 1371 |
+
if( p->aStmt[eStmt]==0 ){
|
| 1372 |
+
sqlite3_reset(pStmt);
|
| 1373 |
+
p->aStmt[eStmt] = pStmt;
|
| 1374 |
+
}else{
|
| 1375 |
+
sqlite3_finalize(pStmt);
|
| 1376 |
+
}
|
| 1377 |
+
}
|
| 1378 |
+
|
| 1379 |
+
static int fts5StorageDecodeSizeArray(
|
| 1380 |
+
int *aCol, int nCol, /* Array to populate */
|
| 1381 |
+
const u8 *aBlob, int nBlob /* Record to read varints from */
|
| 1382 |
+
){
|
| 1383 |
+
int i;
|
| 1384 |
+
int iOff = 0;
|
| 1385 |
+
for(i=0; i<nCol; i++){
|
| 1386 |
+
if( iOff>=nBlob ) return 1;
|
| 1387 |
+
iOff += fts5GetVarint32(&aBlob[iOff], aCol[i]);
|
| 1388 |
+
}
|
| 1389 |
+
return (iOff!=nBlob);
|
| 1390 |
+
}
|
| 1391 |
+
|
| 1392 |
+
/*
|
| 1393 |
+
** Argument aCol points to an array of integers containing one entry for
|
| 1394 |
+
** each table column. This function reads the %_docsize record for the
|
| 1395 |
+
** specified rowid and populates aCol[] with the results.
|
| 1396 |
+
**
|
| 1397 |
+
** An SQLite error code is returned if an error occurs, or SQLITE_OK
|
| 1398 |
+
** otherwise.
|
| 1399 |
+
*/
|
| 1400 |
+
int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol){
|
| 1401 |
+
int nCol = p->pConfig->nCol; /* Number of user columns in table */
|
| 1402 |
+
sqlite3_stmt *pLookup = 0; /* Statement to query %_docsize */
|
| 1403 |
+
int rc; /* Return Code */
|
| 1404 |
+
|
| 1405 |
+
assert( p->pConfig->bColumnsize );
|
| 1406 |
+
rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
|
| 1407 |
+
if( pLookup ){
|
| 1408 |
+
int bCorrupt = 1;
|
| 1409 |
+
assert( rc==SQLITE_OK );
|
| 1410 |
+
sqlite3_bind_int64(pLookup, 1, iRowid);
|
| 1411 |
+
if( SQLITE_ROW==sqlite3_step(pLookup) ){
|
| 1412 |
+
const u8 *aBlob = sqlite3_column_blob(pLookup, 0);
|
| 1413 |
+
int nBlob = sqlite3_column_bytes(pLookup, 0);
|
| 1414 |
+
if( 0==fts5StorageDecodeSizeArray(aCol, nCol, aBlob, nBlob) ){
|
| 1415 |
+
bCorrupt = 0;
|
| 1416 |
+
}
|
| 1417 |
+
}
|
| 1418 |
+
rc = sqlite3_reset(pLookup);
|
| 1419 |
+
if( bCorrupt && rc==SQLITE_OK ){
|
| 1420 |
+
rc = FTS5_CORRUPT;
|
| 1421 |
+
}
|
| 1422 |
+
}else{
|
| 1423 |
+
assert( rc!=SQLITE_OK );
|
| 1424 |
+
}
|
| 1425 |
+
|
| 1426 |
+
return rc;
|
| 1427 |
+
}
|
| 1428 |
+
|
| 1429 |
+
int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnToken){
|
| 1430 |
+
int rc = fts5StorageLoadTotals(p, 0);
|
| 1431 |
+
if( rc==SQLITE_OK ){
|
| 1432 |
+
*pnToken = 0;
|
| 1433 |
+
if( iCol<0 ){
|
| 1434 |
+
int i;
|
| 1435 |
+
for(i=0; i<p->pConfig->nCol; i++){
|
| 1436 |
+
*pnToken += p->aTotalSize[i];
|
| 1437 |
+
}
|
| 1438 |
+
}else if( iCol<p->pConfig->nCol ){
|
| 1439 |
+
*pnToken = p->aTotalSize[iCol];
|
| 1440 |
+
}else{
|
| 1441 |
+
rc = SQLITE_RANGE;
|
| 1442 |
+
}
|
| 1443 |
+
}
|
| 1444 |
+
return rc;
|
| 1445 |
+
}
|
| 1446 |
+
|
| 1447 |
+
int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow){
|
| 1448 |
+
int rc = fts5StorageLoadTotals(p, 0);
|
| 1449 |
+
if( rc==SQLITE_OK ){
|
| 1450 |
+
/* nTotalRow being zero does not necessarily indicate a corrupt
|
| 1451 |
+
** database - it might be that the FTS5 table really does contain zero
|
| 1452 |
+
** rows. However this function is only called from the xRowCount() API,
|
| 1453 |
+
** and there is no way for that API to be invoked if the table contains
|
| 1454 |
+
** no rows. Hence the FTS5_CORRUPT return. */
|
| 1455 |
+
*pnRow = p->nTotalRow;
|
| 1456 |
+
if( p->nTotalRow<=0 ) rc = FTS5_CORRUPT;
|
| 1457 |
+
}
|
| 1458 |
+
return rc;
|
| 1459 |
+
}
|
| 1460 |
+
|
| 1461 |
+
/*
|
| 1462 |
+
** Flush any data currently held in-memory to disk.
|
| 1463 |
+
*/
|
| 1464 |
+
int sqlite3Fts5StorageSync(Fts5Storage *p){
|
| 1465 |
+
int rc = SQLITE_OK;
|
| 1466 |
+
i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
|
| 1467 |
+
if( p->bTotalsValid ){
|
| 1468 |
+
rc = fts5StorageSaveTotals(p);
|
| 1469 |
+
if( rc==SQLITE_OK ){
|
| 1470 |
+
p->bTotalsValid = 0;
|
| 1471 |
+
}
|
| 1472 |
+
}
|
| 1473 |
+
if( rc==SQLITE_OK ){
|
| 1474 |
+
rc = sqlite3Fts5IndexSync(p->pIndex);
|
| 1475 |
+
}
|
| 1476 |
+
sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
|
| 1477 |
+
return rc;
|
| 1478 |
+
}
|
| 1479 |
+
|
| 1480 |
+
int sqlite3Fts5StorageRollback(Fts5Storage *p){
|
| 1481 |
+
p->bTotalsValid = 0;
|
| 1482 |
+
return sqlite3Fts5IndexRollback(p->pIndex);
|
| 1483 |
+
}
|
| 1484 |
+
|
| 1485 |
+
int sqlite3Fts5StorageConfigValue(
|
| 1486 |
+
Fts5Storage *p,
|
| 1487 |
+
const char *z,
|
| 1488 |
+
sqlite3_value *pVal,
|
| 1489 |
+
int iVal
|
| 1490 |
+
){
|
| 1491 |
+
sqlite3_stmt *pReplace = 0;
|
| 1492 |
+
int rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_CONFIG, &pReplace, 0);
|
| 1493 |
+
if( rc==SQLITE_OK ){
|
| 1494 |
+
sqlite3_bind_text(pReplace, 1, z, -1, SQLITE_STATIC);
|
| 1495 |
+
if( pVal ){
|
| 1496 |
+
sqlite3_bind_value(pReplace, 2, pVal);
|
| 1497 |
+
}else{
|
| 1498 |
+
sqlite3_bind_int(pReplace, 2, iVal);
|
| 1499 |
+
}
|
| 1500 |
+
sqlite3_step(pReplace);
|
| 1501 |
+
rc = sqlite3_reset(pReplace);
|
| 1502 |
+
sqlite3_bind_null(pReplace, 1);
|
| 1503 |
+
}
|
| 1504 |
+
if( rc==SQLITE_OK && pVal ){
|
| 1505 |
+
int iNew = p->pConfig->iCookie + 1;
|
| 1506 |
+
rc = sqlite3Fts5IndexSetCookie(p->pIndex, iNew);
|
| 1507 |
+
if( rc==SQLITE_OK ){
|
| 1508 |
+
p->pConfig->iCookie = iNew;
|
| 1509 |
+
}
|
| 1510 |
+
}
|
| 1511 |
+
return rc;
|
| 1512 |
+
}
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/fts5/fts5_test_tok.c
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** 2013 Apr 22
|
| 3 |
+
**
|
| 4 |
+
** The author disclaims copyright to this source code. In place of
|
| 5 |
+
** a legal notice, here is a blessing:
|
| 6 |
+
**
|
| 7 |
+
** May you do good and not evil.
|
| 8 |
+
** May you find forgiveness for yourself and forgive others.
|
| 9 |
+
** May you share freely, never taking more than you give.
|
| 10 |
+
**
|
| 11 |
+
******************************************************************************
|
| 12 |
+
**
|
| 13 |
+
** This file contains code for the "fts5tokenize" virtual table module.
|
| 14 |
+
** An fts5tokenize virtual table is created as follows:
|
| 15 |
+
**
|
| 16 |
+
** CREATE VIRTUAL TABLE <tbl> USING fts5tokenize(
|
| 17 |
+
** <tokenizer-name>, <arg-1>, ...
|
| 18 |
+
** );
|
| 19 |
+
**
|
| 20 |
+
** The table created has the following schema:
|
| 21 |
+
**
|
| 22 |
+
** CREATE TABLE <tbl>(input HIDDEN, token, start, end, position)
|
| 23 |
+
**
|
| 24 |
+
** When queried, the query must include a WHERE clause of type:
|
| 25 |
+
**
|
| 26 |
+
** input = <string>
|
| 27 |
+
**
|
| 28 |
+
** The virtual table module tokenizes this <string>, using the FTS3
|
| 29 |
+
** tokenizer specified by the arguments to the CREATE VIRTUAL TABLE
|
| 30 |
+
** statement and returns one row for each token in the result. With
|
| 31 |
+
** fields set as follows:
|
| 32 |
+
**
|
| 33 |
+
** input: Always set to a copy of <string>
|
| 34 |
+
** token: A token from the input.
|
| 35 |
+
** start: Byte offset of the token within the input <string>.
|
| 36 |
+
** end: Byte offset of the byte immediately following the end of the
|
| 37 |
+
** token within the input string.
|
| 38 |
+
** pos: Token offset of token within input.
|
| 39 |
+
**
|
| 40 |
+
*/
|
| 41 |
+
#if defined(SQLITE_TEST) && defined(SQLITE_ENABLE_FTS5)
|
| 42 |
+
|
| 43 |
+
#include "fts5.h"
|
| 44 |
+
#include <string.h>
|
| 45 |
+
#include <assert.h>
|
| 46 |
+
|
| 47 |
+
typedef struct Fts5tokTable Fts5tokTable;
|
| 48 |
+
typedef struct Fts5tokCursor Fts5tokCursor;
|
| 49 |
+
typedef struct Fts5tokRow Fts5tokRow;
|
| 50 |
+
|
| 51 |
+
/*
|
| 52 |
+
** Virtual table structure.
|
| 53 |
+
*/
|
| 54 |
+
struct Fts5tokTable {
|
| 55 |
+
sqlite3_vtab base; /* Base class used by SQLite core */
|
| 56 |
+
fts5_tokenizer tok; /* Tokenizer functions */
|
| 57 |
+
Fts5Tokenizer *pTok; /* Tokenizer instance */
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
/*
|
| 61 |
+
** A container for a rows values.
|
| 62 |
+
*/
|
| 63 |
+
struct Fts5tokRow {
|
| 64 |
+
char *zToken;
|
| 65 |
+
int iStart;
|
| 66 |
+
int iEnd;
|
| 67 |
+
int iPos;
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
/*
|
| 71 |
+
** Virtual table cursor structure.
|
| 72 |
+
*/
|
| 73 |
+
struct Fts5tokCursor {
|
| 74 |
+
sqlite3_vtab_cursor base; /* Base class used by SQLite core */
|
| 75 |
+
int iRowid; /* Current 'rowid' value */
|
| 76 |
+
char *zInput; /* Input string */
|
| 77 |
+
int nRow; /* Number of entries in aRow[] */
|
| 78 |
+
Fts5tokRow *aRow; /* Array of rows to return */
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
static void fts5tokDequote(char *z){
|
| 82 |
+
char q = z[0];
|
| 83 |
+
|
| 84 |
+
if( q=='[' || q=='\'' || q=='"' || q=='`' ){
|
| 85 |
+
int iIn = 1;
|
| 86 |
+
int iOut = 0;
|
| 87 |
+
if( q=='[' ) q = ']';
|
| 88 |
+
|
| 89 |
+
while( z[iIn] ){
|
| 90 |
+
if( z[iIn]==q ){
|
| 91 |
+
if( z[iIn+1]!=q ){
|
| 92 |
+
/* Character iIn was the close quote. */
|
| 93 |
+
iIn++;
|
| 94 |
+
break;
|
| 95 |
+
}else{
|
| 96 |
+
/* Character iIn and iIn+1 form an escaped quote character. Skip
|
| 97 |
+
** the input cursor past both and copy a single quote character
|
| 98 |
+
** to the output buffer. */
|
| 99 |
+
iIn += 2;
|
| 100 |
+
z[iOut++] = q;
|
| 101 |
+
}
|
| 102 |
+
}else{
|
| 103 |
+
z[iOut++] = z[iIn++];
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
z[iOut] = '\0';
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
/*
|
| 112 |
+
** The second argument, argv[], is an array of pointers to nul-terminated
|
| 113 |
+
** strings. This function makes a copy of the array and strings into a
|
| 114 |
+
** single block of memory. It then dequotes any of the strings that appear
|
| 115 |
+
** to be quoted.
|
| 116 |
+
**
|
| 117 |
+
** If successful, output parameter *pazDequote is set to point at the
|
| 118 |
+
** array of dequoted strings and SQLITE_OK is returned. The caller is
|
| 119 |
+
** responsible for eventually calling sqlite3_free() to free the array
|
| 120 |
+
** in this case. Or, if an error occurs, an SQLite error code is returned.
|
| 121 |
+
** The final value of *pazDequote is undefined in this case.
|
| 122 |
+
*/
|
| 123 |
+
static int fts5tokDequoteArray(
|
| 124 |
+
int argc, /* Number of elements in argv[] */
|
| 125 |
+
const char * const *argv, /* Input array */
|
| 126 |
+
char ***pazDequote /* Output array */
|
| 127 |
+
){
|
| 128 |
+
int rc = SQLITE_OK; /* Return code */
|
| 129 |
+
if( argc==0 ){
|
| 130 |
+
*pazDequote = 0;
|
| 131 |
+
}else{
|
| 132 |
+
int i;
|
| 133 |
+
int nByte = 0;
|
| 134 |
+
char **azDequote;
|
| 135 |
+
|
| 136 |
+
for(i=0; i<argc; i++){
|
| 137 |
+
nByte += (int)(strlen(argv[i]) + 1);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
*pazDequote = azDequote = sqlite3_malloc64(sizeof(char *)*argc + nByte);
|
| 141 |
+
if( azDequote==0 ){
|
| 142 |
+
rc = SQLITE_NOMEM;
|
| 143 |
+
}else{
|
| 144 |
+
char *pSpace = (char *)&azDequote[argc];
|
| 145 |
+
for(i=0; i<argc; i++){
|
| 146 |
+
int n = (int)strlen(argv[i]);
|
| 147 |
+
azDequote[i] = pSpace;
|
| 148 |
+
memcpy(pSpace, argv[i], n+1);
|
| 149 |
+
fts5tokDequote(pSpace);
|
| 150 |
+
pSpace += (n+1);
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
return rc;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/*
|
| 159 |
+
** Schema of the tokenizer table.
|
| 160 |
+
*/
|
| 161 |
+
#define FTS3_TOK_SCHEMA "CREATE TABLE x(input HIDDEN, token, start, end, position)"
|
| 162 |
+
|
| 163 |
+
/*
|
| 164 |
+
** This function does all the work for both the xConnect and xCreate methods.
|
| 165 |
+
** These tables have no persistent representation of their own, so xConnect
|
| 166 |
+
** and xCreate are identical operations.
|
| 167 |
+
**
|
| 168 |
+
** argv[0]: module name
|
| 169 |
+
** argv[1]: database name
|
| 170 |
+
** argv[2]: table name
|
| 171 |
+
** argv[3]: first argument (tokenizer name)
|
| 172 |
+
*/
|
| 173 |
+
static int fts5tokConnectMethod(
|
| 174 |
+
sqlite3 *db, /* Database connection */
|
| 175 |
+
void *pCtx, /* Pointer to fts5_api object */
|
| 176 |
+
int argc, /* Number of elements in argv array */
|
| 177 |
+
const char * const *argv, /* xCreate/xConnect argument array */
|
| 178 |
+
sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
|
| 179 |
+
char **pzErr /* OUT: sqlite3_malloc'd error message */
|
| 180 |
+
){
|
| 181 |
+
fts5_api *pApi = (fts5_api*)pCtx;
|
| 182 |
+
Fts5tokTable *pTab = 0;
|
| 183 |
+
int rc;
|
| 184 |
+
char **azDequote = 0;
|
| 185 |
+
int nDequote = 0;
|
| 186 |
+
|
| 187 |
+
rc = sqlite3_declare_vtab(db,
|
| 188 |
+
"CREATE TABLE x(input HIDDEN, token, start, end, position)"
|
| 189 |
+
);
|
| 190 |
+
|
| 191 |
+
if( rc==SQLITE_OK ){
|
| 192 |
+
nDequote = argc-3;
|
| 193 |
+
rc = fts5tokDequoteArray(nDequote, &argv[3], &azDequote);
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
if( rc==SQLITE_OK ){
|
| 197 |
+
pTab = (Fts5tokTable*)sqlite3_malloc(sizeof(Fts5tokTable));
|
| 198 |
+
if( pTab==0 ){
|
| 199 |
+
rc = SQLITE_NOMEM;
|
| 200 |
+
}else{
|
| 201 |
+
memset(pTab, 0, sizeof(Fts5tokTable));
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
if( rc==SQLITE_OK ){
|
| 206 |
+
void *pTokCtx = 0;
|
| 207 |
+
const char *zModule = 0;
|
| 208 |
+
if( nDequote>0 ){
|
| 209 |
+
zModule = azDequote[0];
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
rc = pApi->xFindTokenizer(pApi, zModule, &pTokCtx, &pTab->tok);
|
| 213 |
+
if( rc==SQLITE_OK ){
|
| 214 |
+
const char **azArg = (nDequote>1 ? (const char **)&azDequote[1] : 0);
|
| 215 |
+
int nArg = nDequote>0 ? nDequote-1 : 0;
|
| 216 |
+
rc = pTab->tok.xCreate(pTokCtx, azArg, nArg, &pTab->pTok);
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
if( rc!=SQLITE_OK ){
|
| 221 |
+
sqlite3_free(pTab);
|
| 222 |
+
pTab = 0;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
*ppVtab = (sqlite3_vtab*)pTab;
|
| 226 |
+
sqlite3_free(azDequote);
|
| 227 |
+
return rc;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/*
|
| 231 |
+
** This function does the work for both the xDisconnect and xDestroy methods.
|
| 232 |
+
** These tables have no persistent representation of their own, so xDisconnect
|
| 233 |
+
** and xDestroy are identical operations.
|
| 234 |
+
*/
|
| 235 |
+
static int fts5tokDisconnectMethod(sqlite3_vtab *pVtab){
|
| 236 |
+
Fts5tokTable *pTab = (Fts5tokTable *)pVtab;
|
| 237 |
+
if( pTab->pTok ){
|
| 238 |
+
pTab->tok.xDelete(pTab->pTok);
|
| 239 |
+
}
|
| 240 |
+
sqlite3_free(pTab);
|
| 241 |
+
return SQLITE_OK;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/*
|
| 245 |
+
** xBestIndex - Analyze a WHERE and ORDER BY clause.
|
| 246 |
+
*/
|
| 247 |
+
static int fts5tokBestIndexMethod(
|
| 248 |
+
sqlite3_vtab *pVTab,
|
| 249 |
+
sqlite3_index_info *pInfo
|
| 250 |
+
){
|
| 251 |
+
int i;
|
| 252 |
+
|
| 253 |
+
for(i=0; i<pInfo->nConstraint; i++){
|
| 254 |
+
if( pInfo->aConstraint[i].usable
|
| 255 |
+
&& pInfo->aConstraint[i].iColumn==0
|
| 256 |
+
&& pInfo->aConstraint[i].op==SQLITE_INDEX_CONSTRAINT_EQ
|
| 257 |
+
){
|
| 258 |
+
pInfo->idxNum = 1;
|
| 259 |
+
pInfo->aConstraintUsage[i].argvIndex = 1;
|
| 260 |
+
pInfo->aConstraintUsage[i].omit = 1;
|
| 261 |
+
pInfo->estimatedCost = 1;
|
| 262 |
+
return SQLITE_OK;
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
pInfo->idxNum = 0;
|
| 267 |
+
assert( pInfo->estimatedCost>1000000.0 );
|
| 268 |
+
|
| 269 |
+
return SQLITE_OK;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
/*
|
| 273 |
+
** xOpen - Open a cursor.
|
| 274 |
+
*/
|
| 275 |
+
static int fts5tokOpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){
|
| 276 |
+
Fts5tokCursor *pCsr;
|
| 277 |
+
|
| 278 |
+
pCsr = (Fts5tokCursor *)sqlite3_malloc(sizeof(Fts5tokCursor));
|
| 279 |
+
if( pCsr==0 ){
|
| 280 |
+
return SQLITE_NOMEM;
|
| 281 |
+
}
|
| 282 |
+
memset(pCsr, 0, sizeof(Fts5tokCursor));
|
| 283 |
+
|
| 284 |
+
*ppCsr = (sqlite3_vtab_cursor *)pCsr;
|
| 285 |
+
return SQLITE_OK;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/*
|
| 289 |
+
** Reset the tokenizer cursor passed as the only argument. As if it had
|
| 290 |
+
** just been returned by fts5tokOpenMethod().
|
| 291 |
+
*/
|
| 292 |
+
static void fts5tokResetCursor(Fts5tokCursor *pCsr){
|
| 293 |
+
int i;
|
| 294 |
+
for(i=0; i<pCsr->nRow; i++){
|
| 295 |
+
sqlite3_free(pCsr->aRow[i].zToken);
|
| 296 |
+
}
|
| 297 |
+
sqlite3_free(pCsr->zInput);
|
| 298 |
+
sqlite3_free(pCsr->aRow);
|
| 299 |
+
pCsr->zInput = 0;
|
| 300 |
+
pCsr->aRow = 0;
|
| 301 |
+
pCsr->nRow = 0;
|
| 302 |
+
pCsr->iRowid = 0;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
/*
|
| 306 |
+
** xClose - Close a cursor.
|
| 307 |
+
*/
|
| 308 |
+
static int fts5tokCloseMethod(sqlite3_vtab_cursor *pCursor){
|
| 309 |
+
Fts5tokCursor *pCsr = (Fts5tokCursor *)pCursor;
|
| 310 |
+
fts5tokResetCursor(pCsr);
|
| 311 |
+
sqlite3_free(pCsr);
|
| 312 |
+
return SQLITE_OK;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
/*
|
| 316 |
+
** xNext - Advance the cursor to the next row, if any.
|
| 317 |
+
*/
|
| 318 |
+
static int fts5tokNextMethod(sqlite3_vtab_cursor *pCursor){
|
| 319 |
+
Fts5tokCursor *pCsr = (Fts5tokCursor *)pCursor;
|
| 320 |
+
pCsr->iRowid++;
|
| 321 |
+
return SQLITE_OK;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
static int fts5tokCb(
|
| 325 |
+
void *pCtx, /* Pointer to Fts5tokCursor */
|
| 326 |
+
int tflags, /* Mask of FTS5_TOKEN_* flags */
|
| 327 |
+
const char *pToken, /* Pointer to buffer containing token */
|
| 328 |
+
int nToken, /* Size of token in bytes */
|
| 329 |
+
int iStart, /* Byte offset of token within input text */
|
| 330 |
+
int iEnd /* Byte offset of end of token within input text */
|
| 331 |
+
){
|
| 332 |
+
Fts5tokCursor *pCsr = (Fts5tokCursor*)pCtx;
|
| 333 |
+
Fts5tokRow *pRow;
|
| 334 |
+
|
| 335 |
+
if( (pCsr->nRow & (pCsr->nRow-1))==0 ){
|
| 336 |
+
int nNew = pCsr->nRow ? pCsr->nRow*2 : 32;
|
| 337 |
+
Fts5tokRow *aNew;
|
| 338 |
+
aNew = (Fts5tokRow*)sqlite3_realloc64(pCsr->aRow, nNew*sizeof(Fts5tokRow));
|
| 339 |
+
if( aNew==0 ) return SQLITE_NOMEM;
|
| 340 |
+
memset(&aNew[pCsr->nRow], 0, sizeof(Fts5tokRow)*(nNew-pCsr->nRow));
|
| 341 |
+
pCsr->aRow = aNew;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
pRow = &pCsr->aRow[pCsr->nRow];
|
| 345 |
+
pRow->iStart = iStart;
|
| 346 |
+
pRow->iEnd = iEnd;
|
| 347 |
+
if( pCsr->nRow ){
|
| 348 |
+
pRow->iPos = pRow[-1].iPos + ((tflags & FTS5_TOKEN_COLOCATED) ? 0 : 1);
|
| 349 |
+
}
|
| 350 |
+
pRow->zToken = sqlite3_malloc(nToken+1);
|
| 351 |
+
if( pRow->zToken==0 ) return SQLITE_NOMEM;
|
| 352 |
+
memcpy(pRow->zToken, pToken, nToken);
|
| 353 |
+
pRow->zToken[nToken] = 0;
|
| 354 |
+
pCsr->nRow++;
|
| 355 |
+
|
| 356 |
+
return SQLITE_OK;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
/*
|
| 360 |
+
** xFilter - Initialize a cursor to point at the start of its data.
|
| 361 |
+
*/
|
| 362 |
+
static int fts5tokFilterMethod(
|
| 363 |
+
sqlite3_vtab_cursor *pCursor, /* The cursor used for this query */
|
| 364 |
+
int idxNum, /* Strategy index */
|
| 365 |
+
const char *idxStr, /* Unused */
|
| 366 |
+
int nVal, /* Number of elements in apVal */
|
| 367 |
+
sqlite3_value **apVal /* Arguments for the indexing scheme */
|
| 368 |
+
){
|
| 369 |
+
int rc = SQLITE_ERROR;
|
| 370 |
+
Fts5tokCursor *pCsr = (Fts5tokCursor *)pCursor;
|
| 371 |
+
Fts5tokTable *pTab = (Fts5tokTable *)(pCursor->pVtab);
|
| 372 |
+
|
| 373 |
+
fts5tokResetCursor(pCsr);
|
| 374 |
+
if( idxNum==1 ){
|
| 375 |
+
const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
|
| 376 |
+
int nByte = sqlite3_value_bytes(apVal[0]);
|
| 377 |
+
pCsr->zInput = sqlite3_malloc(nByte+1);
|
| 378 |
+
if( pCsr->zInput==0 ){
|
| 379 |
+
rc = SQLITE_NOMEM;
|
| 380 |
+
}else{
|
| 381 |
+
if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte);
|
| 382 |
+
pCsr->zInput[nByte] = 0;
|
| 383 |
+
rc = pTab->tok.xTokenize(
|
| 384 |
+
pTab->pTok, (void*)pCsr, 0, zByte, nByte, fts5tokCb
|
| 385 |
+
);
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
if( rc!=SQLITE_OK ) return rc;
|
| 390 |
+
return fts5tokNextMethod(pCursor);
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
/*
|
| 394 |
+
** xEof - Return true if the cursor is at EOF, or false otherwise.
|
| 395 |
+
*/
|
| 396 |
+
static int fts5tokEofMethod(sqlite3_vtab_cursor *pCursor){
|
| 397 |
+
Fts5tokCursor *pCsr = (Fts5tokCursor *)pCursor;
|
| 398 |
+
return (pCsr->iRowid>pCsr->nRow);
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
/*
|
| 402 |
+
** xColumn - Return a column value.
|
| 403 |
+
*/
|
| 404 |
+
static int fts5tokColumnMethod(
|
| 405 |
+
sqlite3_vtab_cursor *pCursor, /* Cursor to retrieve value from */
|
| 406 |
+
sqlite3_context *pCtx, /* Context for sqlite3_result_xxx() calls */
|
| 407 |
+
int iCol /* Index of column to read value from */
|
| 408 |
+
){
|
| 409 |
+
Fts5tokCursor *pCsr = (Fts5tokCursor *)pCursor;
|
| 410 |
+
Fts5tokRow *pRow = &pCsr->aRow[pCsr->iRowid-1];
|
| 411 |
+
|
| 412 |
+
/* CREATE TABLE x(input, token, start, end, position) */
|
| 413 |
+
switch( iCol ){
|
| 414 |
+
case 0:
|
| 415 |
+
sqlite3_result_text(pCtx, pCsr->zInput, -1, SQLITE_TRANSIENT);
|
| 416 |
+
break;
|
| 417 |
+
case 1:
|
| 418 |
+
sqlite3_result_text(pCtx, pRow->zToken, -1, SQLITE_TRANSIENT);
|
| 419 |
+
break;
|
| 420 |
+
case 2:
|
| 421 |
+
sqlite3_result_int(pCtx, pRow->iStart);
|
| 422 |
+
break;
|
| 423 |
+
case 3:
|
| 424 |
+
sqlite3_result_int(pCtx, pRow->iEnd);
|
| 425 |
+
break;
|
| 426 |
+
default:
|
| 427 |
+
assert( iCol==4 );
|
| 428 |
+
sqlite3_result_int(pCtx, pRow->iPos);
|
| 429 |
+
break;
|
| 430 |
+
}
|
| 431 |
+
return SQLITE_OK;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
/*
|
| 435 |
+
** xRowid - Return the current rowid for the cursor.
|
| 436 |
+
*/
|
| 437 |
+
static int fts5tokRowidMethod(
|
| 438 |
+
sqlite3_vtab_cursor *pCursor, /* Cursor to retrieve value from */
|
| 439 |
+
sqlite_int64 *pRowid /* OUT: Rowid value */
|
| 440 |
+
){
|
| 441 |
+
Fts5tokCursor *pCsr = (Fts5tokCursor *)pCursor;
|
| 442 |
+
*pRowid = (sqlite3_int64)pCsr->iRowid;
|
| 443 |
+
return SQLITE_OK;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
/*
|
| 447 |
+
** Register the fts5tok module with database connection db. Return SQLITE_OK
|
| 448 |
+
** if successful or an error code if sqlite3_create_module() fails.
|
| 449 |
+
*/
|
| 450 |
+
int sqlite3Fts5TestRegisterTok(sqlite3 *db, fts5_api *pApi){
|
| 451 |
+
static const sqlite3_module fts5tok_module = {
|
| 452 |
+
0, /* iVersion */
|
| 453 |
+
fts5tokConnectMethod, /* xCreate */
|
| 454 |
+
fts5tokConnectMethod, /* xConnect */
|
| 455 |
+
fts5tokBestIndexMethod, /* xBestIndex */
|
| 456 |
+
fts5tokDisconnectMethod, /* xDisconnect */
|
| 457 |
+
fts5tokDisconnectMethod, /* xDestroy */
|
| 458 |
+
fts5tokOpenMethod, /* xOpen */
|
| 459 |
+
fts5tokCloseMethod, /* xClose */
|
| 460 |
+
fts5tokFilterMethod, /* xFilter */
|
| 461 |
+
fts5tokNextMethod, /* xNext */
|
| 462 |
+
fts5tokEofMethod, /* xEof */
|
| 463 |
+
fts5tokColumnMethod, /* xColumn */
|
| 464 |
+
fts5tokRowidMethod, /* xRowid */
|
| 465 |
+
0, /* xUpdate */
|
| 466 |
+
0, /* xBegin */
|
| 467 |
+
0, /* xSync */
|
| 468 |
+
0, /* xCommit */
|
| 469 |
+
0, /* xRollback */
|
| 470 |
+
0, /* xFindFunction */
|
| 471 |
+
0, /* xRename */
|
| 472 |
+
0, /* xSavepoint */
|
| 473 |
+
0, /* xRelease */
|
| 474 |
+
0, /* xRollbackTo */
|
| 475 |
+
0, /* xShadowName */
|
| 476 |
+
0 /* xIntegrity */
|
| 477 |
+
};
|
| 478 |
+
int rc; /* Return code */
|
| 479 |
+
|
| 480 |
+
rc = sqlite3_create_module(db, "fts5tokenize", &fts5tok_module, (void*)pApi);
|
| 481 |
+
return rc;
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
#endif /* defined(SQLITE_TEST) && defined(SQLITE_ENABLE_FTS5) */
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/fts5/mkportersteps.tcl
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# 2014 Jun 09
|
| 3 |
+
#
|
| 4 |
+
# The author disclaims copyright to this source code. In place of
|
| 5 |
+
# a legal notice, here is a blessing:
|
| 6 |
+
#
|
| 7 |
+
# May you do good and not evil.
|
| 8 |
+
# May you find forgiveness for yourself and forgive others.
|
| 9 |
+
# May you share freely, never taking more than you give.
|
| 10 |
+
#
|
| 11 |
+
#-------------------------------------------------------------------------
|
| 12 |
+
#
|
| 13 |
+
# This script generates the implementations of the following C functions,
|
| 14 |
+
# which are part of the porter tokenizer implementation:
|
| 15 |
+
#
|
| 16 |
+
# static int fts5PorterStep1B(char *aBuf, int *pnBuf);
|
| 17 |
+
# static int fts5PorterStep1B2(char *aBuf, int *pnBuf);
|
| 18 |
+
# static int fts5PorterStep2(char *aBuf, int *pnBuf);
|
| 19 |
+
# static int fts5PorterStep3(char *aBuf, int *pnBuf);
|
| 20 |
+
# static int fts5PorterStep4(char *aBuf, int *pnBuf);
|
| 21 |
+
#
|
| 22 |
+
|
| 23 |
+
set O(Step1B2) {
|
| 24 |
+
{ at {} ate 1 }
|
| 25 |
+
{ bl {} ble 1 }
|
| 26 |
+
{ iz {} ize 1 }
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
set O(Step1B) {
|
| 30 |
+
{ "eed" fts5Porter_MGt0 "ee" 0 }
|
| 31 |
+
{ "ed" fts5Porter_Vowel "" 1 }
|
| 32 |
+
{ "ing" fts5Porter_Vowel "" 1 }
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
set O(Step2) {
|
| 36 |
+
{ "ational" fts5Porter_MGt0 "ate" }
|
| 37 |
+
{ "tional" fts5Porter_MGt0 "tion" }
|
| 38 |
+
{ "enci" fts5Porter_MGt0 "ence" }
|
| 39 |
+
{ "anci" fts5Porter_MGt0 "ance" }
|
| 40 |
+
{ "izer" fts5Porter_MGt0 "ize" }
|
| 41 |
+
{ "logi" fts5Porter_MGt0 "log" }
|
| 42 |
+
{ "bli" fts5Porter_MGt0 "ble" }
|
| 43 |
+
{ "alli" fts5Porter_MGt0 "al" }
|
| 44 |
+
{ "entli" fts5Porter_MGt0 "ent" }
|
| 45 |
+
{ "eli" fts5Porter_MGt0 "e" }
|
| 46 |
+
{ "ousli" fts5Porter_MGt0 "ous" }
|
| 47 |
+
{ "ization" fts5Porter_MGt0 "ize" }
|
| 48 |
+
{ "ation" fts5Porter_MGt0 "ate" }
|
| 49 |
+
{ "ator" fts5Porter_MGt0 "ate" }
|
| 50 |
+
{ "alism" fts5Porter_MGt0 "al" }
|
| 51 |
+
{ "iveness" fts5Porter_MGt0 "ive" }
|
| 52 |
+
{ "fulness" fts5Porter_MGt0 "ful" }
|
| 53 |
+
{ "ousness" fts5Porter_MGt0 "ous" }
|
| 54 |
+
{ "aliti" fts5Porter_MGt0 "al" }
|
| 55 |
+
{ "iviti" fts5Porter_MGt0 "ive" }
|
| 56 |
+
{ "biliti" fts5Porter_MGt0 "ble" }
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
set O(Step3) {
|
| 60 |
+
{ "icate" fts5Porter_MGt0 "ic" }
|
| 61 |
+
{ "ative" fts5Porter_MGt0 "" }
|
| 62 |
+
{ "alize" fts5Porter_MGt0 "al" }
|
| 63 |
+
{ "iciti" fts5Porter_MGt0 "ic" }
|
| 64 |
+
{ "ical" fts5Porter_MGt0 "ic" }
|
| 65 |
+
{ "ful" fts5Porter_MGt0 "" }
|
| 66 |
+
{ "ness" fts5Porter_MGt0 "" }
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
set O(Step4) {
|
| 70 |
+
{ "al" fts5Porter_MGt1 "" }
|
| 71 |
+
{ "ance" fts5Porter_MGt1 "" }
|
| 72 |
+
{ "ence" fts5Porter_MGt1 "" }
|
| 73 |
+
{ "er" fts5Porter_MGt1 "" }
|
| 74 |
+
{ "ic" fts5Porter_MGt1 "" }
|
| 75 |
+
{ "able" fts5Porter_MGt1 "" }
|
| 76 |
+
{ "ible" fts5Porter_MGt1 "" }
|
| 77 |
+
{ "ant" fts5Porter_MGt1 "" }
|
| 78 |
+
{ "ement" fts5Porter_MGt1 "" }
|
| 79 |
+
{ "ment" fts5Porter_MGt1 "" }
|
| 80 |
+
{ "ent" fts5Porter_MGt1 "" }
|
| 81 |
+
{ "ion" fts5Porter_MGt1_and_S_or_T "" }
|
| 82 |
+
{ "ou" fts5Porter_MGt1 "" }
|
| 83 |
+
{ "ism" fts5Porter_MGt1 "" }
|
| 84 |
+
{ "ate" fts5Porter_MGt1 "" }
|
| 85 |
+
{ "iti" fts5Porter_MGt1 "" }
|
| 86 |
+
{ "ous" fts5Porter_MGt1 "" }
|
| 87 |
+
{ "ive" fts5Porter_MGt1 "" }
|
| 88 |
+
{ "ize" fts5Porter_MGt1 "" }
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
proc sort_cb {lhs rhs} {
|
| 92 |
+
set L [string range [lindex $lhs 0] end-1 end-1]
|
| 93 |
+
set R [string range [lindex $rhs 0] end-1 end-1]
|
| 94 |
+
string compare $L $R
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
proc create_step_function {name data} {
|
| 98 |
+
|
| 99 |
+
set T(function) {
|
| 100 |
+
static int fts5Porter${name}(char *aBuf, int *pnBuf){
|
| 101 |
+
int ret = 0;
|
| 102 |
+
int nBuf = *pnBuf;
|
| 103 |
+
switch( aBuf[nBuf-2] ){
|
| 104 |
+
${switchbody}
|
| 105 |
+
}
|
| 106 |
+
return ret;
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
set T(case) {
|
| 111 |
+
case '${k}':
|
| 112 |
+
${ifstmts}
|
| 113 |
+
break;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
set T(if_0_0_0) {
|
| 117 |
+
if( ${match} ){
|
| 118 |
+
*pnBuf = nBuf - $n;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
set T(if_1_0_0) {
|
| 122 |
+
if( ${match} ){
|
| 123 |
+
if( ${cond} ){
|
| 124 |
+
*pnBuf = nBuf - $n;
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
set T(if_0_1_0) {
|
| 129 |
+
if( ${match} ){
|
| 130 |
+
${memcpy}
|
| 131 |
+
*pnBuf = nBuf - $n + $nRep;
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
set T(if_1_1_0) {
|
| 135 |
+
if( ${match} ){
|
| 136 |
+
if( ${cond} ){
|
| 137 |
+
${memcpy}
|
| 138 |
+
*pnBuf = nBuf - $n + $nRep;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
set T(if_1_0_1) {
|
| 143 |
+
if( ${match} ){
|
| 144 |
+
if( ${cond} ){
|
| 145 |
+
*pnBuf = nBuf - $n;
|
| 146 |
+
ret = 1;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
set T(if_0_1_1) {
|
| 151 |
+
if( ${match} ){
|
| 152 |
+
${memcpy}
|
| 153 |
+
*pnBuf = nBuf - $n + $nRep;
|
| 154 |
+
ret = 1;
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
set T(if_1_1_1) {
|
| 158 |
+
if( ${match} ){
|
| 159 |
+
if( ${cond} ){
|
| 160 |
+
${memcpy}
|
| 161 |
+
*pnBuf = nBuf - $n + $nRep;
|
| 162 |
+
ret = 1;
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
set switchbody ""
|
| 168 |
+
|
| 169 |
+
foreach I $data {
|
| 170 |
+
set k [string range [lindex $I 0] end-1 end-1]
|
| 171 |
+
lappend aCase($k) $I
|
| 172 |
+
}
|
| 173 |
+
foreach k [lsort [array names aCase]] {
|
| 174 |
+
set ifstmts ""
|
| 175 |
+
foreach I $aCase($k) {
|
| 176 |
+
set zSuffix [lindex $I 0] ;# Suffix text for this rule
|
| 177 |
+
set zRep [lindex $I 2] ;# Replacement text for rule
|
| 178 |
+
set xCond [lindex $I 1] ;# Condition callback (or "")
|
| 179 |
+
|
| 180 |
+
set n [string length $zSuffix]
|
| 181 |
+
set nRep [string length $zRep]
|
| 182 |
+
|
| 183 |
+
set match "nBuf>$n && 0==memcmp(\"$zSuffix\", &aBuf\[nBuf-$n\], $n)"
|
| 184 |
+
set memcpy "memcpy(&aBuf\[nBuf-$n\], \"$zRep\", $nRep);"
|
| 185 |
+
set cond "${xCond}(aBuf, nBuf-$n)"
|
| 186 |
+
|
| 187 |
+
set bMemcpy [expr {$nRep>0}]
|
| 188 |
+
set bCond [expr {$xCond!=""}]
|
| 189 |
+
set bRet [expr {[llength $I]>3 && [lindex $I 3]}]
|
| 190 |
+
|
| 191 |
+
set t $T(if_${bCond}_${bMemcpy}_${bRet})
|
| 192 |
+
lappend ifstmts [string trim [subst -nocommands $t]]
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
set ifstmts [join $ifstmts "else "]
|
| 196 |
+
|
| 197 |
+
append switchbody [subst -nocommands $T(case)]
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
puts [subst -nocommands $T(function)]
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
puts [string trim {
|
| 206 |
+
/**************************************************************************
|
| 207 |
+
***************************************************************************
|
| 208 |
+
** GENERATED CODE STARTS HERE (mkportersteps.tcl)
|
| 209 |
+
*/
|
| 210 |
+
}]
|
| 211 |
+
foreach step [array names O] {
|
| 212 |
+
create_step_function $step $O($step)
|
| 213 |
+
}
|
| 214 |
+
puts [string trim {
|
| 215 |
+
/*
|
| 216 |
+
** GENERATED CODE ENDS HERE (mkportersteps.tcl)
|
| 217 |
+
***************************************************************************
|
| 218 |
+
**************************************************************************/
|
| 219 |
+
}]
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/dbdata.c
ADDED
|
@@ -0,0 +1,1020 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** 2019-04-17
|
| 3 |
+
**
|
| 4 |
+
** The author disclaims copyright to this source code. In place of
|
| 5 |
+
** a legal notice, here is a blessing:
|
| 6 |
+
**
|
| 7 |
+
** May you do good and not evil.
|
| 8 |
+
** May you find forgiveness for yourself and forgive others.
|
| 9 |
+
** May you share freely, never taking more than you give.
|
| 10 |
+
**
|
| 11 |
+
******************************************************************************
|
| 12 |
+
**
|
| 13 |
+
** This file contains an implementation of two eponymous virtual tables,
|
| 14 |
+
** "sqlite_dbdata" and "sqlite_dbptr". Both modules require that the
|
| 15 |
+
** "sqlite_dbpage" eponymous virtual table be available.
|
| 16 |
+
**
|
| 17 |
+
** SQLITE_DBDATA:
|
| 18 |
+
** sqlite_dbdata is used to extract data directly from a database b-tree
|
| 19 |
+
** page and its associated overflow pages, bypassing the b-tree layer.
|
| 20 |
+
** The table schema is equivalent to:
|
| 21 |
+
**
|
| 22 |
+
** CREATE TABLE sqlite_dbdata(
|
| 23 |
+
** pgno INTEGER,
|
| 24 |
+
** cell INTEGER,
|
| 25 |
+
** field INTEGER,
|
| 26 |
+
** value ANY,
|
| 27 |
+
** schema TEXT HIDDEN
|
| 28 |
+
** );
|
| 29 |
+
**
|
| 30 |
+
** IMPORTANT: THE VIRTUAL TABLE SCHEMA ABOVE IS SUBJECT TO CHANGE. IN THE
|
| 31 |
+
** FUTURE NEW NON-HIDDEN COLUMNS MAY BE ADDED BETWEEN "value" AND
|
| 32 |
+
** "schema".
|
| 33 |
+
**
|
| 34 |
+
** Each page of the database is inspected. If it cannot be interpreted as
|
| 35 |
+
** a b-tree page, or if it is a b-tree page containing 0 entries, the
|
| 36 |
+
** sqlite_dbdata table contains no rows for that page. Otherwise, the
|
| 37 |
+
** table contains one row for each field in the record associated with
|
| 38 |
+
** each cell on the page. For intkey b-trees, the key value is stored in
|
| 39 |
+
** field -1.
|
| 40 |
+
**
|
| 41 |
+
** For example, for the database:
|
| 42 |
+
**
|
| 43 |
+
** CREATE TABLE t1(a, b); -- root page is page 2
|
| 44 |
+
** INSERT INTO t1(rowid, a, b) VALUES(5, 'v', 'five');
|
| 45 |
+
** INSERT INTO t1(rowid, a, b) VALUES(10, 'x', 'ten');
|
| 46 |
+
**
|
| 47 |
+
** the sqlite_dbdata table contains, as well as from entries related to
|
| 48 |
+
** page 1, content equivalent to:
|
| 49 |
+
**
|
| 50 |
+
** INSERT INTO sqlite_dbdata(pgno, cell, field, value) VALUES
|
| 51 |
+
** (2, 0, -1, 5 ),
|
| 52 |
+
** (2, 0, 0, 'v' ),
|
| 53 |
+
** (2, 0, 1, 'five'),
|
| 54 |
+
** (2, 1, -1, 10 ),
|
| 55 |
+
** (2, 1, 0, 'x' ),
|
| 56 |
+
** (2, 1, 1, 'ten' );
|
| 57 |
+
**
|
| 58 |
+
** If database corruption is encountered, this module does not report an
|
| 59 |
+
** error. Instead, it attempts to extract as much data as possible and
|
| 60 |
+
** ignores the corruption.
|
| 61 |
+
**
|
| 62 |
+
** SQLITE_DBPTR:
|
| 63 |
+
** The sqlite_dbptr table has the following schema:
|
| 64 |
+
**
|
| 65 |
+
** CREATE TABLE sqlite_dbptr(
|
| 66 |
+
** pgno INTEGER,
|
| 67 |
+
** child INTEGER,
|
| 68 |
+
** schema TEXT HIDDEN
|
| 69 |
+
** );
|
| 70 |
+
**
|
| 71 |
+
** It contains one entry for each b-tree pointer between a parent and
|
| 72 |
+
** child page in the database.
|
| 73 |
+
*/
|
| 74 |
+
|
| 75 |
+
#if !defined(SQLITEINT_H)
|
| 76 |
+
#include "sqlite3.h"
|
| 77 |
+
|
| 78 |
+
typedef unsigned char u8;
|
| 79 |
+
typedef unsigned int u32;
|
| 80 |
+
|
| 81 |
+
#endif
|
| 82 |
+
#include <string.h>
|
| 83 |
+
#include <assert.h>
|
| 84 |
+
|
| 85 |
+
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
| 86 |
+
|
| 87 |
+
#define DBDATA_PADDING_BYTES 100
|
| 88 |
+
|
| 89 |
+
typedef struct DbdataTable DbdataTable;
|
| 90 |
+
typedef struct DbdataCursor DbdataCursor;
|
| 91 |
+
typedef struct DbdataBuffer DbdataBuffer;
|
| 92 |
+
|
| 93 |
+
/*
|
| 94 |
+
** Buffer type.
|
| 95 |
+
*/
|
| 96 |
+
struct DbdataBuffer {
|
| 97 |
+
u8 *aBuf;
|
| 98 |
+
sqlite3_int64 nBuf;
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
/* Cursor object */
|
| 102 |
+
struct DbdataCursor {
|
| 103 |
+
sqlite3_vtab_cursor base; /* Base class. Must be first */
|
| 104 |
+
sqlite3_stmt *pStmt; /* For fetching database pages */
|
| 105 |
+
|
| 106 |
+
int iPgno; /* Current page number */
|
| 107 |
+
u8 *aPage; /* Buffer containing page */
|
| 108 |
+
int nPage; /* Size of aPage[] in bytes */
|
| 109 |
+
int nCell; /* Number of cells on aPage[] */
|
| 110 |
+
int iCell; /* Current cell number */
|
| 111 |
+
int bOnePage; /* True to stop after one page */
|
| 112 |
+
int szDb;
|
| 113 |
+
sqlite3_int64 iRowid;
|
| 114 |
+
|
| 115 |
+
/* Only for the sqlite_dbdata table */
|
| 116 |
+
DbdataBuffer rec;
|
| 117 |
+
sqlite3_int64 nRec; /* Size of pRec[] in bytes */
|
| 118 |
+
sqlite3_int64 nHdr; /* Size of header in bytes */
|
| 119 |
+
int iField; /* Current field number */
|
| 120 |
+
u8 *pHdrPtr;
|
| 121 |
+
u8 *pPtr;
|
| 122 |
+
u32 enc; /* Text encoding */
|
| 123 |
+
|
| 124 |
+
sqlite3_int64 iIntkey; /* Integer key value */
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
/* Table object */
|
| 128 |
+
struct DbdataTable {
|
| 129 |
+
sqlite3_vtab base; /* Base class. Must be first */
|
| 130 |
+
sqlite3 *db; /* The database connection */
|
| 131 |
+
sqlite3_stmt *pStmt; /* For fetching database pages */
|
| 132 |
+
int bPtr; /* True for sqlite3_dbptr table */
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
/* Column and schema definitions for sqlite_dbdata */
|
| 136 |
+
#define DBDATA_COLUMN_PGNO 0
|
| 137 |
+
#define DBDATA_COLUMN_CELL 1
|
| 138 |
+
#define DBDATA_COLUMN_FIELD 2
|
| 139 |
+
#define DBDATA_COLUMN_VALUE 3
|
| 140 |
+
#define DBDATA_COLUMN_SCHEMA 4
|
| 141 |
+
#define DBDATA_SCHEMA \
|
| 142 |
+
"CREATE TABLE x(" \
|
| 143 |
+
" pgno INTEGER," \
|
| 144 |
+
" cell INTEGER," \
|
| 145 |
+
" field INTEGER," \
|
| 146 |
+
" value ANY," \
|
| 147 |
+
" schema TEXT HIDDEN" \
|
| 148 |
+
")"
|
| 149 |
+
|
| 150 |
+
/* Column and schema definitions for sqlite_dbptr */
|
| 151 |
+
#define DBPTR_COLUMN_PGNO 0
|
| 152 |
+
#define DBPTR_COLUMN_CHILD 1
|
| 153 |
+
#define DBPTR_COLUMN_SCHEMA 2
|
| 154 |
+
#define DBPTR_SCHEMA \
|
| 155 |
+
"CREATE TABLE x(" \
|
| 156 |
+
" pgno INTEGER," \
|
| 157 |
+
" child INTEGER," \
|
| 158 |
+
" schema TEXT HIDDEN" \
|
| 159 |
+
")"
|
| 160 |
+
|
| 161 |
+
/*
|
| 162 |
+
** Ensure the buffer passed as the first argument is at least nMin bytes
|
| 163 |
+
** in size. If an error occurs while attempting to resize the buffer,
|
| 164 |
+
** SQLITE_NOMEM is returned. Otherwise, SQLITE_OK.
|
| 165 |
+
*/
|
| 166 |
+
static int dbdataBufferSize(DbdataBuffer *pBuf, sqlite3_int64 nMin){
|
| 167 |
+
if( nMin>pBuf->nBuf ){
|
| 168 |
+
sqlite3_int64 nNew = nMin+16384;
|
| 169 |
+
u8 *aNew = (u8*)sqlite3_realloc64(pBuf->aBuf, nNew);
|
| 170 |
+
|
| 171 |
+
if( aNew==0 ) return SQLITE_NOMEM;
|
| 172 |
+
pBuf->aBuf = aNew;
|
| 173 |
+
pBuf->nBuf = nNew;
|
| 174 |
+
}
|
| 175 |
+
return SQLITE_OK;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/*
|
| 179 |
+
** Release the allocation managed by buffer pBuf.
|
| 180 |
+
*/
|
| 181 |
+
static void dbdataBufferFree(DbdataBuffer *pBuf){
|
| 182 |
+
sqlite3_free(pBuf->aBuf);
|
| 183 |
+
memset(pBuf, 0, sizeof(*pBuf));
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/*
|
| 187 |
+
** Connect to an sqlite_dbdata (pAux==0) or sqlite_dbptr (pAux!=0) virtual
|
| 188 |
+
** table.
|
| 189 |
+
*/
|
| 190 |
+
static int dbdataConnect(
|
| 191 |
+
sqlite3 *db,
|
| 192 |
+
void *pAux,
|
| 193 |
+
int argc, const char *const*argv,
|
| 194 |
+
sqlite3_vtab **ppVtab,
|
| 195 |
+
char **pzErr
|
| 196 |
+
){
|
| 197 |
+
DbdataTable *pTab = 0;
|
| 198 |
+
int rc = sqlite3_declare_vtab(db, pAux ? DBPTR_SCHEMA : DBDATA_SCHEMA);
|
| 199 |
+
|
| 200 |
+
(void)argc;
|
| 201 |
+
(void)argv;
|
| 202 |
+
(void)pzErr;
|
| 203 |
+
sqlite3_vtab_config(db, SQLITE_VTAB_USES_ALL_SCHEMAS);
|
| 204 |
+
if( rc==SQLITE_OK ){
|
| 205 |
+
pTab = (DbdataTable*)sqlite3_malloc64(sizeof(DbdataTable));
|
| 206 |
+
if( pTab==0 ){
|
| 207 |
+
rc = SQLITE_NOMEM;
|
| 208 |
+
}else{
|
| 209 |
+
memset(pTab, 0, sizeof(DbdataTable));
|
| 210 |
+
pTab->db = db;
|
| 211 |
+
pTab->bPtr = (pAux!=0);
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
*ppVtab = (sqlite3_vtab*)pTab;
|
| 216 |
+
return rc;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/*
|
| 220 |
+
** Disconnect from or destroy a sqlite_dbdata or sqlite_dbptr virtual table.
|
| 221 |
+
*/
|
| 222 |
+
static int dbdataDisconnect(sqlite3_vtab *pVtab){
|
| 223 |
+
DbdataTable *pTab = (DbdataTable*)pVtab;
|
| 224 |
+
if( pTab ){
|
| 225 |
+
sqlite3_finalize(pTab->pStmt);
|
| 226 |
+
sqlite3_free(pVtab);
|
| 227 |
+
}
|
| 228 |
+
return SQLITE_OK;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/*
|
| 232 |
+
** This function interprets two types of constraints:
|
| 233 |
+
**
|
| 234 |
+
** schema=?
|
| 235 |
+
** pgno=?
|
| 236 |
+
**
|
| 237 |
+
** If neither are present, idxNum is set to 0. If schema=? is present,
|
| 238 |
+
** the 0x01 bit in idxNum is set. If pgno=? is present, the 0x02 bit
|
| 239 |
+
** in idxNum is set.
|
| 240 |
+
**
|
| 241 |
+
** If both parameters are present, schema is in position 0 and pgno in
|
| 242 |
+
** position 1.
|
| 243 |
+
*/
|
| 244 |
+
static int dbdataBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdx){
|
| 245 |
+
DbdataTable *pTab = (DbdataTable*)tab;
|
| 246 |
+
int i;
|
| 247 |
+
int iSchema = -1;
|
| 248 |
+
int iPgno = -1;
|
| 249 |
+
int colSchema = (pTab->bPtr ? DBPTR_COLUMN_SCHEMA : DBDATA_COLUMN_SCHEMA);
|
| 250 |
+
|
| 251 |
+
for(i=0; i<pIdx->nConstraint; i++){
|
| 252 |
+
struct sqlite3_index_constraint *p = &pIdx->aConstraint[i];
|
| 253 |
+
if( p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
|
| 254 |
+
if( p->iColumn==colSchema ){
|
| 255 |
+
if( p->usable==0 ) return SQLITE_CONSTRAINT;
|
| 256 |
+
iSchema = i;
|
| 257 |
+
}
|
| 258 |
+
if( p->iColumn==DBDATA_COLUMN_PGNO && p->usable ){
|
| 259 |
+
iPgno = i;
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
if( iSchema>=0 ){
|
| 265 |
+
pIdx->aConstraintUsage[iSchema].argvIndex = 1;
|
| 266 |
+
pIdx->aConstraintUsage[iSchema].omit = 1;
|
| 267 |
+
}
|
| 268 |
+
if( iPgno>=0 ){
|
| 269 |
+
pIdx->aConstraintUsage[iPgno].argvIndex = 1 + (iSchema>=0);
|
| 270 |
+
pIdx->aConstraintUsage[iPgno].omit = 1;
|
| 271 |
+
pIdx->estimatedCost = 100;
|
| 272 |
+
pIdx->estimatedRows = 50;
|
| 273 |
+
|
| 274 |
+
if( pTab->bPtr==0 && pIdx->nOrderBy && pIdx->aOrderBy[0].desc==0 ){
|
| 275 |
+
int iCol = pIdx->aOrderBy[0].iColumn;
|
| 276 |
+
if( pIdx->nOrderBy==1 ){
|
| 277 |
+
pIdx->orderByConsumed = (iCol==0 || iCol==1);
|
| 278 |
+
}else if( pIdx->nOrderBy==2 && pIdx->aOrderBy[1].desc==0 && iCol==0 ){
|
| 279 |
+
pIdx->orderByConsumed = (pIdx->aOrderBy[1].iColumn==1);
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
}else{
|
| 284 |
+
pIdx->estimatedCost = 100000000;
|
| 285 |
+
pIdx->estimatedRows = 1000000000;
|
| 286 |
+
}
|
| 287 |
+
pIdx->idxNum = (iSchema>=0 ? 0x01 : 0x00) | (iPgno>=0 ? 0x02 : 0x00);
|
| 288 |
+
return SQLITE_OK;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
/*
|
| 292 |
+
** Open a new sqlite_dbdata or sqlite_dbptr cursor.
|
| 293 |
+
*/
|
| 294 |
+
static int dbdataOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
|
| 295 |
+
DbdataCursor *pCsr;
|
| 296 |
+
|
| 297 |
+
pCsr = (DbdataCursor*)sqlite3_malloc64(sizeof(DbdataCursor));
|
| 298 |
+
if( pCsr==0 ){
|
| 299 |
+
return SQLITE_NOMEM;
|
| 300 |
+
}else{
|
| 301 |
+
memset(pCsr, 0, sizeof(DbdataCursor));
|
| 302 |
+
pCsr->base.pVtab = pVTab;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
*ppCursor = (sqlite3_vtab_cursor *)pCsr;
|
| 306 |
+
return SQLITE_OK;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
/*
|
| 310 |
+
** Restore a cursor object to the state it was in when first allocated
|
| 311 |
+
** by dbdataOpen().
|
| 312 |
+
*/
|
| 313 |
+
static void dbdataResetCursor(DbdataCursor *pCsr){
|
| 314 |
+
DbdataTable *pTab = (DbdataTable*)(pCsr->base.pVtab);
|
| 315 |
+
if( pTab->pStmt==0 ){
|
| 316 |
+
pTab->pStmt = pCsr->pStmt;
|
| 317 |
+
}else{
|
| 318 |
+
sqlite3_finalize(pCsr->pStmt);
|
| 319 |
+
}
|
| 320 |
+
pCsr->pStmt = 0;
|
| 321 |
+
pCsr->iPgno = 1;
|
| 322 |
+
pCsr->iCell = 0;
|
| 323 |
+
pCsr->iField = 0;
|
| 324 |
+
pCsr->bOnePage = 0;
|
| 325 |
+
sqlite3_free(pCsr->aPage);
|
| 326 |
+
dbdataBufferFree(&pCsr->rec);
|
| 327 |
+
pCsr->aPage = 0;
|
| 328 |
+
pCsr->nRec = 0;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
/*
|
| 332 |
+
** Close an sqlite_dbdata or sqlite_dbptr cursor.
|
| 333 |
+
*/
|
| 334 |
+
static int dbdataClose(sqlite3_vtab_cursor *pCursor){
|
| 335 |
+
DbdataCursor *pCsr = (DbdataCursor*)pCursor;
|
| 336 |
+
dbdataResetCursor(pCsr);
|
| 337 |
+
sqlite3_free(pCsr);
|
| 338 |
+
return SQLITE_OK;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
/*
|
| 342 |
+
** Utility methods to decode 16 and 32-bit big-endian unsigned integers.
|
| 343 |
+
*/
|
| 344 |
+
static u32 get_uint16(unsigned char *a){
|
| 345 |
+
return (a[0]<<8)|a[1];
|
| 346 |
+
}
|
| 347 |
+
static u32 get_uint32(unsigned char *a){
|
| 348 |
+
return ((u32)a[0]<<24)
|
| 349 |
+
| ((u32)a[1]<<16)
|
| 350 |
+
| ((u32)a[2]<<8)
|
| 351 |
+
| ((u32)a[3]);
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
/*
|
| 355 |
+
** Load page pgno from the database via the sqlite_dbpage virtual table.
|
| 356 |
+
** If successful, set (*ppPage) to point to a buffer containing the page
|
| 357 |
+
** data, (*pnPage) to the size of that buffer in bytes and return
|
| 358 |
+
** SQLITE_OK. In this case it is the responsibility of the caller to
|
| 359 |
+
** eventually free the buffer using sqlite3_free().
|
| 360 |
+
**
|
| 361 |
+
** Or, if an error occurs, set both (*ppPage) and (*pnPage) to 0 and
|
| 362 |
+
** return an SQLite error code.
|
| 363 |
+
*/
|
| 364 |
+
static int dbdataLoadPage(
|
| 365 |
+
DbdataCursor *pCsr, /* Cursor object */
|
| 366 |
+
u32 pgno, /* Page number of page to load */
|
| 367 |
+
u8 **ppPage, /* OUT: pointer to page buffer */
|
| 368 |
+
int *pnPage /* OUT: Size of (*ppPage) in bytes */
|
| 369 |
+
){
|
| 370 |
+
int rc2;
|
| 371 |
+
int rc = SQLITE_OK;
|
| 372 |
+
sqlite3_stmt *pStmt = pCsr->pStmt;
|
| 373 |
+
|
| 374 |
+
*ppPage = 0;
|
| 375 |
+
*pnPage = 0;
|
| 376 |
+
if( pgno>0 ){
|
| 377 |
+
sqlite3_bind_int64(pStmt, 2, pgno);
|
| 378 |
+
if( SQLITE_ROW==sqlite3_step(pStmt) ){
|
| 379 |
+
int nCopy = sqlite3_column_bytes(pStmt, 0);
|
| 380 |
+
if( nCopy>0 ){
|
| 381 |
+
u8 *pPage;
|
| 382 |
+
pPage = (u8*)sqlite3_malloc64(nCopy + DBDATA_PADDING_BYTES);
|
| 383 |
+
if( pPage==0 ){
|
| 384 |
+
rc = SQLITE_NOMEM;
|
| 385 |
+
}else{
|
| 386 |
+
const u8 *pCopy = sqlite3_column_blob(pStmt, 0);
|
| 387 |
+
memcpy(pPage, pCopy, nCopy);
|
| 388 |
+
memset(&pPage[nCopy], 0, DBDATA_PADDING_BYTES);
|
| 389 |
+
}
|
| 390 |
+
*ppPage = pPage;
|
| 391 |
+
*pnPage = nCopy;
|
| 392 |
+
}
|
| 393 |
+
}
|
| 394 |
+
rc2 = sqlite3_reset(pStmt);
|
| 395 |
+
if( rc==SQLITE_OK ) rc = rc2;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
return rc;
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
/*
|
| 402 |
+
** Read a varint. Put the value in *pVal and return the number of bytes.
|
| 403 |
+
*/
|
| 404 |
+
static int dbdataGetVarint(const u8 *z, sqlite3_int64 *pVal){
|
| 405 |
+
sqlite3_uint64 u = 0;
|
| 406 |
+
int i;
|
| 407 |
+
for(i=0; i<8; i++){
|
| 408 |
+
u = (u<<7) + (z[i]&0x7f);
|
| 409 |
+
if( (z[i]&0x80)==0 ){ *pVal = (sqlite3_int64)u; return i+1; }
|
| 410 |
+
}
|
| 411 |
+
u = (u<<8) + (z[i]&0xff);
|
| 412 |
+
*pVal = (sqlite3_int64)u;
|
| 413 |
+
return 9;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
/*
|
| 417 |
+
** Like dbdataGetVarint(), but set the output to 0 if it is less than 0
|
| 418 |
+
** or greater than 0xFFFFFFFF. This can be used for all varints in an
|
| 419 |
+
** SQLite database except for key values in intkey tables.
|
| 420 |
+
*/
|
| 421 |
+
static int dbdataGetVarintU32(const u8 *z, sqlite3_int64 *pVal){
|
| 422 |
+
sqlite3_int64 val;
|
| 423 |
+
int nRet = dbdataGetVarint(z, &val);
|
| 424 |
+
if( val<0 || val>0xFFFFFFFF ) val = 0;
|
| 425 |
+
*pVal = val;
|
| 426 |
+
return nRet;
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
/*
|
| 430 |
+
** Return the number of bytes of space used by an SQLite value of type
|
| 431 |
+
** eType.
|
| 432 |
+
*/
|
| 433 |
+
static int dbdataValueBytes(int eType){
|
| 434 |
+
switch( eType ){
|
| 435 |
+
case 0: case 8: case 9:
|
| 436 |
+
case 10: case 11:
|
| 437 |
+
return 0;
|
| 438 |
+
case 1:
|
| 439 |
+
return 1;
|
| 440 |
+
case 2:
|
| 441 |
+
return 2;
|
| 442 |
+
case 3:
|
| 443 |
+
return 3;
|
| 444 |
+
case 4:
|
| 445 |
+
return 4;
|
| 446 |
+
case 5:
|
| 447 |
+
return 6;
|
| 448 |
+
case 6:
|
| 449 |
+
case 7:
|
| 450 |
+
return 8;
|
| 451 |
+
default:
|
| 452 |
+
if( eType>0 ){
|
| 453 |
+
return ((eType-12) / 2);
|
| 454 |
+
}
|
| 455 |
+
return 0;
|
| 456 |
+
}
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
/*
|
| 460 |
+
** Load a value of type eType from buffer pData and use it to set the
|
| 461 |
+
** result of context object pCtx.
|
| 462 |
+
*/
|
| 463 |
+
static void dbdataValue(
|
| 464 |
+
sqlite3_context *pCtx,
|
| 465 |
+
u32 enc,
|
| 466 |
+
int eType,
|
| 467 |
+
u8 *pData,
|
| 468 |
+
sqlite3_int64 nData
|
| 469 |
+
){
|
| 470 |
+
if( eType>=0 ){
|
| 471 |
+
if( dbdataValueBytes(eType)<=nData ){
|
| 472 |
+
switch( eType ){
|
| 473 |
+
case 0:
|
| 474 |
+
case 10:
|
| 475 |
+
case 11:
|
| 476 |
+
sqlite3_result_null(pCtx);
|
| 477 |
+
break;
|
| 478 |
+
|
| 479 |
+
case 8:
|
| 480 |
+
sqlite3_result_int(pCtx, 0);
|
| 481 |
+
break;
|
| 482 |
+
case 9:
|
| 483 |
+
sqlite3_result_int(pCtx, 1);
|
| 484 |
+
break;
|
| 485 |
+
|
| 486 |
+
case 1: case 2: case 3: case 4: case 5: case 6: case 7: {
|
| 487 |
+
sqlite3_uint64 v = (signed char)pData[0];
|
| 488 |
+
pData++;
|
| 489 |
+
switch( eType ){
|
| 490 |
+
case 7:
|
| 491 |
+
case 6: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2;
|
| 492 |
+
case 5: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2;
|
| 493 |
+
case 4: v = (v<<8) + pData[0]; pData++;
|
| 494 |
+
case 3: v = (v<<8) + pData[0]; pData++;
|
| 495 |
+
case 2: v = (v<<8) + pData[0]; pData++;
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
if( eType==7 ){
|
| 499 |
+
double r;
|
| 500 |
+
memcpy(&r, &v, sizeof(r));
|
| 501 |
+
sqlite3_result_double(pCtx, r);
|
| 502 |
+
}else{
|
| 503 |
+
sqlite3_result_int64(pCtx, (sqlite3_int64)v);
|
| 504 |
+
}
|
| 505 |
+
break;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
default: {
|
| 509 |
+
int n = ((eType-12) / 2);
|
| 510 |
+
if( eType % 2 ){
|
| 511 |
+
switch( enc ){
|
| 512 |
+
#ifndef SQLITE_OMIT_UTF16
|
| 513 |
+
case SQLITE_UTF16BE:
|
| 514 |
+
sqlite3_result_text16be(pCtx, (void*)pData, n, SQLITE_TRANSIENT);
|
| 515 |
+
break;
|
| 516 |
+
case SQLITE_UTF16LE:
|
| 517 |
+
sqlite3_result_text16le(pCtx, (void*)pData, n, SQLITE_TRANSIENT);
|
| 518 |
+
break;
|
| 519 |
+
#endif
|
| 520 |
+
default:
|
| 521 |
+
sqlite3_result_text(pCtx, (char*)pData, n, SQLITE_TRANSIENT);
|
| 522 |
+
break;
|
| 523 |
+
}
|
| 524 |
+
}else{
|
| 525 |
+
sqlite3_result_blob(pCtx, pData, n, SQLITE_TRANSIENT);
|
| 526 |
+
}
|
| 527 |
+
}
|
| 528 |
+
}
|
| 529 |
+
}else{
|
| 530 |
+
if( eType==7 ){
|
| 531 |
+
sqlite3_result_double(pCtx, 0.0);
|
| 532 |
+
}else if( eType<7 ){
|
| 533 |
+
sqlite3_result_int(pCtx, 0);
|
| 534 |
+
}else if( eType%2 ){
|
| 535 |
+
sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
|
| 536 |
+
}else{
|
| 537 |
+
sqlite3_result_blob(pCtx, "", 0, SQLITE_STATIC);
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
+
}
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
/* This macro is a copy of the MX_CELL() macro in the SQLite core. Given
|
| 544 |
+
** a page-size, it returns the maximum number of cells that may be present
|
| 545 |
+
** on the page. */
|
| 546 |
+
#define DBDATA_MX_CELL(pgsz) ((pgsz-8)/6)
|
| 547 |
+
|
| 548 |
+
/* Maximum number of fields that may appear in a single record. This is
|
| 549 |
+
** the "hard-limit", according to comments in sqliteLimit.h. */
|
| 550 |
+
#define DBDATA_MX_FIELD 32676
|
| 551 |
+
|
| 552 |
+
/*
|
| 553 |
+
** Move an sqlite_dbdata or sqlite_dbptr cursor to the next entry.
|
| 554 |
+
*/
|
| 555 |
+
static int dbdataNext(sqlite3_vtab_cursor *pCursor){
|
| 556 |
+
DbdataCursor *pCsr = (DbdataCursor*)pCursor;
|
| 557 |
+
DbdataTable *pTab = (DbdataTable*)pCursor->pVtab;
|
| 558 |
+
|
| 559 |
+
pCsr->iRowid++;
|
| 560 |
+
while( 1 ){
|
| 561 |
+
int rc;
|
| 562 |
+
int iOff = (pCsr->iPgno==1 ? 100 : 0);
|
| 563 |
+
int bNextPage = 0;
|
| 564 |
+
|
| 565 |
+
if( pCsr->aPage==0 ){
|
| 566 |
+
while( 1 ){
|
| 567 |
+
if( pCsr->bOnePage==0 && pCsr->iPgno>pCsr->szDb ) return SQLITE_OK;
|
| 568 |
+
rc = dbdataLoadPage(pCsr, pCsr->iPgno, &pCsr->aPage, &pCsr->nPage);
|
| 569 |
+
if( rc!=SQLITE_OK ) return rc;
|
| 570 |
+
if( pCsr->aPage && pCsr->nPage>=256 ) break;
|
| 571 |
+
sqlite3_free(pCsr->aPage);
|
| 572 |
+
pCsr->aPage = 0;
|
| 573 |
+
if( pCsr->bOnePage ) return SQLITE_OK;
|
| 574 |
+
pCsr->iPgno++;
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
assert( iOff+3+2<=pCsr->nPage );
|
| 578 |
+
pCsr->iCell = pTab->bPtr ? -2 : 0;
|
| 579 |
+
pCsr->nCell = get_uint16(&pCsr->aPage[iOff+3]);
|
| 580 |
+
if( pCsr->nCell>DBDATA_MX_CELL(pCsr->nPage) ){
|
| 581 |
+
pCsr->nCell = DBDATA_MX_CELL(pCsr->nPage);
|
| 582 |
+
}
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
if( pTab->bPtr ){
|
| 586 |
+
if( pCsr->aPage[iOff]!=0x02 && pCsr->aPage[iOff]!=0x05 ){
|
| 587 |
+
pCsr->iCell = pCsr->nCell;
|
| 588 |
+
}
|
| 589 |
+
pCsr->iCell++;
|
| 590 |
+
if( pCsr->iCell>=pCsr->nCell ){
|
| 591 |
+
sqlite3_free(pCsr->aPage);
|
| 592 |
+
pCsr->aPage = 0;
|
| 593 |
+
if( pCsr->bOnePage ) return SQLITE_OK;
|
| 594 |
+
pCsr->iPgno++;
|
| 595 |
+
}else{
|
| 596 |
+
return SQLITE_OK;
|
| 597 |
+
}
|
| 598 |
+
}else{
|
| 599 |
+
/* If there is no record loaded, load it now. */
|
| 600 |
+
assert( pCsr->rec.aBuf!=0 || pCsr->nRec==0 );
|
| 601 |
+
if( pCsr->nRec==0 ){
|
| 602 |
+
int bHasRowid = 0;
|
| 603 |
+
int nPointer = 0;
|
| 604 |
+
sqlite3_int64 nPayload = 0;
|
| 605 |
+
sqlite3_int64 nHdr = 0;
|
| 606 |
+
int iHdr;
|
| 607 |
+
int U, X;
|
| 608 |
+
int nLocal;
|
| 609 |
+
|
| 610 |
+
switch( pCsr->aPage[iOff] ){
|
| 611 |
+
case 0x02:
|
| 612 |
+
nPointer = 4;
|
| 613 |
+
break;
|
| 614 |
+
case 0x0a:
|
| 615 |
+
break;
|
| 616 |
+
case 0x0d:
|
| 617 |
+
bHasRowid = 1;
|
| 618 |
+
break;
|
| 619 |
+
default:
|
| 620 |
+
/* This is not a b-tree page with records on it. Continue. */
|
| 621 |
+
pCsr->iCell = pCsr->nCell;
|
| 622 |
+
break;
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
if( pCsr->iCell>=pCsr->nCell ){
|
| 626 |
+
bNextPage = 1;
|
| 627 |
+
}else{
|
| 628 |
+
int iCellPtr = iOff + 8 + nPointer + pCsr->iCell*2;
|
| 629 |
+
|
| 630 |
+
if( iCellPtr>pCsr->nPage ){
|
| 631 |
+
bNextPage = 1;
|
| 632 |
+
}else{
|
| 633 |
+
iOff = get_uint16(&pCsr->aPage[iCellPtr]);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
/* For an interior node cell, skip past the child-page number */
|
| 637 |
+
iOff += nPointer;
|
| 638 |
+
|
| 639 |
+
/* Load the "byte of payload including overflow" field */
|
| 640 |
+
if( bNextPage || iOff>pCsr->nPage || iOff<=iCellPtr ){
|
| 641 |
+
bNextPage = 1;
|
| 642 |
+
}else{
|
| 643 |
+
iOff += dbdataGetVarintU32(&pCsr->aPage[iOff], &nPayload);
|
| 644 |
+
if( nPayload>0x7fffff00 ) nPayload &= 0x3fff;
|
| 645 |
+
if( nPayload==0 ) nPayload = 1;
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
/* If this is a leaf intkey cell, load the rowid */
|
| 649 |
+
if( bHasRowid && !bNextPage && iOff<pCsr->nPage ){
|
| 650 |
+
iOff += dbdataGetVarint(&pCsr->aPage[iOff], &pCsr->iIntkey);
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
/* Figure out how much data to read from the local page */
|
| 654 |
+
U = pCsr->nPage;
|
| 655 |
+
if( bHasRowid ){
|
| 656 |
+
X = U-35;
|
| 657 |
+
}else{
|
| 658 |
+
X = ((U-12)*64/255)-23;
|
| 659 |
+
}
|
| 660 |
+
if( nPayload<=X ){
|
| 661 |
+
nLocal = nPayload;
|
| 662 |
+
}else{
|
| 663 |
+
int M, K;
|
| 664 |
+
M = ((U-12)*32/255)-23;
|
| 665 |
+
K = M+((nPayload-M)%(U-4));
|
| 666 |
+
if( K<=X ){
|
| 667 |
+
nLocal = K;
|
| 668 |
+
}else{
|
| 669 |
+
nLocal = M;
|
| 670 |
+
}
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
if( bNextPage || nLocal+iOff>pCsr->nPage ){
|
| 674 |
+
bNextPage = 1;
|
| 675 |
+
}else{
|
| 676 |
+
|
| 677 |
+
/* Allocate space for payload. And a bit more to catch small buffer
|
| 678 |
+
** overruns caused by attempting to read a varint or similar from
|
| 679 |
+
** near the end of a corrupt record. */
|
| 680 |
+
rc = dbdataBufferSize(&pCsr->rec, nPayload+DBDATA_PADDING_BYTES);
|
| 681 |
+
if( rc!=SQLITE_OK ) return rc;
|
| 682 |
+
assert( pCsr->rec.aBuf!=0 );
|
| 683 |
+
assert( nPayload!=0 );
|
| 684 |
+
|
| 685 |
+
/* Load the nLocal bytes of payload */
|
| 686 |
+
memcpy(pCsr->rec.aBuf, &pCsr->aPage[iOff], nLocal);
|
| 687 |
+
iOff += nLocal;
|
| 688 |
+
|
| 689 |
+
/* Load content from overflow pages */
|
| 690 |
+
if( nPayload>nLocal ){
|
| 691 |
+
sqlite3_int64 nRem = nPayload - nLocal;
|
| 692 |
+
u32 pgnoOvfl = get_uint32(&pCsr->aPage[iOff]);
|
| 693 |
+
while( nRem>0 ){
|
| 694 |
+
u8 *aOvfl = 0;
|
| 695 |
+
int nOvfl = 0;
|
| 696 |
+
int nCopy;
|
| 697 |
+
rc = dbdataLoadPage(pCsr, pgnoOvfl, &aOvfl, &nOvfl);
|
| 698 |
+
assert( rc!=SQLITE_OK || aOvfl==0 || nOvfl==pCsr->nPage );
|
| 699 |
+
if( rc!=SQLITE_OK ) return rc;
|
| 700 |
+
if( aOvfl==0 ) break;
|
| 701 |
+
|
| 702 |
+
nCopy = U-4;
|
| 703 |
+
if( nCopy>nRem ) nCopy = nRem;
|
| 704 |
+
memcpy(&pCsr->rec.aBuf[nPayload-nRem], &aOvfl[4], nCopy);
|
| 705 |
+
nRem -= nCopy;
|
| 706 |
+
|
| 707 |
+
pgnoOvfl = get_uint32(aOvfl);
|
| 708 |
+
sqlite3_free(aOvfl);
|
| 709 |
+
}
|
| 710 |
+
nPayload -= nRem;
|
| 711 |
+
}
|
| 712 |
+
memset(&pCsr->rec.aBuf[nPayload], 0, DBDATA_PADDING_BYTES);
|
| 713 |
+
pCsr->nRec = nPayload;
|
| 714 |
+
|
| 715 |
+
iHdr = dbdataGetVarintU32(pCsr->rec.aBuf, &nHdr);
|
| 716 |
+
if( nHdr>nPayload ) nHdr = 0;
|
| 717 |
+
pCsr->nHdr = nHdr;
|
| 718 |
+
pCsr->pHdrPtr = &pCsr->rec.aBuf[iHdr];
|
| 719 |
+
pCsr->pPtr = &pCsr->rec.aBuf[pCsr->nHdr];
|
| 720 |
+
pCsr->iField = (bHasRowid ? -1 : 0);
|
| 721 |
+
}
|
| 722 |
+
}
|
| 723 |
+
}else{
|
| 724 |
+
pCsr->iField++;
|
| 725 |
+
if( pCsr->iField>0 ){
|
| 726 |
+
sqlite3_int64 iType;
|
| 727 |
+
if( pCsr->pHdrPtr>=&pCsr->rec.aBuf[pCsr->nRec]
|
| 728 |
+
|| pCsr->iField>=DBDATA_MX_FIELD
|
| 729 |
+
){
|
| 730 |
+
bNextPage = 1;
|
| 731 |
+
}else{
|
| 732 |
+
int szField = 0;
|
| 733 |
+
pCsr->pHdrPtr += dbdataGetVarintU32(pCsr->pHdrPtr, &iType);
|
| 734 |
+
szField = dbdataValueBytes(iType);
|
| 735 |
+
if( (pCsr->nRec - (pCsr->pPtr - pCsr->rec.aBuf))<szField ){
|
| 736 |
+
pCsr->pPtr = &pCsr->rec.aBuf[pCsr->nRec];
|
| 737 |
+
}else{
|
| 738 |
+
pCsr->pPtr += szField;
|
| 739 |
+
}
|
| 740 |
+
}
|
| 741 |
+
}
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
if( bNextPage ){
|
| 745 |
+
sqlite3_free(pCsr->aPage);
|
| 746 |
+
pCsr->aPage = 0;
|
| 747 |
+
pCsr->nRec = 0;
|
| 748 |
+
if( pCsr->bOnePage ) return SQLITE_OK;
|
| 749 |
+
pCsr->iPgno++;
|
| 750 |
+
}else{
|
| 751 |
+
if( pCsr->iField<0 || pCsr->pHdrPtr<&pCsr->rec.aBuf[pCsr->nHdr] ){
|
| 752 |
+
return SQLITE_OK;
|
| 753 |
+
}
|
| 754 |
+
|
| 755 |
+
/* Advance to the next cell. The next iteration of the loop will load
|
| 756 |
+
** the record and so on. */
|
| 757 |
+
pCsr->nRec = 0;
|
| 758 |
+
pCsr->iCell++;
|
| 759 |
+
}
|
| 760 |
+
}
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
assert( !"can't get here" );
|
| 764 |
+
return SQLITE_OK;
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
/*
|
| 768 |
+
** Return true if the cursor is at EOF.
|
| 769 |
+
*/
|
| 770 |
+
static int dbdataEof(sqlite3_vtab_cursor *pCursor){
|
| 771 |
+
DbdataCursor *pCsr = (DbdataCursor*)pCursor;
|
| 772 |
+
return pCsr->aPage==0;
|
| 773 |
+
}
|
| 774 |
+
|
| 775 |
+
/*
|
| 776 |
+
** Return true if nul-terminated string zSchema ends in "()". Or false
|
| 777 |
+
** otherwise.
|
| 778 |
+
*/
|
| 779 |
+
static int dbdataIsFunction(const char *zSchema){
|
| 780 |
+
size_t n = strlen(zSchema);
|
| 781 |
+
if( n>2 && zSchema[n-2]=='(' && zSchema[n-1]==')' ){
|
| 782 |
+
return (int)n-2;
|
| 783 |
+
}
|
| 784 |
+
return 0;
|
| 785 |
+
}
|
| 786 |
+
|
| 787 |
+
/*
|
| 788 |
+
** Determine the size in pages of database zSchema (where zSchema is
|
| 789 |
+
** "main", "temp" or the name of an attached database) and set
|
| 790 |
+
** pCsr->szDb accordingly. If successful, return SQLITE_OK. Otherwise,
|
| 791 |
+
** an SQLite error code.
|
| 792 |
+
*/
|
| 793 |
+
static int dbdataDbsize(DbdataCursor *pCsr, const char *zSchema){
|
| 794 |
+
DbdataTable *pTab = (DbdataTable*)pCsr->base.pVtab;
|
| 795 |
+
char *zSql = 0;
|
| 796 |
+
int rc, rc2;
|
| 797 |
+
int nFunc = 0;
|
| 798 |
+
sqlite3_stmt *pStmt = 0;
|
| 799 |
+
|
| 800 |
+
if( (nFunc = dbdataIsFunction(zSchema))>0 ){
|
| 801 |
+
zSql = sqlite3_mprintf("SELECT %.*s(0)", nFunc, zSchema);
|
| 802 |
+
}else{
|
| 803 |
+
zSql = sqlite3_mprintf("PRAGMA %Q.page_count", zSchema);
|
| 804 |
+
}
|
| 805 |
+
if( zSql==0 ) return SQLITE_NOMEM;
|
| 806 |
+
|
| 807 |
+
rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pStmt, 0);
|
| 808 |
+
sqlite3_free(zSql);
|
| 809 |
+
if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
|
| 810 |
+
pCsr->szDb = sqlite3_column_int(pStmt, 0);
|
| 811 |
+
}
|
| 812 |
+
rc2 = sqlite3_finalize(pStmt);
|
| 813 |
+
if( rc==SQLITE_OK ) rc = rc2;
|
| 814 |
+
return rc;
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
/*
|
| 818 |
+
** Attempt to figure out the encoding of the database by retrieving page 1
|
| 819 |
+
** and inspecting the header field. If successful, set the pCsr->enc variable
|
| 820 |
+
** and return SQLITE_OK. Otherwise, return an SQLite error code.
|
| 821 |
+
*/
|
| 822 |
+
static int dbdataGetEncoding(DbdataCursor *pCsr){
|
| 823 |
+
int rc = SQLITE_OK;
|
| 824 |
+
int nPg1 = 0;
|
| 825 |
+
u8 *aPg1 = 0;
|
| 826 |
+
rc = dbdataLoadPage(pCsr, 1, &aPg1, &nPg1);
|
| 827 |
+
if( rc==SQLITE_OK && nPg1>=(56+4) ){
|
| 828 |
+
pCsr->enc = get_uint32(&aPg1[56]);
|
| 829 |
+
}
|
| 830 |
+
sqlite3_free(aPg1);
|
| 831 |
+
return rc;
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
/*
|
| 836 |
+
** xFilter method for sqlite_dbdata and sqlite_dbptr.
|
| 837 |
+
*/
|
| 838 |
+
static int dbdataFilter(
|
| 839 |
+
sqlite3_vtab_cursor *pCursor,
|
| 840 |
+
int idxNum, const char *idxStr,
|
| 841 |
+
int argc, sqlite3_value **argv
|
| 842 |
+
){
|
| 843 |
+
DbdataCursor *pCsr = (DbdataCursor*)pCursor;
|
| 844 |
+
DbdataTable *pTab = (DbdataTable*)pCursor->pVtab;
|
| 845 |
+
int rc = SQLITE_OK;
|
| 846 |
+
const char *zSchema = "main";
|
| 847 |
+
(void)idxStr;
|
| 848 |
+
(void)argc;
|
| 849 |
+
|
| 850 |
+
dbdataResetCursor(pCsr);
|
| 851 |
+
assert( pCsr->iPgno==1 );
|
| 852 |
+
if( idxNum & 0x01 ){
|
| 853 |
+
zSchema = (const char*)sqlite3_value_text(argv[0]);
|
| 854 |
+
if( zSchema==0 ) zSchema = "";
|
| 855 |
+
}
|
| 856 |
+
if( idxNum & 0x02 ){
|
| 857 |
+
pCsr->iPgno = sqlite3_value_int(argv[(idxNum & 0x01)]);
|
| 858 |
+
pCsr->bOnePage = 1;
|
| 859 |
+
}else{
|
| 860 |
+
rc = dbdataDbsize(pCsr, zSchema);
|
| 861 |
+
}
|
| 862 |
+
|
| 863 |
+
if( rc==SQLITE_OK ){
|
| 864 |
+
int nFunc = 0;
|
| 865 |
+
if( pTab->pStmt ){
|
| 866 |
+
pCsr->pStmt = pTab->pStmt;
|
| 867 |
+
pTab->pStmt = 0;
|
| 868 |
+
}else if( (nFunc = dbdataIsFunction(zSchema))>0 ){
|
| 869 |
+
char *zSql = sqlite3_mprintf("SELECT %.*s(?2)", nFunc, zSchema);
|
| 870 |
+
if( zSql==0 ){
|
| 871 |
+
rc = SQLITE_NOMEM;
|
| 872 |
+
}else{
|
| 873 |
+
rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
|
| 874 |
+
sqlite3_free(zSql);
|
| 875 |
+
}
|
| 876 |
+
}else{
|
| 877 |
+
rc = sqlite3_prepare_v2(pTab->db,
|
| 878 |
+
"SELECT data FROM sqlite_dbpage(?) WHERE pgno=?", -1,
|
| 879 |
+
&pCsr->pStmt, 0
|
| 880 |
+
);
|
| 881 |
+
}
|
| 882 |
+
}
|
| 883 |
+
if( rc==SQLITE_OK ){
|
| 884 |
+
rc = sqlite3_bind_text(pCsr->pStmt, 1, zSchema, -1, SQLITE_TRANSIENT);
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
/* Try to determine the encoding of the db by inspecting the header
|
| 888 |
+
** field on page 1. */
|
| 889 |
+
if( rc==SQLITE_OK ){
|
| 890 |
+
rc = dbdataGetEncoding(pCsr);
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
if( rc!=SQLITE_OK ){
|
| 894 |
+
pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db));
|
| 895 |
+
}
|
| 896 |
+
|
| 897 |
+
if( rc==SQLITE_OK ){
|
| 898 |
+
rc = dbdataNext(pCursor);
|
| 899 |
+
}
|
| 900 |
+
return rc;
|
| 901 |
+
}
|
| 902 |
+
|
| 903 |
+
/*
|
| 904 |
+
** Return a column for the sqlite_dbdata or sqlite_dbptr table.
|
| 905 |
+
*/
|
| 906 |
+
static int dbdataColumn(
|
| 907 |
+
sqlite3_vtab_cursor *pCursor,
|
| 908 |
+
sqlite3_context *ctx,
|
| 909 |
+
int i
|
| 910 |
+
){
|
| 911 |
+
DbdataCursor *pCsr = (DbdataCursor*)pCursor;
|
| 912 |
+
DbdataTable *pTab = (DbdataTable*)pCursor->pVtab;
|
| 913 |
+
if( pTab->bPtr ){
|
| 914 |
+
switch( i ){
|
| 915 |
+
case DBPTR_COLUMN_PGNO:
|
| 916 |
+
sqlite3_result_int64(ctx, pCsr->iPgno);
|
| 917 |
+
break;
|
| 918 |
+
case DBPTR_COLUMN_CHILD: {
|
| 919 |
+
int iOff = pCsr->iPgno==1 ? 100 : 0;
|
| 920 |
+
if( pCsr->iCell<0 ){
|
| 921 |
+
iOff += 8;
|
| 922 |
+
}else{
|
| 923 |
+
iOff += 12 + pCsr->iCell*2;
|
| 924 |
+
if( iOff>pCsr->nPage ) return SQLITE_OK;
|
| 925 |
+
iOff = get_uint16(&pCsr->aPage[iOff]);
|
| 926 |
+
}
|
| 927 |
+
if( iOff<=pCsr->nPage ){
|
| 928 |
+
sqlite3_result_int64(ctx, get_uint32(&pCsr->aPage[iOff]));
|
| 929 |
+
}
|
| 930 |
+
break;
|
| 931 |
+
}
|
| 932 |
+
}
|
| 933 |
+
}else{
|
| 934 |
+
switch( i ){
|
| 935 |
+
case DBDATA_COLUMN_PGNO:
|
| 936 |
+
sqlite3_result_int64(ctx, pCsr->iPgno);
|
| 937 |
+
break;
|
| 938 |
+
case DBDATA_COLUMN_CELL:
|
| 939 |
+
sqlite3_result_int(ctx, pCsr->iCell);
|
| 940 |
+
break;
|
| 941 |
+
case DBDATA_COLUMN_FIELD:
|
| 942 |
+
sqlite3_result_int(ctx, pCsr->iField);
|
| 943 |
+
break;
|
| 944 |
+
case DBDATA_COLUMN_VALUE: {
|
| 945 |
+
if( pCsr->iField<0 ){
|
| 946 |
+
sqlite3_result_int64(ctx, pCsr->iIntkey);
|
| 947 |
+
}else if( &pCsr->rec.aBuf[pCsr->nRec] >= pCsr->pPtr ){
|
| 948 |
+
sqlite3_int64 iType;
|
| 949 |
+
dbdataGetVarintU32(pCsr->pHdrPtr, &iType);
|
| 950 |
+
dbdataValue(
|
| 951 |
+
ctx, pCsr->enc, iType, pCsr->pPtr,
|
| 952 |
+
&pCsr->rec.aBuf[pCsr->nRec] - pCsr->pPtr
|
| 953 |
+
);
|
| 954 |
+
}
|
| 955 |
+
break;
|
| 956 |
+
}
|
| 957 |
+
}
|
| 958 |
+
}
|
| 959 |
+
return SQLITE_OK;
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
/*
|
| 963 |
+
** Return the rowid for an sqlite_dbdata or sqlite_dptr table.
|
| 964 |
+
*/
|
| 965 |
+
static int dbdataRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
|
| 966 |
+
DbdataCursor *pCsr = (DbdataCursor*)pCursor;
|
| 967 |
+
*pRowid = pCsr->iRowid;
|
| 968 |
+
return SQLITE_OK;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
|
| 972 |
+
/*
|
| 973 |
+
** Invoke this routine to register the "sqlite_dbdata" virtual table module
|
| 974 |
+
*/
|
| 975 |
+
static int sqlite3DbdataRegister(sqlite3 *db){
|
| 976 |
+
static sqlite3_module dbdata_module = {
|
| 977 |
+
0, /* iVersion */
|
| 978 |
+
0, /* xCreate */
|
| 979 |
+
dbdataConnect, /* xConnect */
|
| 980 |
+
dbdataBestIndex, /* xBestIndex */
|
| 981 |
+
dbdataDisconnect, /* xDisconnect */
|
| 982 |
+
0, /* xDestroy */
|
| 983 |
+
dbdataOpen, /* xOpen - open a cursor */
|
| 984 |
+
dbdataClose, /* xClose - close a cursor */
|
| 985 |
+
dbdataFilter, /* xFilter - configure scan constraints */
|
| 986 |
+
dbdataNext, /* xNext - advance a cursor */
|
| 987 |
+
dbdataEof, /* xEof - check for end of scan */
|
| 988 |
+
dbdataColumn, /* xColumn - read data */
|
| 989 |
+
dbdataRowid, /* xRowid - read data */
|
| 990 |
+
0, /* xUpdate */
|
| 991 |
+
0, /* xBegin */
|
| 992 |
+
0, /* xSync */
|
| 993 |
+
0, /* xCommit */
|
| 994 |
+
0, /* xRollback */
|
| 995 |
+
0, /* xFindMethod */
|
| 996 |
+
0, /* xRename */
|
| 997 |
+
0, /* xSavepoint */
|
| 998 |
+
0, /* xRelease */
|
| 999 |
+
0, /* xRollbackTo */
|
| 1000 |
+
0, /* xShadowName */
|
| 1001 |
+
0 /* xIntegrity */
|
| 1002 |
+
};
|
| 1003 |
+
|
| 1004 |
+
int rc = sqlite3_create_module(db, "sqlite_dbdata", &dbdata_module, 0);
|
| 1005 |
+
if( rc==SQLITE_OK ){
|
| 1006 |
+
rc = sqlite3_create_module(db, "sqlite_dbptr", &dbdata_module, (void*)1);
|
| 1007 |
+
}
|
| 1008 |
+
return rc;
|
| 1009 |
+
}
|
| 1010 |
+
|
| 1011 |
+
int sqlite3_dbdata_init(
|
| 1012 |
+
sqlite3 *db,
|
| 1013 |
+
char **pzErrMsg,
|
| 1014 |
+
const sqlite3_api_routines *pApi
|
| 1015 |
+
){
|
| 1016 |
+
(void)pzErrMsg;
|
| 1017 |
+
return sqlite3DbdataRegister(db);
|
| 1018 |
+
}
|
| 1019 |
+
|
| 1020 |
+
#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recover1.test
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2022 August 28
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
|
| 13 |
+
source [file join [file dirname [info script]] recover_common.tcl]
|
| 14 |
+
set testprefix recover1
|
| 15 |
+
|
| 16 |
+
proc compare_result {db1 db2 sql} {
|
| 17 |
+
set r1 [$db1 eval $sql]
|
| 18 |
+
set r2 [$db2 eval $sql]
|
| 19 |
+
if {$r1 != $r2} {
|
| 20 |
+
puts "r1: $r1"
|
| 21 |
+
puts "r2: $r2"
|
| 22 |
+
error "mismatch for $sql"
|
| 23 |
+
}
|
| 24 |
+
return ""
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
proc compare_dbs {db1 db2} {
|
| 28 |
+
compare_result $db1 $db2 "SELECT sql FROM sqlite_master ORDER BY 1"
|
| 29 |
+
foreach tbl [$db1 eval {SELECT name FROM sqlite_master WHERE type='table'}] {
|
| 30 |
+
compare_result $db1 $db2 "SELECT * FROM $tbl"
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
compare_result $db1 $db2 "PRAGMA page_size"
|
| 34 |
+
compare_result $db1 $db2 "PRAGMA auto_vacuum"
|
| 35 |
+
compare_result $db1 $db2 "PRAGMA encoding"
|
| 36 |
+
compare_result $db1 $db2 "PRAGMA user_version"
|
| 37 |
+
compare_result $db1 $db2 "PRAGMA application_id"
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
proc do_recover_test {tn} {
|
| 41 |
+
forcedelete test.db2
|
| 42 |
+
forcedelete rstate.db
|
| 43 |
+
|
| 44 |
+
uplevel [list do_test $tn.1 {
|
| 45 |
+
set R [sqlite3_recover_init db main test.db2]
|
| 46 |
+
$R config testdb rstate.db
|
| 47 |
+
$R run
|
| 48 |
+
$R finish
|
| 49 |
+
} {}]
|
| 50 |
+
|
| 51 |
+
sqlite3 db2 test.db2
|
| 52 |
+
uplevel [list do_test $tn.2 [list compare_dbs db db2] {}]
|
| 53 |
+
db2 close
|
| 54 |
+
|
| 55 |
+
forcedelete test.db2
|
| 56 |
+
forcedelete rstate.db
|
| 57 |
+
|
| 58 |
+
uplevel [list do_test $tn.3 {
|
| 59 |
+
set ::sqlhook [list]
|
| 60 |
+
set R [sqlite3_recover_init_sql db main my_sql_hook]
|
| 61 |
+
$R config testdb rstate.db
|
| 62 |
+
$R config rowids 1
|
| 63 |
+
$R run
|
| 64 |
+
$R finish
|
| 65 |
+
} {}]
|
| 66 |
+
|
| 67 |
+
sqlite3 db2 test.db2
|
| 68 |
+
execsql [join $::sqlhook ";"] db2
|
| 69 |
+
db2 close
|
| 70 |
+
sqlite3 db2 test.db2
|
| 71 |
+
uplevel [list do_test $tn.4 [list compare_dbs db db2] {}]
|
| 72 |
+
db2 close
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
proc my_sql_hook {sql} {
|
| 76 |
+
lappend ::sqlhook $sql
|
| 77 |
+
return 0
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
do_execsql_test 1.0 {
|
| 81 |
+
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
| 82 |
+
CREATE TABLE t2(a INTEGER PRIMARY KEY, b) WITHOUT ROWID;
|
| 83 |
+
WITH s(i) AS (
|
| 84 |
+
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10
|
| 85 |
+
)
|
| 86 |
+
INSERT INTO t1 SELECT i*2, hex(randomblob(250)) FROM s;
|
| 87 |
+
INSERT INTO t2 SELECT * FROM t1;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
do_recover_test 1
|
| 91 |
+
|
| 92 |
+
do_execsql_test 2.0 {
|
| 93 |
+
ALTER TABLE t1 ADD COLUMN c DEFAULT 'xyz'
|
| 94 |
+
}
|
| 95 |
+
do_recover_test 2
|
| 96 |
+
|
| 97 |
+
do_execsql_test 3.0 {
|
| 98 |
+
CREATE INDEX i1 ON t1(c);
|
| 99 |
+
}
|
| 100 |
+
do_recover_test 3
|
| 101 |
+
|
| 102 |
+
do_execsql_test 4.0 {
|
| 103 |
+
CREATE VIEW v1 AS SELECT * FROM t2;
|
| 104 |
+
}
|
| 105 |
+
do_recover_test 4
|
| 106 |
+
|
| 107 |
+
do_execsql_test 5.0 {
|
| 108 |
+
CREATE UNIQUE INDEX i2 ON t1(c, b);
|
| 109 |
+
}
|
| 110 |
+
do_recover_test 5
|
| 111 |
+
|
| 112 |
+
#--------------------------------------------------------------------------
|
| 113 |
+
#
|
| 114 |
+
reset_db
|
| 115 |
+
do_execsql_test 6.0 {
|
| 116 |
+
CREATE TABLE t1(
|
| 117 |
+
a INTEGER PRIMARY KEY,
|
| 118 |
+
b INT,
|
| 119 |
+
c TEXT,
|
| 120 |
+
d INT GENERATED ALWAYS AS (a*abs(b)) VIRTUAL,
|
| 121 |
+
e TEXT GENERATED ALWAYS AS (substr(c,b,b+1)) STORED,
|
| 122 |
+
f TEXT GENERATED ALWAYS AS (substr(c,b,b+1)) STORED
|
| 123 |
+
);
|
| 124 |
+
|
| 125 |
+
INSERT INTO t1 VALUES(1, 2, 'hello world');
|
| 126 |
+
}
|
| 127 |
+
do_recover_test 6
|
| 128 |
+
|
| 129 |
+
do_execsql_test 7.0 {
|
| 130 |
+
CREATE TABLE t2(i, j GENERATED ALWAYS AS (i+1) STORED, k);
|
| 131 |
+
INSERT INTO t2 VALUES(10, 'ten');
|
| 132 |
+
}
|
| 133 |
+
do_execsql_test 7.1 {
|
| 134 |
+
SELECT * FROM t2
|
| 135 |
+
} {10 11 ten}
|
| 136 |
+
|
| 137 |
+
do_recover_test 7.2
|
| 138 |
+
|
| 139 |
+
#--------------------------------------------------------------------------
|
| 140 |
+
#
|
| 141 |
+
reset_db
|
| 142 |
+
do_execsql_test 8.0 {
|
| 143 |
+
CREATE TABLE x1(a INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
|
| 144 |
+
WITH s(i) AS (
|
| 145 |
+
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<2
|
| 146 |
+
)
|
| 147 |
+
INSERT INTO x1(b, c) SELECT hex(randomblob(100)), hex(randomblob(100)) FROM s;
|
| 148 |
+
|
| 149 |
+
CREATE INDEX x1b ON x1(b);
|
| 150 |
+
CREATE INDEX x1cb ON x1(c, b);
|
| 151 |
+
DELETE FROM x1 WHERE a>50;
|
| 152 |
+
|
| 153 |
+
ANALYZE;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
do_recover_test 8
|
| 157 |
+
|
| 158 |
+
#-------------------------------------------------------------------------
|
| 159 |
+
reset_db
|
| 160 |
+
ifcapable fts5 {
|
| 161 |
+
do_execsql_test 9.1 {
|
| 162 |
+
CREATE VIRTUAL TABLE ft5 USING fts5(a, b);
|
| 163 |
+
INSERT INTO ft5 VALUES('hello', 'world');
|
| 164 |
+
}
|
| 165 |
+
do_recover_test 9
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
#-------------------------------------------------------------------------
|
| 169 |
+
reset_db
|
| 170 |
+
do_execsql_test 10.1 {
|
| 171 |
+
CREATE TABLE x1(a PRIMARY KEY, str TEXT) WITHOUT ROWID;
|
| 172 |
+
INSERT INTO x1 VALUES(1, '
|
| 173 |
+
\nhello\012world(\n0)(\n1)
|
| 174 |
+
');
|
| 175 |
+
INSERT INTO x1 VALUES(2, '
|
| 176 |
+
\nhello
|
| 177 |
+
');
|
| 178 |
+
}
|
| 179 |
+
do_execsql_test 10.2 "
|
| 180 |
+
INSERT INTO x1 VALUES(3, '\012hello there\015world');
|
| 181 |
+
INSERT INTO x1 VALUES(4, '\015hello there\015world');
|
| 182 |
+
"
|
| 183 |
+
do_recover_test 10
|
| 184 |
+
|
| 185 |
+
#-------------------------------------------------------------------------
|
| 186 |
+
reset_db
|
| 187 |
+
do_execsql_test 11.1 {
|
| 188 |
+
PRAGMA page_size = 4096;
|
| 189 |
+
PRAGMA encoding='utf16';
|
| 190 |
+
PRAGMA auto_vacuum = 2;
|
| 191 |
+
PRAGMA user_version = 45;
|
| 192 |
+
PRAGMA application_id = 22;
|
| 193 |
+
|
| 194 |
+
CREATE TABLE u1(u, v);
|
| 195 |
+
INSERT INTO u1 VALUES('edvin marton', 'bond');
|
| 196 |
+
INSERT INTO u1 VALUES(1, 4.0);
|
| 197 |
+
}
|
| 198 |
+
do_execsql_test 11.1a {
|
| 199 |
+
PRAGMA auto_vacuum;
|
| 200 |
+
} {2}
|
| 201 |
+
|
| 202 |
+
do_recover_test 11
|
| 203 |
+
|
| 204 |
+
do_test 12.1 {
|
| 205 |
+
set R [sqlite3_recover_init db "" test.db2]
|
| 206 |
+
$R config lostandfound ""
|
| 207 |
+
$R config invalid xyz
|
| 208 |
+
} {12}
|
| 209 |
+
do_test 12.2 {
|
| 210 |
+
$R run
|
| 211 |
+
$R run
|
| 212 |
+
} {0}
|
| 213 |
+
|
| 214 |
+
do_test 12.3 {
|
| 215 |
+
$R finish
|
| 216 |
+
} {}
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
#-------------------------------------------------------------------------
|
| 221 |
+
reset_db
|
| 222 |
+
file_control_reservebytes db 16
|
| 223 |
+
do_execsql_test 12.1 {
|
| 224 |
+
PRAGMA auto_vacuum = 2;
|
| 225 |
+
PRAGMA user_version = 45;
|
| 226 |
+
PRAGMA application_id = 22;
|
| 227 |
+
|
| 228 |
+
CREATE TABLE u1(u, v);
|
| 229 |
+
CREATE UNIQUE INDEX i1 ON u1(u, v);
|
| 230 |
+
INSERT INTO u1 VALUES(1, 2), (3, 4);
|
| 231 |
+
|
| 232 |
+
CREATE TABLE u2(u, v);
|
| 233 |
+
CREATE UNIQUE INDEX i2 ON u1(u, v);
|
| 234 |
+
INSERT INTO u2 VALUES(hex(randomblob(500)), hex(randomblob(1000)));
|
| 235 |
+
INSERT INTO u2 VALUES(hex(randomblob(500)), hex(randomblob(1000)));
|
| 236 |
+
INSERT INTO u2 VALUES(hex(randomblob(500)), hex(randomblob(1000)));
|
| 237 |
+
INSERT INTO u2 VALUES(hex(randomblob(50000)), hex(randomblob(20000)));
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
do_recover_test 12
|
| 241 |
+
|
| 242 |
+
#-------------------------------------------------------------------------
|
| 243 |
+
reset_db
|
| 244 |
+
sqlite3 db ""
|
| 245 |
+
do_recover_test 13
|
| 246 |
+
|
| 247 |
+
do_execsql_test 14.1 {
|
| 248 |
+
PRAGMA auto_vacuum = 2;
|
| 249 |
+
PRAGMA user_version = 45;
|
| 250 |
+
PRAGMA application_id = 22;
|
| 251 |
+
|
| 252 |
+
CREATE TABLE u1(u, v);
|
| 253 |
+
CREATE UNIQUE INDEX i1 ON u1(u, v);
|
| 254 |
+
INSERT INTO u1 VALUES(1, 2), (3, 4);
|
| 255 |
+
|
| 256 |
+
CREATE TABLE u2(u, v);
|
| 257 |
+
CREATE UNIQUE INDEX i2 ON u1(u, v);
|
| 258 |
+
INSERT INTO u2 VALUES(hex(randomblob(500)), hex(randomblob(1000)));
|
| 259 |
+
INSERT INTO u2 VALUES(hex(randomblob(500)), hex(randomblob(1000)));
|
| 260 |
+
INSERT INTO u2 VALUES(hex(randomblob(500)), hex(randomblob(1000)));
|
| 261 |
+
INSERT INTO u2 VALUES(hex(randomblob(50000)), hex(randomblob(20000)));
|
| 262 |
+
}
|
| 263 |
+
do_recover_test 14
|
| 264 |
+
|
| 265 |
+
#-------------------------------------------------------------------------
|
| 266 |
+
reset_db
|
| 267 |
+
execsql {
|
| 268 |
+
PRAGMA journal_mode=OFF;
|
| 269 |
+
PRAGMA mmap_size=10;
|
| 270 |
+
}
|
| 271 |
+
do_execsql_test 15.1 {
|
| 272 |
+
CREATE TABLE t1(x);
|
| 273 |
+
} {}
|
| 274 |
+
do_recover_test 15
|
| 275 |
+
|
| 276 |
+
#-------------------------------------------------------------------------
|
| 277 |
+
reset_db
|
| 278 |
+
do_test 16.1 {
|
| 279 |
+
execsql { PRAGMA journal_mode = wal }
|
| 280 |
+
execsql {
|
| 281 |
+
CREATE TABLE t1(x);
|
| 282 |
+
INSERT INTO t1 VALUES(1), (2), (3);
|
| 283 |
+
}
|
| 284 |
+
} {}
|
| 285 |
+
do_test 16.2 {
|
| 286 |
+
set R [sqlite3_recover_init db main test.db2]
|
| 287 |
+
$R run
|
| 288 |
+
$R finish
|
| 289 |
+
} {}
|
| 290 |
+
do_execsql_test 16.3 {
|
| 291 |
+
SELECT * FROM t1;
|
| 292 |
+
} {1 2 3}
|
| 293 |
+
|
| 294 |
+
do_execsql_test 16.4 {
|
| 295 |
+
BEGIN;
|
| 296 |
+
SELECT * FROM t1;
|
| 297 |
+
} {1 2 3}
|
| 298 |
+
do_test 16.5 {
|
| 299 |
+
set R [sqlite3_recover_init db main test.db2]
|
| 300 |
+
$R run
|
| 301 |
+
list [catch { $R finish } msg] $msg
|
| 302 |
+
} {1 {cannot start a transaction within a transaction}}
|
| 303 |
+
do_execsql_test 16.6 {
|
| 304 |
+
SELECT * FROM t1;
|
| 305 |
+
} {1 2 3}
|
| 306 |
+
do_execsql_test 16.7 {
|
| 307 |
+
INSERT INTO t1 VALUES(4);
|
| 308 |
+
}
|
| 309 |
+
do_test 16.8 {
|
| 310 |
+
set R [sqlite3_recover_init db main test.db2]
|
| 311 |
+
$R run
|
| 312 |
+
list [catch { $R finish } msg] $msg
|
| 313 |
+
} {1 {cannot start a transaction within a transaction}}
|
| 314 |
+
do_execsql_test 16.9 {
|
| 315 |
+
SELECT * FROM t1;
|
| 316 |
+
COMMIT;
|
| 317 |
+
} {1 2 3 4}
|
| 318 |
+
|
| 319 |
+
#-------------------------------------------------------------------------
|
| 320 |
+
reset_db
|
| 321 |
+
do_execsql_test 17.1 {
|
| 322 |
+
CREATE TABLE t(a, PRIMARY KEY(a, a COLLATE NOCASE)) WITHOUT ROWID;
|
| 323 |
+
INSERT INTO t VALUES('abc');
|
| 324 |
+
INSERT INTO t VALUES('def');
|
| 325 |
+
}
|
| 326 |
+
do_test 17.2 {
|
| 327 |
+
set R [sqlite3_recover_init db main test.db2]
|
| 328 |
+
$R run
|
| 329 |
+
list [catch { $R finish } msg] $msg
|
| 330 |
+
} {0 {}}
|
| 331 |
+
|
| 332 |
+
#-------------------------------------------------------------------------
|
| 333 |
+
foreach enc {utf8 utf16 utf16le utf16be} {
|
| 334 |
+
reset_db
|
| 335 |
+
do_execsql_test 18.$enc.1 {
|
| 336 |
+
PRAGMA auto_vacuum = 0;
|
| 337 |
+
PRAGMA encoding='utf16';
|
| 338 |
+
CREATE TABLE t1(a, b);
|
| 339 |
+
CREATE TABLE t2(a, b);
|
| 340 |
+
INSERT INTO t1 VALUES('abc', 'def');
|
| 341 |
+
PRAGMA writable_schema = 1;
|
| 342 |
+
DELETE FROM sqlite_schema WHERE name='t1';
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
proc my_sql_hook2 {sql} {
|
| 346 |
+
if {[string match "INSERT INTO lostandfound*" $sql]} {
|
| 347 |
+
lappend ::script $sql
|
| 348 |
+
}
|
| 349 |
+
return 0
|
| 350 |
+
}
|
| 351 |
+
do_test 18.$enc.2 {
|
| 352 |
+
set ::script [list]
|
| 353 |
+
set R [sqlite3_recover_init_sql db main my_sql_hook2]
|
| 354 |
+
$R config lostandfound lostandfound
|
| 355 |
+
$R run
|
| 356 |
+
$R finish
|
| 357 |
+
set ::script
|
| 358 |
+
} {{INSERT INTO lostandfound VALUES(2, 2, 2, 1, 'abc', 'def')}}
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
#-------------------------------------------------------------------------
|
| 362 |
+
reset_db
|
| 363 |
+
do_execsql_test 19.0 {
|
| 364 |
+
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT);
|
| 365 |
+
INSERT INTO t1 VALUES(1, 'one');
|
| 366 |
+
INSERT INTO t1 VALUES(2, 'two');
|
| 367 |
+
|
| 368 |
+
ALTER TABLE t1 ADD COLUMN c NOT NULL DEFAULT 13;
|
| 369 |
+
INSERT INTO t1 VALUES(3, 'three', 'hello world');
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
do_recover_test 19.1
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
finish_test
|
| 377 |
+
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recoverclobber.test
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2019 April 23
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# Tests for the SQLITE_RECOVER_ROWIDS option.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
source [file join [file dirname [info script]] recover_common.tcl]
|
| 16 |
+
set testprefix recoverclobber
|
| 17 |
+
|
| 18 |
+
proc recover {db output} {
|
| 19 |
+
set R [sqlite3_recover_init db main test.db2]
|
| 20 |
+
$R run
|
| 21 |
+
$R finish
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
forcedelete test.db2
|
| 25 |
+
do_execsql_test 1.0 {
|
| 26 |
+
ATTACH 'test.db2' AS aux;
|
| 27 |
+
CREATE TABLE aux.x1(x, one);
|
| 28 |
+
INSERT INTO x1 VALUES(1, 'one'), (2, 'two'), (3, 'three');
|
| 29 |
+
|
| 30 |
+
CREATE TABLE t1(a, b);
|
| 31 |
+
INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 3), (4, 4);
|
| 32 |
+
|
| 33 |
+
DETACH aux;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
breakpoint
|
| 37 |
+
do_test 1.1 {
|
| 38 |
+
recover db test.db2
|
| 39 |
+
} {}
|
| 40 |
+
|
| 41 |
+
do_execsql_test 1.2 {
|
| 42 |
+
ATTACH 'test.db2' AS aux;
|
| 43 |
+
SELECT * FROM aux.t1;
|
| 44 |
+
} {1 1 2 2 3 3 4 4}
|
| 45 |
+
|
| 46 |
+
do_catchsql_test 1.3 {
|
| 47 |
+
SELECT * FROM aux.x1;
|
| 48 |
+
} {1 {no such table: aux.x1}}
|
| 49 |
+
|
| 50 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recovercorrupt.test
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2022 August 28
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
|
| 13 |
+
source [file join [file dirname [info script]] recover_common.tcl]
|
| 14 |
+
set testprefix recovercorrupt
|
| 15 |
+
|
| 16 |
+
database_may_be_corrupt
|
| 17 |
+
|
| 18 |
+
do_execsql_test 1.0 {
|
| 19 |
+
PRAGMA page_size = 512;
|
| 20 |
+
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
| 21 |
+
INSERT INTO t1 VALUES(1, 2, 3);
|
| 22 |
+
INSERT INTO t1 VALUES(2, hex(randomblob(100)), randomblob(200));
|
| 23 |
+
CREATE INDEX i1 ON t1(b, c);
|
| 24 |
+
CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
|
| 25 |
+
INSERT INTO t2 VALUES(1, 2, 3);
|
| 26 |
+
INSERT INTO t2 VALUES(2, hex(randomblob(100)), randomblob(200));
|
| 27 |
+
ANALYZE;
|
| 28 |
+
PRAGMA writable_schema = 1;
|
| 29 |
+
DELETE FROM sqlite_schema WHERE name='t2';
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
do_test 1.1 {
|
| 33 |
+
expr [file size test.db]>3072
|
| 34 |
+
} {1}
|
| 35 |
+
|
| 36 |
+
proc toggle_bit {blob bit} {
|
| 37 |
+
set byte [expr {$bit / 8}]
|
| 38 |
+
set bit [expr {$bit & 0x0F}]
|
| 39 |
+
binary scan $blob a${byte}ca* A x B
|
| 40 |
+
set x [expr {$x ^ (1 << $bit)}]
|
| 41 |
+
binary format a*ca* $A $x $B
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
db_save_and_close
|
| 46 |
+
for {set ii 0} {$ii < 10000} {incr ii} {
|
| 47 |
+
db_restore_and_reopen
|
| 48 |
+
db func toggle_bit toggle_bit
|
| 49 |
+
set bitsperpage [expr 512*8]
|
| 50 |
+
|
| 51 |
+
set pg [expr {($ii / $bitsperpage)+1}]
|
| 52 |
+
set byte [expr {$ii % $bitsperpage}]
|
| 53 |
+
db eval {
|
| 54 |
+
UPDATE sqlite_dbpage SET data = toggle_bit(data, $byte) WHERE pgno=$pg
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
set R [sqlite3_recover_init db main test.db2]
|
| 58 |
+
$R config lostandfound lost_and_found
|
| 59 |
+
$R run
|
| 60 |
+
do_test 1.2.$ii {
|
| 61 |
+
$R finish
|
| 62 |
+
} {}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
finish_test
|
| 67 |
+
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recovercorrupt4.test
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2024 May 15
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
|
| 13 |
+
source [file join [file dirname [info script]] recover_common.tcl]
|
| 14 |
+
set testprefix recovercorrupt4
|
| 15 |
+
|
| 16 |
+
database_may_be_corrupt
|
| 17 |
+
|
| 18 |
+
if {[permutation]!="inmemory_journal"} {
|
| 19 |
+
# This test cannot be run with the inmemory_journal permutation, as it
|
| 20 |
+
# must open a truncated, corrupt, database file. With the inmemory_journal
|
| 21 |
+
# permutation, this fails (SQLITE_CORRUPT error) when the [sqlite3] wrapper
|
| 22 |
+
# executes "PRAGMA journal_mode = memory".
|
| 23 |
+
do_execsql_test 1.0 {
|
| 24 |
+
CREATE TABLE rows(indexed INTEGER NOT NULL, unindexed INTEGER NOT NULL, filler BLOB NOT NULL DEFAULT 13);
|
| 25 |
+
-- CREATE UNIQUE INDEX rows_index ON rows(indexed);
|
| 26 |
+
INSERT INTO rows(indexed, unindexed, filler) VALUES(1, 1, x'31');
|
| 27 |
+
INSERT INTO rows(indexed, unindexed, filler) VALUES(2, 2, x'32');
|
| 28 |
+
INSERT INTO rows(indexed, unindexed, filler) VALUES(4, 4, x'34');
|
| 29 |
+
INSERT INTO rows(indexed, unindexed, filler) VALUES(8, 8, randomblob(2048));
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
db close
|
| 33 |
+
|
| 34 |
+
do_test 1.1 {
|
| 35 |
+
set sz [expr [file size test.db] - 1024]
|
| 36 |
+
set fd [open test.db]
|
| 37 |
+
fconfigure $fd -translation binary
|
| 38 |
+
|
| 39 |
+
set data [read $fd $sz]
|
| 40 |
+
set fd2 [open test.db2 w]
|
| 41 |
+
fconfigure $fd2 -translation binary
|
| 42 |
+
puts -nonewline $fd2 $data
|
| 43 |
+
close $fd2
|
| 44 |
+
set {} {}
|
| 45 |
+
} {}
|
| 46 |
+
|
| 47 |
+
do_test 1.2 {
|
| 48 |
+
forcedelete test.db3
|
| 49 |
+
sqlite3 db test.db2
|
| 50 |
+
set R [sqlite3_recover_init db main test.db3]
|
| 51 |
+
$R run
|
| 52 |
+
$R finish
|
| 53 |
+
} {}
|
| 54 |
+
|
| 55 |
+
do_test 1.3 {
|
| 56 |
+
sqlite3 db test.db3
|
| 57 |
+
execsql {
|
| 58 |
+
SELECT indexed, unindexed FROM rows
|
| 59 |
+
}
|
| 60 |
+
} {1 1 2 2 4 4 8 8}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recoverfault2.test
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2022 August 28
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
|
| 13 |
+
source [file join [file dirname [info script]] recover_common.tcl]
|
| 14 |
+
set testprefix recoverfault2
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
#--------------------------------------------------------------------------
|
| 18 |
+
proc compare_result {db1 db2 sql} {
|
| 19 |
+
set r1 [$db1 eval $sql]
|
| 20 |
+
set r2 [$db2 eval $sql]
|
| 21 |
+
if {$r1 != $r2} {
|
| 22 |
+
puts "r1: $r1"
|
| 23 |
+
puts "r2: $r2"
|
| 24 |
+
error "mismatch for $sql"
|
| 25 |
+
}
|
| 26 |
+
return ""
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
proc compare_dbs {db1 db2} {
|
| 30 |
+
compare_result $db1 $db2 "SELECT sql FROM sqlite_master ORDER BY 1"
|
| 31 |
+
foreach tbl [$db1 eval {SELECT name FROM sqlite_master WHERE type='table'}] {
|
| 32 |
+
compare_result $db1 $db2 "SELECT * FROM $tbl"
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
#--------------------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
do_execsql_test 1.0 "
|
| 38 |
+
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
| 39 |
+
INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n');
|
| 40 |
+
"
|
| 41 |
+
faultsim_save_and_close
|
| 42 |
+
|
| 43 |
+
proc my_sql_hook {sql} {
|
| 44 |
+
lappend ::lSql $sql
|
| 45 |
+
return 0
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
do_faultsim_test 1 -faults oom* -prep {
|
| 49 |
+
catch { db2 close }
|
| 50 |
+
faultsim_restore_and_reopen
|
| 51 |
+
set ::lSql [list]
|
| 52 |
+
} -body {
|
| 53 |
+
set R [sqlite3_recover_init_sql db main my_sql_hook]
|
| 54 |
+
$R run
|
| 55 |
+
$R finish
|
| 56 |
+
} -test {
|
| 57 |
+
faultsim_test_result {0 {}} {1 {}}
|
| 58 |
+
if {$testrc==0} {
|
| 59 |
+
sqlite3 db2 ""
|
| 60 |
+
db2 eval [join $::lSql ";"]
|
| 61 |
+
compare_dbs db db2
|
| 62 |
+
db2 close
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
ifcapable utf16 {
|
| 67 |
+
reset_db
|
| 68 |
+
do_execsql_test 2.0 "
|
| 69 |
+
PRAGMA encoding='utf-16';
|
| 70 |
+
CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
|
| 71 |
+
INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n');
|
| 72 |
+
"
|
| 73 |
+
faultsim_save_and_close
|
| 74 |
+
|
| 75 |
+
proc my_sql_hook {sql} {
|
| 76 |
+
lappend ::lSql $sql
|
| 77 |
+
return 0
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
do_faultsim_test 2 -faults oom-t* -prep {
|
| 81 |
+
catch { db2 close }
|
| 82 |
+
faultsim_restore_and_reopen
|
| 83 |
+
set ::lSql [list]
|
| 84 |
+
} -body {
|
| 85 |
+
set R [sqlite3_recover_init_sql db main my_sql_hook]
|
| 86 |
+
$R run
|
| 87 |
+
$R finish
|
| 88 |
+
} -test {
|
| 89 |
+
faultsim_test_result {0 {}} {1 {}}
|
| 90 |
+
if {$testrc==0} {
|
| 91 |
+
sqlite3 db2 ""
|
| 92 |
+
db2 eval [join $::lSql ";"]
|
| 93 |
+
compare_dbs db db2
|
| 94 |
+
db2 close
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
finish_test
|
| 102 |
+
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/recoverrowid.test
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2022 September 07
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# Tests for the SQLITE_RECOVER_ROWIDS option.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
source [file join [file dirname [info script]] recover_common.tcl]
|
| 16 |
+
set testprefix recoverrowid
|
| 17 |
+
|
| 18 |
+
proc recover {db bRowids output} {
|
| 19 |
+
forcedelete $output
|
| 20 |
+
|
| 21 |
+
set R [sqlite3_recover_init db main test.db2]
|
| 22 |
+
$R config rowids $bRowids
|
| 23 |
+
$R run
|
| 24 |
+
$R finish
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
do_execsql_test 1.0 {
|
| 28 |
+
CREATE TABLE t1(a, b);
|
| 29 |
+
INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 3), (4, 4);
|
| 30 |
+
DELETE FROM t1 WHERE a IN (1, 3);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
do_test 1.1 {
|
| 34 |
+
recover db 0 test.db2
|
| 35 |
+
sqlite3 db2 test.db2
|
| 36 |
+
execsql { SELECT rowid, a, b FROM t1 ORDER BY rowid} db2
|
| 37 |
+
} {1 2 2 2 4 4}
|
| 38 |
+
|
| 39 |
+
do_test 1.2 {
|
| 40 |
+
db2 close
|
| 41 |
+
recover db 1 test.db2
|
| 42 |
+
sqlite3 db2 test.db2
|
| 43 |
+
execsql { SELECT rowid, a, b FROM t1 ORDER BY rowid} db2
|
| 44 |
+
} {2 2 2 4 4 4}
|
| 45 |
+
db2 close
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/recover/test_recover.c
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** 2022-08-27
|
| 3 |
+
**
|
| 4 |
+
** The author disclaims copyright to this source code. In place of
|
| 5 |
+
** a legal notice, here is a blessing:
|
| 6 |
+
**
|
| 7 |
+
** May you do good and not evil.
|
| 8 |
+
** May you find forgiveness for yourself and forgive others.
|
| 9 |
+
** May you share freely, never taking more than you give.
|
| 10 |
+
**
|
| 11 |
+
*************************************************************************
|
| 12 |
+
**
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
#include "sqlite3recover.h"
|
| 16 |
+
#include "sqliteInt.h"
|
| 17 |
+
#include "tclsqlite.h"
|
| 18 |
+
#include <assert.h>
|
| 19 |
+
|
| 20 |
+
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
| 21 |
+
|
| 22 |
+
typedef struct TestRecover TestRecover;
|
| 23 |
+
struct TestRecover {
|
| 24 |
+
sqlite3_recover *p;
|
| 25 |
+
Tcl_Interp *interp;
|
| 26 |
+
Tcl_Obj *pScript;
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
static int xSqlCallback(void *pSqlArg, const char *zSql){
|
| 30 |
+
TestRecover *p = (TestRecover*)pSqlArg;
|
| 31 |
+
Tcl_Obj *pEval = 0;
|
| 32 |
+
int res = 0;
|
| 33 |
+
|
| 34 |
+
pEval = Tcl_DuplicateObj(p->pScript);
|
| 35 |
+
Tcl_IncrRefCount(pEval);
|
| 36 |
+
|
| 37 |
+
res = Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewStringObj(zSql, -1));
|
| 38 |
+
if( res==TCL_OK ){
|
| 39 |
+
res = Tcl_EvalObjEx(p->interp, pEval, 0);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
Tcl_DecrRefCount(pEval);
|
| 43 |
+
if( res ){
|
| 44 |
+
Tcl_BackgroundError(p->interp);
|
| 45 |
+
return TCL_ERROR;
|
| 46 |
+
}else{
|
| 47 |
+
Tcl_Obj *pObj = Tcl_GetObjResult(p->interp);
|
| 48 |
+
if( Tcl_GetCharLength(pObj)==0 ){
|
| 49 |
+
res = 0;
|
| 50 |
+
}else if( Tcl_GetIntFromObj(p->interp, pObj, &res) ){
|
| 51 |
+
Tcl_BackgroundError(p->interp);
|
| 52 |
+
return TCL_ERROR;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
return res;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
static int getDbPointer(Tcl_Interp *interp, Tcl_Obj *pObj, sqlite3 **pDb){
|
| 59 |
+
Tcl_CmdInfo info;
|
| 60 |
+
if( 0==Tcl_GetCommandInfo(interp, Tcl_GetString(pObj), &info) ){
|
| 61 |
+
Tcl_AppendResult(interp, "no such handle: ", Tcl_GetString(pObj), 0);
|
| 62 |
+
return TCL_ERROR;
|
| 63 |
+
}
|
| 64 |
+
*pDb = *(sqlite3 **)info.objClientData;
|
| 65 |
+
return TCL_OK;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/*
|
| 69 |
+
** Implementation of the command created by [sqlite3_recover_init]:
|
| 70 |
+
**
|
| 71 |
+
** $cmd config OP ARG
|
| 72 |
+
** $cmd run
|
| 73 |
+
** $cmd errmsg
|
| 74 |
+
** $cmd errcode
|
| 75 |
+
** $cmd finalize
|
| 76 |
+
*/
|
| 77 |
+
static int testRecoverCmd(
|
| 78 |
+
void *clientData,
|
| 79 |
+
Tcl_Interp *interp,
|
| 80 |
+
int objc,
|
| 81 |
+
Tcl_Obj *CONST objv[]
|
| 82 |
+
){
|
| 83 |
+
static struct RecoverSub {
|
| 84 |
+
const char *zSub;
|
| 85 |
+
int nArg;
|
| 86 |
+
const char *zMsg;
|
| 87 |
+
} aSub[] = {
|
| 88 |
+
{ "config", 2, "ARG" }, /* 0 */
|
| 89 |
+
{ "run", 0, "" }, /* 1 */
|
| 90 |
+
{ "errmsg", 0, "" }, /* 2 */
|
| 91 |
+
{ "errcode", 0, "" }, /* 3 */
|
| 92 |
+
{ "finish", 0, "" }, /* 4 */
|
| 93 |
+
{ "step", 0, "" }, /* 5 */
|
| 94 |
+
{ 0 }
|
| 95 |
+
};
|
| 96 |
+
int rc = TCL_OK;
|
| 97 |
+
int iSub = 0;
|
| 98 |
+
TestRecover *pTest = (TestRecover*)clientData;
|
| 99 |
+
|
| 100 |
+
if( objc<2 ){
|
| 101 |
+
Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ...");
|
| 102 |
+
return TCL_ERROR;
|
| 103 |
+
}
|
| 104 |
+
rc = Tcl_GetIndexFromObjStruct(interp,
|
| 105 |
+
objv[1], aSub, sizeof(aSub[0]), "sub-command", 0, &iSub
|
| 106 |
+
);
|
| 107 |
+
if( rc!=TCL_OK ) return rc;
|
| 108 |
+
if( (objc-2)!=aSub[iSub].nArg ){
|
| 109 |
+
Tcl_WrongNumArgs(interp, 2, objv, aSub[iSub].zMsg);
|
| 110 |
+
return TCL_ERROR;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
switch( iSub ){
|
| 114 |
+
case 0: assert( sqlite3_stricmp("config", aSub[iSub].zSub)==0 ); {
|
| 115 |
+
const char *aOp[] = {
|
| 116 |
+
"testdb", /* 0 */
|
| 117 |
+
"lostandfound", /* 1 */
|
| 118 |
+
"freelistcorrupt", /* 2 */
|
| 119 |
+
"rowids", /* 3 */
|
| 120 |
+
"slowindexes", /* 4 */
|
| 121 |
+
"invalid", /* 5 */
|
| 122 |
+
0
|
| 123 |
+
};
|
| 124 |
+
int iOp = 0;
|
| 125 |
+
int res = 0;
|
| 126 |
+
if( Tcl_GetIndexFromObj(interp, objv[2], aOp, "option", 0, &iOp) ){
|
| 127 |
+
return TCL_ERROR;
|
| 128 |
+
}
|
| 129 |
+
switch( iOp ){
|
| 130 |
+
case 0:
|
| 131 |
+
res = sqlite3_recover_config(pTest->p,
|
| 132 |
+
789, (void*)Tcl_GetString(objv[3]) /* MAGIC NUMBER! */
|
| 133 |
+
);
|
| 134 |
+
break;
|
| 135 |
+
case 1: {
|
| 136 |
+
const char *zStr = Tcl_GetString(objv[3]);
|
| 137 |
+
res = sqlite3_recover_config(pTest->p,
|
| 138 |
+
SQLITE_RECOVER_LOST_AND_FOUND, (void*)(zStr[0] ? zStr : 0)
|
| 139 |
+
);
|
| 140 |
+
break;
|
| 141 |
+
}
|
| 142 |
+
case 2: {
|
| 143 |
+
int iVal = 0;
|
| 144 |
+
if( Tcl_GetBooleanFromObj(interp, objv[3], &iVal) ) return TCL_ERROR;
|
| 145 |
+
res = sqlite3_recover_config(pTest->p,
|
| 146 |
+
SQLITE_RECOVER_FREELIST_CORRUPT, (void*)&iVal
|
| 147 |
+
);
|
| 148 |
+
break;
|
| 149 |
+
}
|
| 150 |
+
case 3: {
|
| 151 |
+
int iVal = 0;
|
| 152 |
+
if( Tcl_GetBooleanFromObj(interp, objv[3], &iVal) ) return TCL_ERROR;
|
| 153 |
+
res = sqlite3_recover_config(pTest->p,
|
| 154 |
+
SQLITE_RECOVER_ROWIDS, (void*)&iVal
|
| 155 |
+
);
|
| 156 |
+
break;
|
| 157 |
+
}
|
| 158 |
+
case 4: {
|
| 159 |
+
int iVal = 0;
|
| 160 |
+
if( Tcl_GetBooleanFromObj(interp, objv[3], &iVal) ) return TCL_ERROR;
|
| 161 |
+
res = sqlite3_recover_config(pTest->p,
|
| 162 |
+
SQLITE_RECOVER_SLOWINDEXES, (void*)&iVal
|
| 163 |
+
);
|
| 164 |
+
break;
|
| 165 |
+
}
|
| 166 |
+
case 5: {
|
| 167 |
+
res = sqlite3_recover_config(pTest->p, 12345, 0);
|
| 168 |
+
break;
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
Tcl_SetObjResult(interp, Tcl_NewIntObj(res));
|
| 172 |
+
break;
|
| 173 |
+
}
|
| 174 |
+
case 1: assert( sqlite3_stricmp("run", aSub[iSub].zSub)==0 ); {
|
| 175 |
+
int res = sqlite3_recover_run(pTest->p);
|
| 176 |
+
Tcl_SetObjResult(interp, Tcl_NewIntObj(res));
|
| 177 |
+
break;
|
| 178 |
+
}
|
| 179 |
+
case 2: assert( sqlite3_stricmp("errmsg", aSub[iSub].zSub)==0 ); {
|
| 180 |
+
const char *zErr = sqlite3_recover_errmsg(pTest->p);
|
| 181 |
+
Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1));
|
| 182 |
+
break;
|
| 183 |
+
}
|
| 184 |
+
case 3: assert( sqlite3_stricmp("errcode", aSub[iSub].zSub)==0 ); {
|
| 185 |
+
int errCode = sqlite3_recover_errcode(pTest->p);
|
| 186 |
+
Tcl_SetObjResult(interp, Tcl_NewIntObj(errCode));
|
| 187 |
+
break;
|
| 188 |
+
}
|
| 189 |
+
case 4: assert( sqlite3_stricmp("finish", aSub[iSub].zSub)==0 ); {
|
| 190 |
+
int res = sqlite3_recover_errcode(pTest->p);
|
| 191 |
+
int res2;
|
| 192 |
+
if( res!=SQLITE_OK ){
|
| 193 |
+
const char *zErr = sqlite3_recover_errmsg(pTest->p);
|
| 194 |
+
Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1));
|
| 195 |
+
}
|
| 196 |
+
res2 = sqlite3_recover_finish(pTest->p);
|
| 197 |
+
assert( res2==res );
|
| 198 |
+
if( res ) return TCL_ERROR;
|
| 199 |
+
break;
|
| 200 |
+
}
|
| 201 |
+
case 5: assert( sqlite3_stricmp("step", aSub[iSub].zSub)==0 ); {
|
| 202 |
+
int res = sqlite3_recover_step(pTest->p);
|
| 203 |
+
Tcl_SetObjResult(interp, Tcl_NewIntObj(res));
|
| 204 |
+
break;
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
return TCL_OK;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
/*
|
| 212 |
+
** sqlite3_recover_init DB DBNAME URI
|
| 213 |
+
*/
|
| 214 |
+
static int test_sqlite3_recover_init(
|
| 215 |
+
void *clientData,
|
| 216 |
+
Tcl_Interp *interp,
|
| 217 |
+
int objc,
|
| 218 |
+
Tcl_Obj *CONST objv[]
|
| 219 |
+
){
|
| 220 |
+
static int iTestRecoverCmd = 1;
|
| 221 |
+
|
| 222 |
+
TestRecover *pNew = 0;
|
| 223 |
+
sqlite3 *db = 0;
|
| 224 |
+
const char *zDb = 0;
|
| 225 |
+
const char *zUri = 0;
|
| 226 |
+
char zCmd[128];
|
| 227 |
+
int bSql = clientData ? 1 : 0;
|
| 228 |
+
|
| 229 |
+
if( objc!=4 ){
|
| 230 |
+
const char *zErr = (bSql ? "DB DBNAME SCRIPT" : "DB DBNAME URI");
|
| 231 |
+
Tcl_WrongNumArgs(interp, 1, objv, zErr);
|
| 232 |
+
return TCL_ERROR;
|
| 233 |
+
}
|
| 234 |
+
if( getDbPointer(interp, objv[1], &db) ) return TCL_ERROR;
|
| 235 |
+
zDb = Tcl_GetString(objv[2]);
|
| 236 |
+
if( zDb[0]=='\0' ) zDb = 0;
|
| 237 |
+
|
| 238 |
+
pNew = (TestRecover*)ckalloc(sizeof(TestRecover));
|
| 239 |
+
if( bSql==0 ){
|
| 240 |
+
zUri = Tcl_GetString(objv[3]);
|
| 241 |
+
pNew->p = sqlite3_recover_init(db, zDb, zUri);
|
| 242 |
+
}else{
|
| 243 |
+
pNew->interp = interp;
|
| 244 |
+
pNew->pScript = objv[3];
|
| 245 |
+
Tcl_IncrRefCount(pNew->pScript);
|
| 246 |
+
pNew->p = sqlite3_recover_init_sql(db, zDb, xSqlCallback, (void*)pNew);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
sprintf(zCmd, "sqlite_recover%d", iTestRecoverCmd++);
|
| 250 |
+
Tcl_CreateObjCommand(interp, zCmd, testRecoverCmd, (void*)pNew, 0);
|
| 251 |
+
|
| 252 |
+
Tcl_SetObjResult(interp, Tcl_NewStringObj(zCmd, -1));
|
| 253 |
+
return TCL_OK;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
/*
|
| 257 |
+
** Declaration for public API function in file dbdata.c. This may be called
|
| 258 |
+
** with NULL as the final two arguments to register the sqlite_dbptr and
|
| 259 |
+
** sqlite_dbdata virtual tables with a database handle.
|
| 260 |
+
*/
|
| 261 |
+
#ifdef _WIN32
|
| 262 |
+
__declspec(dllexport)
|
| 263 |
+
#endif
|
| 264 |
+
int sqlite3_dbdata_init(sqlite3*, char**, const sqlite3_api_routines*);
|
| 265 |
+
|
| 266 |
+
/*
|
| 267 |
+
** sqlite3_recover_init DB DBNAME URI
|
| 268 |
+
*/
|
| 269 |
+
static int test_sqlite3_dbdata_init(
|
| 270 |
+
void *clientData,
|
| 271 |
+
Tcl_Interp *interp,
|
| 272 |
+
int objc,
|
| 273 |
+
Tcl_Obj *CONST objv[]
|
| 274 |
+
){
|
| 275 |
+
sqlite3 *db = 0;
|
| 276 |
+
|
| 277 |
+
if( objc!=2 ){
|
| 278 |
+
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
| 279 |
+
return TCL_ERROR;
|
| 280 |
+
}
|
| 281 |
+
if( getDbPointer(interp, objv[1], &db) ) return TCL_ERROR;
|
| 282 |
+
sqlite3_dbdata_init(db, 0, 0);
|
| 283 |
+
|
| 284 |
+
Tcl_ResetResult(interp);
|
| 285 |
+
return TCL_OK;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
| 289 |
+
|
| 290 |
+
int TestRecover_Init(Tcl_Interp *interp){
|
| 291 |
+
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
| 292 |
+
struct Cmd {
|
| 293 |
+
const char *zCmd;
|
| 294 |
+
Tcl_ObjCmdProc *xProc;
|
| 295 |
+
void *pArg;
|
| 296 |
+
} aCmd[] = {
|
| 297 |
+
{ "sqlite3_recover_init", test_sqlite3_recover_init, 0 },
|
| 298 |
+
{ "sqlite3_recover_init_sql", test_sqlite3_recover_init, (void*)1 },
|
| 299 |
+
{ "sqlite3_dbdata_init", test_sqlite3_dbdata_init, (void*)1 },
|
| 300 |
+
};
|
| 301 |
+
int i;
|
| 302 |
+
|
| 303 |
+
for(i=0; i<sizeof(aCmd)/sizeof(struct Cmd); i++){
|
| 304 |
+
struct Cmd *p = &aCmd[i];
|
| 305 |
+
Tcl_CreateObjCommand(interp, p->zCmd, p->xProc, p->pArg, 0);
|
| 306 |
+
}
|
| 307 |
+
#endif
|
| 308 |
+
return TCL_OK;
|
| 309 |
+
}
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree.c
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** 2008 May 26
|
| 3 |
+
**
|
| 4 |
+
** The author disclaims copyright to this source code. In place of
|
| 5 |
+
** a legal notice, here is a blessing:
|
| 6 |
+
**
|
| 7 |
+
** May you do good and not evil.
|
| 8 |
+
** May you find forgiveness for yourself and forgive others.
|
| 9 |
+
** May you share freely, never taking more than you give.
|
| 10 |
+
**
|
| 11 |
+
******************************************************************************
|
| 12 |
+
**
|
| 13 |
+
** This header file is used by programs that want to link against the
|
| 14 |
+
** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
|
| 15 |
+
*/
|
| 16 |
+
#include "sqlite3.h"
|
| 17 |
+
|
| 18 |
+
#ifdef SQLITE_OMIT_VIRTUALTABLE
|
| 19 |
+
# undef SQLITE_ENABLE_RTREE
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
#ifdef __cplusplus
|
| 23 |
+
extern "C" {
|
| 24 |
+
#endif /* __cplusplus */
|
| 25 |
+
|
| 26 |
+
int sqlite3RtreeInit(sqlite3 *db);
|
| 27 |
+
|
| 28 |
+
#ifdef __cplusplus
|
| 29 |
+
} /* extern "C" */
|
| 30 |
+
#endif /* __cplusplus */
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree1.test
ADDED
|
@@ -0,0 +1,818 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2008 Feb 19
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# The focus of this file is testing the r-tree extension.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
set testprefix rtree1
|
| 21 |
+
|
| 22 |
+
# Test plan:
|
| 23 |
+
#
|
| 24 |
+
# rtree-1.*: Creating/destroying r-tree tables.
|
| 25 |
+
# rtree-2.*: Test the implicit constraints - unique rowid and
|
| 26 |
+
# (coord[N]<=coord[N+1]) for even values of N. Also
|
| 27 |
+
# automatic assigning of rowid values.
|
| 28 |
+
# rtree-3.*: Linear scans of r-tree data.
|
| 29 |
+
# rtree-4.*: Test INSERT
|
| 30 |
+
# rtree-5.*: Test DELETE
|
| 31 |
+
# rtree-6.*: Test UPDATE
|
| 32 |
+
# rtree-7.*: Test renaming an r-tree table.
|
| 33 |
+
# rtree-8.*: Test constrained scans of r-tree data.
|
| 34 |
+
#
|
| 35 |
+
# rtree-12.*: Test that on-conflict clauses are supported.
|
| 36 |
+
# rtree-13.*: Test that bug [d2889096e7bdeac6d] has been fixed.
|
| 37 |
+
# rtree-14.*: Test if a non-integer is inserted into the PK column of an
|
| 38 |
+
# r-tree table, it is converted to an integer before being
|
| 39 |
+
# inserted. Also that if a non-numeric is inserted into one
|
| 40 |
+
# of the min/max dimension columns, it is converted to the
|
| 41 |
+
# required type before being inserted.
|
| 42 |
+
# rtree-15.*: Check that DROP TABLE works within a transaction that
|
| 43 |
+
# writes to an r-tree table.
|
| 44 |
+
#
|
| 45 |
+
|
| 46 |
+
ifcapable !rtree {
|
| 47 |
+
finish_test
|
| 48 |
+
return
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
#----------------------------------------------------------------------------
|
| 52 |
+
# Test cases rtree-1.* test CREATE and DROP table statements.
|
| 53 |
+
#
|
| 54 |
+
|
| 55 |
+
# Test creating and dropping an rtree table.
|
| 56 |
+
#
|
| 57 |
+
do_test rtree-1.1.1 {
|
| 58 |
+
execsql { CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2) }
|
| 59 |
+
} {}
|
| 60 |
+
do_test rtree-1.1.2a {
|
| 61 |
+
execsql { SELECT name FROM sqlite_master ORDER BY name }
|
| 62 |
+
} {t1 t1_node t1_parent t1_rowid}
|
| 63 |
+
do_execsql_test rtree-1.1.2b {
|
| 64 |
+
SELECT name FROM pragma_table_list WHERE type='shadow' ORDER BY name;
|
| 65 |
+
} {t1_node t1_parent t1_rowid}
|
| 66 |
+
do_test rtree-1.1.3 {
|
| 67 |
+
execsql {
|
| 68 |
+
DROP TABLE t1;
|
| 69 |
+
SELECT name FROM sqlite_master ORDER BY name;
|
| 70 |
+
}
|
| 71 |
+
} {}
|
| 72 |
+
|
| 73 |
+
# Test creating and dropping an rtree table with an odd name in
|
| 74 |
+
# an attached database.
|
| 75 |
+
#
|
| 76 |
+
do_test rtree-1.2.1 {
|
| 77 |
+
file delete -force test2.db
|
| 78 |
+
execsql {
|
| 79 |
+
ATTACH 'test2.db' AS aux;
|
| 80 |
+
CREATE VIRTUAL TABLE aux.'a" "b' USING rtree(ii, x1, x2, y1, y2);
|
| 81 |
+
}
|
| 82 |
+
} {}
|
| 83 |
+
do_test rtree-1.2.2 {
|
| 84 |
+
execsql { SELECT name FROM sqlite_master ORDER BY name }
|
| 85 |
+
} {}
|
| 86 |
+
do_test rtree-1.2.3 {
|
| 87 |
+
execsql { SELECT name FROM aux.sqlite_master ORDER BY name }
|
| 88 |
+
} {{a" "b} {a" "b_node} {a" "b_parent} {a" "b_rowid}}
|
| 89 |
+
do_test rtree-1.2.4 {
|
| 90 |
+
execsql {
|
| 91 |
+
DROP TABLE aux.'a" "b';
|
| 92 |
+
SELECT name FROM aux.sqlite_master ORDER BY name;
|
| 93 |
+
}
|
| 94 |
+
} {}
|
| 95 |
+
|
| 96 |
+
# Test that the logic for checking the number of columns specified
|
| 97 |
+
# for an rtree table. Acceptable values are odd numbers between 3 and
|
| 98 |
+
# 11, inclusive.
|
| 99 |
+
#
|
| 100 |
+
set cols [list i1 i2 i3 i4 i5 i6 i7 i8 i9 iA iB iC iD iE iF iG iH iI iJ iK]
|
| 101 |
+
for {set nCol 1} {$nCol<[llength $cols]} {incr nCol} {
|
| 102 |
+
|
| 103 |
+
set columns [join [lrange $cols 0 [expr {$nCol-1}]] ,]
|
| 104 |
+
|
| 105 |
+
set X {0 {}}
|
| 106 |
+
if {$nCol%2 == 0} { set X {1 {Wrong number of columns for an rtree table}} }
|
| 107 |
+
if {$nCol < 3} { set X {1 {Too few columns for an rtree table}} }
|
| 108 |
+
if {$nCol > 11} { set X {1 {Too many columns for an rtree table}} }
|
| 109 |
+
|
| 110 |
+
do_test rtree-1.3.$nCol {
|
| 111 |
+
catchsql "
|
| 112 |
+
CREATE VIRTUAL TABLE t1 USING rtree($columns);
|
| 113 |
+
"
|
| 114 |
+
} $X
|
| 115 |
+
|
| 116 |
+
catchsql { DROP TABLE t1 }
|
| 117 |
+
}
|
| 118 |
+
do_catchsql_test rtree-1.3.1000 {
|
| 119 |
+
CREATE VIRTUAL TABLE t1000 USING rtree;
|
| 120 |
+
} {1 {Too few columns for an rtree table}}
|
| 121 |
+
|
| 122 |
+
# Like execsql except display output as integer where that can be
|
| 123 |
+
# done without loss of information.
|
| 124 |
+
#
|
| 125 |
+
proc execsql_intout {sql} {
|
| 126 |
+
set out {}
|
| 127 |
+
foreach term [execsql $sql] {
|
| 128 |
+
regsub {\.0$} $term {} term
|
| 129 |
+
lappend out $term
|
| 130 |
+
}
|
| 131 |
+
return $out
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
# Test that it is possible to open an existing database that contains
|
| 135 |
+
# r-tree tables.
|
| 136 |
+
#
|
| 137 |
+
do_execsql_test rtree-1.4.1a {
|
| 138 |
+
CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2);
|
| 139 |
+
INSERT INTO t1 VALUES(1, 5.0, 10.0);
|
| 140 |
+
SELECT substr(hex(data),1,40) FROM t1_node;
|
| 141 |
+
} {00000001000000000000000140A0000041200000}
|
| 142 |
+
do_execsql_test rtree-1.4.1b {
|
| 143 |
+
INSERT INTO t1 VALUES(2, 15.0, 20.0);
|
| 144 |
+
} {}
|
| 145 |
+
do_test rtree-1.4.2 {
|
| 146 |
+
db close
|
| 147 |
+
sqlite3 db test.db
|
| 148 |
+
execsql_intout { SELECT * FROM t1 ORDER BY ii }
|
| 149 |
+
} {1 5 10 2 15 20}
|
| 150 |
+
do_test rtree-1.4.3 {
|
| 151 |
+
execsql { DROP TABLE t1 }
|
| 152 |
+
} {}
|
| 153 |
+
|
| 154 |
+
# Test that it is possible to create an r-tree table with ridiculous
|
| 155 |
+
# column names.
|
| 156 |
+
#
|
| 157 |
+
do_test rtree-1.5.1 {
|
| 158 |
+
execsql_intout {
|
| 159 |
+
CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim");
|
| 160 |
+
INSERT INTO t1 VALUES(1, 2, 3);
|
| 161 |
+
SELECT "the key", "x dim.", "x2'dim" FROM t1;
|
| 162 |
+
}
|
| 163 |
+
} {1 2 3}
|
| 164 |
+
do_test rtree-1.5.1 {
|
| 165 |
+
execsql { DROP TABLE t1 }
|
| 166 |
+
} {}
|
| 167 |
+
|
| 168 |
+
# Force the r-tree constructor to fail.
|
| 169 |
+
#
|
| 170 |
+
do_test rtree-1.6.1 {
|
| 171 |
+
execsql { CREATE TABLE t1_rowid(a); }
|
| 172 |
+
catchsql {
|
| 173 |
+
CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim");
|
| 174 |
+
}
|
| 175 |
+
} {1 {table "t1_rowid" already exists}}
|
| 176 |
+
do_test rtree-1.6.1 {
|
| 177 |
+
execsql { DROP TABLE t1_rowid }
|
| 178 |
+
} {}
|
| 179 |
+
|
| 180 |
+
#----------------------------------------------------------------------------
|
| 181 |
+
# Test cases rtree-2.*
|
| 182 |
+
#
|
| 183 |
+
do_test rtree-2.1.1 {
|
| 184 |
+
execsql {
|
| 185 |
+
CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
|
| 186 |
+
SELECT * FROM t1;
|
| 187 |
+
}
|
| 188 |
+
} {}
|
| 189 |
+
|
| 190 |
+
do_test rtree-2.1.2 {
|
| 191 |
+
execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) }
|
| 192 |
+
execsql_intout { SELECT * FROM t1 }
|
| 193 |
+
} {1 1 3 2 4}
|
| 194 |
+
do_test rtree-2.1.3 {
|
| 195 |
+
execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) }
|
| 196 |
+
execsql { SELECT rowid FROM t1 ORDER BY rowid }
|
| 197 |
+
} {1 2}
|
| 198 |
+
do_test rtree-2.1.3 {
|
| 199 |
+
execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) }
|
| 200 |
+
execsql { SELECT ii FROM t1 ORDER BY ii }
|
| 201 |
+
} {1 2 3}
|
| 202 |
+
|
| 203 |
+
do_test rtree-2.2.1 {
|
| 204 |
+
catchsql { INSERT INTO t1 VALUES(2, 1, 3, 2, 4) }
|
| 205 |
+
} {1 {UNIQUE constraint failed: t1.ii}}
|
| 206 |
+
do_test rtree-2.2.2 {
|
| 207 |
+
catchsql { INSERT INTO t1 VALUES(4, 1, 3, 4, 2) }
|
| 208 |
+
} {1 {rtree constraint failed: t1.(y1<=y2)}}
|
| 209 |
+
do_test rtree-2.2.3 {
|
| 210 |
+
catchsql { INSERT INTO t1 VALUES(4, 3, 1, 2, 4) }
|
| 211 |
+
} {1 {rtree constraint failed: t1.(x1<=x2)}}
|
| 212 |
+
do_test rtree-2.2.4 {
|
| 213 |
+
execsql { SELECT ii FROM t1 ORDER BY ii }
|
| 214 |
+
} {1 2 3}
|
| 215 |
+
|
| 216 |
+
do_test rtree-2.X {
|
| 217 |
+
execsql { DROP TABLE t1 }
|
| 218 |
+
} {}
|
| 219 |
+
|
| 220 |
+
#----------------------------------------------------------------------------
|
| 221 |
+
# Test cases rtree-3.* test linear scans of r-tree table data. To test
|
| 222 |
+
# this we have to insert some data into an r-tree, but that is not the
|
| 223 |
+
# focus of these tests.
|
| 224 |
+
#
|
| 225 |
+
do_test rtree-3.1.1 {
|
| 226 |
+
execsql {
|
| 227 |
+
CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
|
| 228 |
+
SELECT * FROM t1;
|
| 229 |
+
}
|
| 230 |
+
} {}
|
| 231 |
+
do_test rtree-3.1.2 {
|
| 232 |
+
execsql_intout {
|
| 233 |
+
INSERT INTO t1 VALUES(5, 1, 3, 2, 4);
|
| 234 |
+
SELECT * FROM t1;
|
| 235 |
+
}
|
| 236 |
+
} {5 1 3 2 4}
|
| 237 |
+
do_test rtree-3.1.3 {
|
| 238 |
+
execsql_intout {
|
| 239 |
+
INSERT INTO t1 VALUES(6, 2, 6, 4, 8);
|
| 240 |
+
SELECT * FROM t1;
|
| 241 |
+
}
|
| 242 |
+
} {5 1 3 2 4 6 2 6 4 8}
|
| 243 |
+
|
| 244 |
+
# Test the constraint on the coordinates (c[i]<=c[i+1] where (i%2==0)):
|
| 245 |
+
do_test rtree-3.2.1 {
|
| 246 |
+
catchsql { INSERT INTO t1 VALUES(7, 2, 6, 4, 3) }
|
| 247 |
+
} {1 {rtree constraint failed: t1.(y1<=y2)}}
|
| 248 |
+
do_test rtree-3.2.2 {
|
| 249 |
+
catchsql { INSERT INTO t1 VALUES(8, 2, 6, 3, 3) }
|
| 250 |
+
} {0 {}}
|
| 251 |
+
|
| 252 |
+
#----------------------------------------------------------------------------
|
| 253 |
+
# Test cases rtree-5.* test DELETE operations.
|
| 254 |
+
#
|
| 255 |
+
do_test rtree-5.1.1 {
|
| 256 |
+
execsql { CREATE VIRTUAL TABLE t2 USING rtree(ii, x1, x2) }
|
| 257 |
+
} {}
|
| 258 |
+
do_test rtree-5.1.2 {
|
| 259 |
+
execsql_intout {
|
| 260 |
+
INSERT INTO t2 VALUES(1, 10, 20);
|
| 261 |
+
INSERT INTO t2 VALUES(2, 30, 40);
|
| 262 |
+
INSERT INTO t2 VALUES(3, 50, 60);
|
| 263 |
+
SELECT * FROM t2 ORDER BY ii;
|
| 264 |
+
}
|
| 265 |
+
} {1 10 20 2 30 40 3 50 60}
|
| 266 |
+
do_test rtree-5.1.3 {
|
| 267 |
+
execsql_intout {
|
| 268 |
+
DELETE FROM t2 WHERE ii=2;
|
| 269 |
+
SELECT * FROM t2 ORDER BY ii;
|
| 270 |
+
}
|
| 271 |
+
} {1 10 20 3 50 60}
|
| 272 |
+
do_test rtree-5.1.4 {
|
| 273 |
+
execsql_intout {
|
| 274 |
+
DELETE FROM t2 WHERE ii=1;
|
| 275 |
+
SELECT * FROM t2 ORDER BY ii;
|
| 276 |
+
}
|
| 277 |
+
} {3 50 60}
|
| 278 |
+
do_test rtree-5.1.5 {
|
| 279 |
+
execsql {
|
| 280 |
+
DELETE FROM t2 WHERE ii=3;
|
| 281 |
+
SELECT * FROM t2 ORDER BY ii;
|
| 282 |
+
}
|
| 283 |
+
} {}
|
| 284 |
+
do_test rtree-5.1.6 {
|
| 285 |
+
execsql { SELECT * FROM t2_rowid }
|
| 286 |
+
} {}
|
| 287 |
+
|
| 288 |
+
#----------------------------------------------------------------------------
|
| 289 |
+
# Test cases rtree-5.* test UPDATE operations.
|
| 290 |
+
#
|
| 291 |
+
do_test rtree-6.1.1 {
|
| 292 |
+
execsql { CREATE VIRTUAL TABLE t3 USING rtree(ii, x1, x2, y1, y2) }
|
| 293 |
+
} {}
|
| 294 |
+
do_test rtree-6.1.2 {
|
| 295 |
+
execsql_intout {
|
| 296 |
+
INSERT INTO t3 VALUES(1, 2, 3, 4, 5);
|
| 297 |
+
UPDATE t3 SET x2=5;
|
| 298 |
+
SELECT * FROM t3;
|
| 299 |
+
}
|
| 300 |
+
} {1 2 5 4 5}
|
| 301 |
+
do_test rtree-6.1.3 {
|
| 302 |
+
execsql { UPDATE t3 SET ii = 2 }
|
| 303 |
+
execsql_intout { SELECT * FROM t3 }
|
| 304 |
+
} {2 2 5 4 5}
|
| 305 |
+
|
| 306 |
+
#----------------------------------------------------------------------------
|
| 307 |
+
# Test cases rtree-7.* test rename operations.
|
| 308 |
+
#
|
| 309 |
+
do_test rtree-7.1.1 {
|
| 310 |
+
execsql {
|
| 311 |
+
CREATE VIRTUAL TABLE t4 USING rtree(ii, x1, x2, y1, y2, z1, z2);
|
| 312 |
+
INSERT INTO t4 VALUES(1, 2, 3, 4, 5, 6, 7);
|
| 313 |
+
}
|
| 314 |
+
} {}
|
| 315 |
+
do_test rtree-7.1.2 {
|
| 316 |
+
execsql { ALTER TABLE t4 RENAME TO t5 }
|
| 317 |
+
execsql_intout { SELECT * FROM t5 }
|
| 318 |
+
} {1 2 3 4 5 6 7}
|
| 319 |
+
do_test rtree-7.1.3 {
|
| 320 |
+
db close
|
| 321 |
+
sqlite3 db test.db
|
| 322 |
+
execsql_intout { SELECT * FROM t5 }
|
| 323 |
+
} {1 2 3 4 5 6 7}
|
| 324 |
+
do_test rtree-7.1.4 {
|
| 325 |
+
execsql { ALTER TABLE t5 RENAME TO 'raisara "one"'''}
|
| 326 |
+
execsql_intout { SELECT * FROM "raisara ""one""'" }
|
| 327 |
+
} {1 2 3 4 5 6 7}
|
| 328 |
+
do_test rtree-7.1.5 {
|
| 329 |
+
execsql_intout { SELECT * FROM 'raisara "one"''' }
|
| 330 |
+
} {1 2 3 4 5 6 7}
|
| 331 |
+
do_test rtree-7.1.6 {
|
| 332 |
+
execsql { ALTER TABLE "raisara ""one""'" RENAME TO "abc 123" }
|
| 333 |
+
execsql_intout { SELECT * FROM "abc 123" }
|
| 334 |
+
} {1 2 3 4 5 6 7}
|
| 335 |
+
do_test rtree-7.1.7 {
|
| 336 |
+
db close
|
| 337 |
+
sqlite3 db test.db
|
| 338 |
+
execsql_intout { SELECT * FROM "abc 123" }
|
| 339 |
+
} {1 2 3 4 5 6 7}
|
| 340 |
+
|
| 341 |
+
# An error midway through a rename operation.
|
| 342 |
+
do_test rtree-7.2.1 {
|
| 343 |
+
execsql {
|
| 344 |
+
CREATE TABLE t4_node(a);
|
| 345 |
+
}
|
| 346 |
+
catchsql { ALTER TABLE "abc 123" RENAME TO t4 }
|
| 347 |
+
} {1 {SQL logic error}}
|
| 348 |
+
do_test rtree-7.2.2 {
|
| 349 |
+
execsql_intout { SELECT * FROM "abc 123" }
|
| 350 |
+
} {1 2 3 4 5 6 7}
|
| 351 |
+
do_test rtree-7.2.3 {
|
| 352 |
+
execsql {
|
| 353 |
+
DROP TABLE t4_node;
|
| 354 |
+
CREATE TABLE t4_rowid(a);
|
| 355 |
+
}
|
| 356 |
+
catchsql { ALTER TABLE "abc 123" RENAME TO t4 }
|
| 357 |
+
} {1 {SQL logic error}}
|
| 358 |
+
do_test rtree-7.2.4 {
|
| 359 |
+
db close
|
| 360 |
+
sqlite3 db test.db
|
| 361 |
+
execsql_intout { SELECT * FROM "abc 123" }
|
| 362 |
+
} {1 2 3 4 5 6 7}
|
| 363 |
+
do_test rtree-7.2.5 {
|
| 364 |
+
execsql { DROP TABLE t4_rowid }
|
| 365 |
+
execsql { ALTER TABLE "abc 123" RENAME TO t4 }
|
| 366 |
+
execsql_intout { SELECT * FROM t4 }
|
| 367 |
+
} {1 2 3 4 5 6 7}
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
#----------------------------------------------------------------------------
|
| 371 |
+
# Test cases rtree-8.*
|
| 372 |
+
#
|
| 373 |
+
|
| 374 |
+
# Test that the function to determine if a leaf cell is part of the
|
| 375 |
+
# result set works.
|
| 376 |
+
do_test rtree-8.1.1 {
|
| 377 |
+
execsql {
|
| 378 |
+
CREATE VIRTUAL TABLE t6 USING rtree(ii, x1, x2);
|
| 379 |
+
INSERT INTO t6 VALUES(1, 3, 7);
|
| 380 |
+
INSERT INTO t6 VALUES(2, 4, 6);
|
| 381 |
+
}
|
| 382 |
+
} {}
|
| 383 |
+
do_test rtree-8.1.2 { execsql { SELECT ii FROM t6 WHERE x1>2 } } {1 2}
|
| 384 |
+
do_test rtree-8.1.3 { execsql { SELECT ii FROM t6 WHERE x1>3 } } {2}
|
| 385 |
+
do_test rtree-8.1.4 { execsql { SELECT ii FROM t6 WHERE x1>4 } } {}
|
| 386 |
+
do_test rtree-8.1.5 { execsql { SELECT ii FROM t6 WHERE x1>5 } } {}
|
| 387 |
+
do_test rtree-8.1.6 { execsql { SELECT ii FROM t6 WHERE x1>''} } {}
|
| 388 |
+
do_test rtree-8.1.7 { execsql { SELECT ii FROM t6 WHERE x1>null}} {}
|
| 389 |
+
do_test rtree-8.1.8 { execsql { SELECT ii FROM t6 WHERE x1>'2'} } {1 2}
|
| 390 |
+
do_test rtree-8.1.9 { execsql { SELECT ii FROM t6 WHERE x1>'3'} } {2}
|
| 391 |
+
do_test rtree-8.2.2 { execsql { SELECT ii FROM t6 WHERE x1>=2 } } {1 2}
|
| 392 |
+
do_test rtree-8.2.3 { execsql { SELECT ii FROM t6 WHERE x1>=3 } } {1 2}
|
| 393 |
+
do_test rtree-8.2.4 { execsql { SELECT ii FROM t6 WHERE x1>=4 } } {2}
|
| 394 |
+
do_test rtree-8.2.5 { execsql { SELECT ii FROM t6 WHERE x1>=5 } } {}
|
| 395 |
+
do_test rtree-8.2.6 { execsql { SELECT ii FROM t6 WHERE x1>=''} } {}
|
| 396 |
+
do_test rtree-8.2.7 { execsql { SELECT ii FROM t6 WHERE x1>=null}} {}
|
| 397 |
+
do_test rtree-8.2.8 { execsql { SELECT ii FROM t6 WHERE x1>='4'} } {2}
|
| 398 |
+
do_test rtree-8.2.9 { execsql { SELECT ii FROM t6 WHERE x1>='5'} } {}
|
| 399 |
+
do_test rtree-8.3.2 { execsql { SELECT ii FROM t6 WHERE x1<2 } } {}
|
| 400 |
+
do_test rtree-8.3.3 { execsql { SELECT ii FROM t6 WHERE x1<3 } } {}
|
| 401 |
+
do_test rtree-8.3.4 { execsql { SELECT ii FROM t6 WHERE x1<4 } } {1}
|
| 402 |
+
do_test rtree-8.3.5 { execsql { SELECT ii FROM t6 WHERE x1<5 } } {1 2}
|
| 403 |
+
do_test rtree-8.3.6 { execsql { SELECT ii FROM t6 WHERE x1<''} } {1 2}
|
| 404 |
+
do_test rtree-8.3.7 { execsql { SELECT ii FROM t6 WHERE x1<null}} {}
|
| 405 |
+
do_test rtree-8.3.8 { execsql { SELECT ii FROM t6 WHERE x1<'3'} } {}
|
| 406 |
+
do_test rtree-8.3.9 { execsql { SELECT ii FROM t6 WHERE x1<'4'} } {1}
|
| 407 |
+
do_test rtree-8.4.2 { execsql { SELECT ii FROM t6 WHERE x1<=2 } } {}
|
| 408 |
+
do_test rtree-8.4.3 { execsql { SELECT ii FROM t6 WHERE x1<=3 } } {1}
|
| 409 |
+
do_test rtree-8.4.4 { execsql { SELECT ii FROM t6 WHERE x1<=4 } } {1 2}
|
| 410 |
+
do_test rtree-8.4.5 { execsql { SELECT ii FROM t6 WHERE x1<=5 } } {1 2}
|
| 411 |
+
do_test rtree-8.4.6 { execsql { SELECT ii FROM t6 WHERE x1<=''} } {1 2}
|
| 412 |
+
do_test rtree-8.4.7 { execsql { SELECT ii FROM t6 WHERE x1<=null}} {}
|
| 413 |
+
do_test rtree-8.5.2 { execsql { SELECT ii FROM t6 WHERE x1=2 } } {}
|
| 414 |
+
do_test rtree-8.5.3 { execsql { SELECT ii FROM t6 WHERE x1=3 } } {1}
|
| 415 |
+
do_test rtree-8.5.4 { execsql { SELECT ii FROM t6 WHERE x1=4 } } {2}
|
| 416 |
+
do_test rtree-8.5.5 { execsql { SELECT ii FROM t6 WHERE x1=5 } } {}
|
| 417 |
+
do_test rtree-8.5.6 { execsql { SELECT ii FROM t6 WHERE x1=''} } {}
|
| 418 |
+
do_test rtree-8.5.7 { execsql { SELECT ii FROM t6 WHERE x1=null}} {}
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
#----------------------------------------------------------------------------
|
| 422 |
+
# Test cases rtree-9.*
|
| 423 |
+
#
|
| 424 |
+
# Test that ticket #3549 is fixed.
|
| 425 |
+
do_test rtree-9.1 {
|
| 426 |
+
execsql {
|
| 427 |
+
CREATE TABLE foo (id INTEGER PRIMARY KEY);
|
| 428 |
+
CREATE VIRTUAL TABLE bar USING rtree (id, minX, maxX, minY, maxY);
|
| 429 |
+
INSERT INTO foo VALUES (null);
|
| 430 |
+
INSERT INTO foo SELECT null FROM foo;
|
| 431 |
+
INSERT INTO foo SELECT null FROM foo;
|
| 432 |
+
INSERT INTO foo SELECT null FROM foo;
|
| 433 |
+
INSERT INTO foo SELECT null FROM foo;
|
| 434 |
+
INSERT INTO foo SELECT null FROM foo;
|
| 435 |
+
INSERT INTO foo SELECT null FROM foo;
|
| 436 |
+
DELETE FROM foo WHERE id > 40;
|
| 437 |
+
INSERT INTO bar SELECT NULL, 0, 0, 0, 0 FROM foo;
|
| 438 |
+
}
|
| 439 |
+
} {}
|
| 440 |
+
|
| 441 |
+
# This used to crash.
|
| 442 |
+
do_test rtree-9.2 {
|
| 443 |
+
execsql {
|
| 444 |
+
SELECT count(*) FROM bar b1, bar b2, foo s1 WHERE s1.id = b1.id;
|
| 445 |
+
}
|
| 446 |
+
} {1600}
|
| 447 |
+
do_test rtree-9.3 {
|
| 448 |
+
execsql {
|
| 449 |
+
SELECT count(*) FROM bar b1, bar b2, foo s1
|
| 450 |
+
WHERE b1.minX <= b2.maxX AND s1.id = b1.id;
|
| 451 |
+
}
|
| 452 |
+
} {1600}
|
| 453 |
+
|
| 454 |
+
#-------------------------------------------------------------------------
|
| 455 |
+
# Ticket #3970: Check that the error message is meaningful when a
|
| 456 |
+
# keyword is used as a column name.
|
| 457 |
+
#
|
| 458 |
+
do_test rtree-10.1 {
|
| 459 |
+
catchsql { CREATE VIRTUAL TABLE t7 USING rtree(index, x1, y1, x2, y2) }
|
| 460 |
+
} {1 {near "index": syntax error}}
|
| 461 |
+
|
| 462 |
+
#-------------------------------------------------------------------------
|
| 463 |
+
# Test last_insert_rowid().
|
| 464 |
+
#
|
| 465 |
+
do_test rtree-11.1 {
|
| 466 |
+
execsql {
|
| 467 |
+
CREATE VIRTUAL TABLE t8 USING rtree(idx, x1, x2, y1, y2);
|
| 468 |
+
INSERT INTO t8 VALUES(1, 1.0, 1.0, 2.0, 2.0);
|
| 469 |
+
SELECT last_insert_rowid();
|
| 470 |
+
}
|
| 471 |
+
} {1}
|
| 472 |
+
do_test rtree-11.2 {
|
| 473 |
+
execsql {
|
| 474 |
+
INSERT INTO t8 VALUES(NULL, 1.0, 1.0, 2.0, 2.0);
|
| 475 |
+
SELECT last_insert_rowid();
|
| 476 |
+
}
|
| 477 |
+
} {2}
|
| 478 |
+
|
| 479 |
+
#-------------------------------------------------------------------------
|
| 480 |
+
# Test on-conflict clause handling.
|
| 481 |
+
#
|
| 482 |
+
db_delete_and_reopen
|
| 483 |
+
do_execsql_test 12.0.1 {
|
| 484 |
+
CREATE VIRTUAL TABLE t1 USING rtree_i32(idx, x1, x2, y1, y2);
|
| 485 |
+
INSERT INTO t1 VALUES(1, 1, 2, 3, 4);
|
| 486 |
+
SELECT substr(hex(data),1,56) FROM t1_node;
|
| 487 |
+
} {00000001000000000000000100000001000000020000000300000004}
|
| 488 |
+
do_execsql_test 12.0.2 {
|
| 489 |
+
INSERT INTO t1 VALUES(2, 2, 3, 4, 5);
|
| 490 |
+
INSERT INTO t1 VALUES(3, 3, 4, 5, 6);
|
| 491 |
+
|
| 492 |
+
CREATE TABLE source(idx, x1, x2, y1, y2);
|
| 493 |
+
INSERT INTO source VALUES(5, 8, 8, 8, 8);
|
| 494 |
+
INSERT INTO source VALUES(2, 7, 7, 7, 7);
|
| 495 |
+
}
|
| 496 |
+
db_save_and_close
|
| 497 |
+
foreach {tn sql_template testdata} {
|
| 498 |
+
1 "INSERT %CONF% INTO t1 VALUES(2, 7, 7, 7, 7)" {
|
| 499 |
+
ROLLBACK 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
|
| 500 |
+
ABORT 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 501 |
+
IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 502 |
+
FAIL 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 503 |
+
REPLACE 0 0 {1 1 2 3 4 2 7 7 7 7 3 3 4 5 6 4 4 5 6 7}
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
2 "INSERT %CONF% INTO t1 SELECT * FROM source" {
|
| 507 |
+
ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
|
| 508 |
+
ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 509 |
+
IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8}
|
| 510 |
+
FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8}
|
| 511 |
+
REPLACE 1 0 {1 1 2 3 4 2 7 7 7 7 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8}
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
3 "UPDATE %CONF% t1 SET idx = 2 WHERE idx = 4" {
|
| 515 |
+
ROLLBACK 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
|
| 516 |
+
ABORT 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 517 |
+
IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 518 |
+
FAIL 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 519 |
+
REPLACE 0 0 {1 1 2 3 4 2 4 5 6 7 3 3 4 5 6}
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
3 "UPDATE %CONF% t1 SET idx = ((idx+1)%5)+1 WHERE idx > 2" {
|
| 523 |
+
ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
|
| 524 |
+
ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 525 |
+
IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 4 4 5 6 7 5 3 4 5 6}
|
| 526 |
+
FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 4 4 5 6 7 5 3 4 5 6}
|
| 527 |
+
REPLACE 1 0 {1 4 5 6 7 2 2 3 4 5 5 3 4 5 6}
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
4 "INSERT %CONF% INTO t1 VALUES(2, 7, 6, 7, 7)" {
|
| 531 |
+
ROLLBACK 0 2 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6}
|
| 532 |
+
ABORT 0 2 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 533 |
+
IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 534 |
+
FAIL 0 2 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 535 |
+
REPLACE 0 2 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7}
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
} {
|
| 539 |
+
foreach {mode uses error data} $testdata {
|
| 540 |
+
db_restore_and_reopen
|
| 541 |
+
|
| 542 |
+
set sql [string map [list %CONF% "OR $mode"] $sql_template]
|
| 543 |
+
set testname "12.$tn.[string tolower $mode]"
|
| 544 |
+
|
| 545 |
+
execsql {
|
| 546 |
+
BEGIN;
|
| 547 |
+
INSERT INTO t1 VALUES(4, 4, 5, 6, 7);
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
set res(0) {0 {}}
|
| 551 |
+
set res(1) {1 {UNIQUE constraint failed: t1.idx}}
|
| 552 |
+
set res(2) {1 {rtree constraint failed: t1.(x1<=x2)}}
|
| 553 |
+
|
| 554 |
+
do_catchsql_test $testname.1 $sql $res($error)
|
| 555 |
+
do_test $testname.2 [list sql_uses_stmt db $sql] $uses
|
| 556 |
+
do_execsql_test $testname.3 { SELECT * FROM t1 ORDER BY idx } $data
|
| 557 |
+
|
| 558 |
+
do_rtree_integrity_test $testname.4 t1
|
| 559 |
+
db close
|
| 560 |
+
}
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
#-------------------------------------------------------------------------
|
| 564 |
+
# Test that bug [d2889096e7bdeac6d] has been fixed.
|
| 565 |
+
#
|
| 566 |
+
reset_db
|
| 567 |
+
do_execsql_test 13.1 {
|
| 568 |
+
CREATE VIRTUAL TABLE t9 USING rtree(id, xmin, xmax);
|
| 569 |
+
INSERT INTO t9 VALUES(1,0,0);
|
| 570 |
+
INSERT INTO t9 VALUES(2,0,0);
|
| 571 |
+
SELECT * FROM t9 WHERE id IN (1, 2);
|
| 572 |
+
} {1 0.0 0.0 2 0.0 0.0}
|
| 573 |
+
|
| 574 |
+
do_execsql_test 13.2 {
|
| 575 |
+
WITH r(x) AS (
|
| 576 |
+
SELECT 1 UNION ALL
|
| 577 |
+
SELECT 2 UNION ALL
|
| 578 |
+
SELECT 3
|
| 579 |
+
)
|
| 580 |
+
SELECT * FROM r CROSS JOIN t9 WHERE id=x;
|
| 581 |
+
} {1 1 0.0 0.0 2 2 0.0 0.0}
|
| 582 |
+
|
| 583 |
+
#-------------------------------------------------------------------------
|
| 584 |
+
# Test if a non-integer is inserted into the PK column of an r-tree
|
| 585 |
+
# table, it is converted to an integer before being inserted. Also
|
| 586 |
+
# that if a non-numeric is inserted into one of the min/max dimension
|
| 587 |
+
# columns, it is converted to the required type before being inserted.
|
| 588 |
+
#
|
| 589 |
+
do_execsql_test 14.1 {
|
| 590 |
+
CREATE VIRTUAL TABLE t10 USING rtree(ii, x1, x2);
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
do_execsql_test 14.2 {
|
| 594 |
+
INSERT INTO t10 VALUES(NULL, 1, 2);
|
| 595 |
+
INSERT INTO t10 VALUES(NULL, 2, 3);
|
| 596 |
+
INSERT INTO t10 VALUES('4xxx', 3, 4);
|
| 597 |
+
INSERT INTO t10 VALUES(5.0, 4, 5);
|
| 598 |
+
INSERT INTO t10 VALUES(6.4, 5, 6);
|
| 599 |
+
}
|
| 600 |
+
do_execsql_test 14.3 {
|
| 601 |
+
SELECT * FROM t10;
|
| 602 |
+
} {
|
| 603 |
+
1 1.0 2.0 2 2.0 3.0 4 3.0 4.0 5 4.0 5.0 6 5.0 6.0
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
do_execsql_test 14.4 {
|
| 607 |
+
DELETE FROM t10;
|
| 608 |
+
INSERT INTO t10 VALUES(1, 'one', 'two');
|
| 609 |
+
INSERT INTO t10 VALUES(2, '52xyz', '81...');
|
| 610 |
+
}
|
| 611 |
+
do_execsql_test 14.5 {
|
| 612 |
+
SELECT * FROM t10;
|
| 613 |
+
} {
|
| 614 |
+
1 0.0 0.0
|
| 615 |
+
2 52.0 81.0
|
| 616 |
+
}
|
| 617 |
+
do_execsql_test 14.6 {
|
| 618 |
+
INSERT INTO t10 VALUES(0,10,20);
|
| 619 |
+
SELECT * FROM t10 WHERE ii=NULL;
|
| 620 |
+
} {}
|
| 621 |
+
do_execsql_test 14.7 {
|
| 622 |
+
SELECT * FROM t10 WHERE ii='xyz';
|
| 623 |
+
} {}
|
| 624 |
+
do_execsql_test 14.8 {
|
| 625 |
+
SELECT * FROM t10 WHERE ii='0.0';
|
| 626 |
+
} {0 10.0 20.0}
|
| 627 |
+
do_execsql_test 14.9 {
|
| 628 |
+
SELECT * FROM t10 WHERE ii=0.0;
|
| 629 |
+
} {0 10.0 20.0}
|
| 630 |
+
|
| 631 |
+
|
| 632 |
+
do_execsql_test 14.104 {
|
| 633 |
+
DROP TABLE t10;
|
| 634 |
+
CREATE VIRTUAL TABLE t10 USING rtree_i32(ii, x1, x2);
|
| 635 |
+
INSERT INTO t10 VALUES(1, 'one', 'two');
|
| 636 |
+
INSERT INTO t10 VALUES(2, '52xyz', '81...');
|
| 637 |
+
INSERT INTO t10 VALUES(3, 42.3, 49.9);
|
| 638 |
+
}
|
| 639 |
+
do_execsql_test 14.105 {
|
| 640 |
+
SELECT * FROM t10;
|
| 641 |
+
} {
|
| 642 |
+
1 0 0
|
| 643 |
+
2 52 81
|
| 644 |
+
3 42 49
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
#-------------------------------------------------------------------------
|
| 648 |
+
#
|
| 649 |
+
do_execsql_test 15.0 {
|
| 650 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, x1,x2, y1,y2);
|
| 651 |
+
CREATE TEMP TABLE t13(a, b, c);
|
| 652 |
+
}
|
| 653 |
+
do_execsql_test 15.1 {
|
| 654 |
+
BEGIN;
|
| 655 |
+
INSERT INTO rt VALUES(1,2,3,4,5);
|
| 656 |
+
}
|
| 657 |
+
do_execsql_test 15.2 {
|
| 658 |
+
DROP TABLE t13;
|
| 659 |
+
COMMIT;
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
# Test cases for the new auxiliary columns feature
|
| 663 |
+
#
|
| 664 |
+
do_catchsql_test 16.100 {
|
| 665 |
+
CREATE VIRTUAL TABLE t16 USING rtree(id,x0,x1,y0,+aux1,x1);
|
| 666 |
+
} {1 {Auxiliary rtree columns must be last}}
|
| 667 |
+
do_test 16.110 {
|
| 668 |
+
set sql {
|
| 669 |
+
CREATE VIRTUAL TABLE t16 USING rtree(
|
| 670 |
+
id, x00, x01, x10, x11, x20, x21, x30, x31, x40, x41
|
| 671 |
+
}
|
| 672 |
+
for {set i 12} {$i<=100} {incr i} {
|
| 673 |
+
append sql ", +a$i"
|
| 674 |
+
}
|
| 675 |
+
append sql ");"
|
| 676 |
+
execsql $sql
|
| 677 |
+
} {}
|
| 678 |
+
do_test 16.120 {
|
| 679 |
+
set sql {
|
| 680 |
+
CREATE VIRTUAL TABLE t16b USING rtree(
|
| 681 |
+
id, x00, x01, x10, x11, x20, x21, x30, x31, x40, x41
|
| 682 |
+
}
|
| 683 |
+
for {set i 12} {$i<=101} {incr i} {
|
| 684 |
+
append sql ", +a$i"
|
| 685 |
+
}
|
| 686 |
+
append sql ");"
|
| 687 |
+
catchsql $sql
|
| 688 |
+
} {1 {Too many columns for an rtree table}}
|
| 689 |
+
|
| 690 |
+
do_execsql_test 16.130 {
|
| 691 |
+
DROP TABLE IF EXISTS rt1;
|
| 692 |
+
CREATE VIRTUAL TABLE rt1 USING rtree(id, x1, x2, +aux);
|
| 693 |
+
INSERT INTO rt1 VALUES(1, 1, 2, 'aux1');
|
| 694 |
+
INSERT INTO rt1 VALUES(2, 2, 3, 'aux2');
|
| 695 |
+
INSERT INTO rt1 VALUES(3, 3, 4, 'aux3');
|
| 696 |
+
INSERT INTO rt1 VALUES(4, 4, 5, 'aux4');
|
| 697 |
+
SELECT * FROM rt1 WHERE id IN (1, 2, 3, 4);
|
| 698 |
+
} {1 1.0 2.0 aux1 2 2.0 3.0 aux2 3 3.0 4.0 aux3 4 4.0 5.0 aux4}
|
| 699 |
+
|
| 700 |
+
reset_db
|
| 701 |
+
do_execsql_test 17.0 {
|
| 702 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id, x1 PRIMARY KEY, x2, y1, y2);
|
| 703 |
+
CREATE VIRTUAL TABLE t2 USING rtree(id, x1, x2, y1, y2 UNIQUE);
|
| 704 |
+
}
|
| 705 |
+
do_execsql_test 17.1 {
|
| 706 |
+
REINDEX t1;
|
| 707 |
+
REINDEX t2;
|
| 708 |
+
} {}
|
| 709 |
+
|
| 710 |
+
do_execsql_test 17.2 {
|
| 711 |
+
REINDEX;
|
| 712 |
+
} {}
|
| 713 |
+
|
| 714 |
+
reset_db
|
| 715 |
+
do_execsql_test 18.0 {
|
| 716 |
+
CREATE VIRTUAL TABLE rt0 USING rtree(c0, c1, c2);
|
| 717 |
+
INSERT INTO rt0(c0,c1,c2) VALUES(9,2,3);
|
| 718 |
+
SELECT c0 FROM rt0 WHERE rt0.c1 > '-1';
|
| 719 |
+
SELECT rt0.c1 > '-1' FROM rt0;
|
| 720 |
+
} {9 1}
|
| 721 |
+
|
| 722 |
+
expand_all_sql db
|
| 723 |
+
|
| 724 |
+
# 2020-02-28 ticket e63b4d1a65546532
|
| 725 |
+
reset_db
|
| 726 |
+
do_execsql_test 19.0 {
|
| 727 |
+
CREATE VIRTUAL TABLE rt0 USING rtree(a,b,c);
|
| 728 |
+
INSERT INTO rt0(a,b,c) VALUES(0,0.0,0.0);
|
| 729 |
+
CREATE VIEW v0(x) AS SELECT DISTINCT rt0.b FROM rt0;
|
| 730 |
+
SELECT v0.x FROM v0, rt0;
|
| 731 |
+
} {0.0}
|
| 732 |
+
do_execsql_test 19.1 {
|
| 733 |
+
SELECT v0.x FROM v0, rt0 WHERE v0.x = rt0.b;
|
| 734 |
+
} {0.0}
|
| 735 |
+
|
| 736 |
+
# 2022-06-20 https://sqlite.org/forum/forumpost/57bdf2217d
|
| 737 |
+
#
|
| 738 |
+
reset_db
|
| 739 |
+
do_execsql_test 20.0 {
|
| 740 |
+
CREATE VIRTUAL TABLE rt0 USING rtree(id, x0, x1);
|
| 741 |
+
CREATE TABLE t0(a INT);
|
| 742 |
+
CREATE TABLE t1(b INT);
|
| 743 |
+
INSERT INTO rt0 VALUES(0, 0, 0);
|
| 744 |
+
}
|
| 745 |
+
do_catchsql_test 20.1 {
|
| 746 |
+
SELECT * FROM t1 JOIN t0 ON x0>a RIGHT JOIN rt0 ON true WHERE +x0 = 0;
|
| 747 |
+
} {1 {ON clause references tables to its right}}
|
| 748 |
+
do_catchsql_test 20.2 {
|
| 749 |
+
SELECT * FROM t1 JOIN t0 ON x0>a RIGHT JOIN rt0 ON true WHERE x0 = 0;
|
| 750 |
+
} {1 {ON clause references tables to its right}}
|
| 751 |
+
db null -
|
| 752 |
+
do_execsql_test 20.3 {
|
| 753 |
+
SELECT * FROM t1 JOIN t0 ON true RIGHT JOIN rt0 ON x0>a WHERE +x0 = 0;
|
| 754 |
+
} {- - 0 0.0 0.0}
|
| 755 |
+
do_execsql_test 20.4 {
|
| 756 |
+
SELECT * FROM t1 JOIN t0 ON true RIGHT JOIN rt0 ON x0>a WHERE x0 = 0;
|
| 757 |
+
} {- - 0 0.0 0.0}
|
| 758 |
+
|
| 759 |
+
# 2023-05-19 https://sqlite.org/forum/forumpost/da61c4a1b5b4af19
|
| 760 |
+
# Do not omit constraints that involve equality comparisons of
|
| 761 |
+
# floating-point values.
|
| 762 |
+
#
|
| 763 |
+
reset_db
|
| 764 |
+
do_execsql_test 21.0 {
|
| 765 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id, x0, x1);
|
| 766 |
+
INSERT INTO t1 VALUES(0, 1, 9223372036854775807);
|
| 767 |
+
SELECT count(*) FROM t1 WHERE x1=9223372036854775807;
|
| 768 |
+
} {0}
|
| 769 |
+
do_execsql_test 21.1 {
|
| 770 |
+
SELECT x1=9223372036854775807 FROM t1;
|
| 771 |
+
} {0}
|
| 772 |
+
|
| 773 |
+
# 2023-05-22 https://sqlite.org/forum/forumpost/da70ee0d0d
|
| 774 |
+
# Round-off error associated with using large integer constraints on
|
| 775 |
+
# a rtree search.
|
| 776 |
+
#
|
| 777 |
+
if {$tcl_platform(machine)!="i686" || $tcl_platform(os)!="Linux"} {
|
| 778 |
+
reset_db
|
| 779 |
+
do_execsql_test 22.0 {
|
| 780 |
+
CREATE VIRTUAL TABLE t1 USING rtree ( id, x0, x1 );
|
| 781 |
+
INSERT INTO t1 VALUES (123, 9223372036854775799, 9223372036854775800);
|
| 782 |
+
SELECT id FROM t1 WHERE x0 > 9223372036854775807;
|
| 783 |
+
} {123}
|
| 784 |
+
do_execsql_test 22.1 {
|
| 785 |
+
SELECT id, x0 > 9223372036854775807 AS 'a0' FROM t1;
|
| 786 |
+
} {123 1}
|
| 787 |
+
}
|
| 788 |
+
|
| 789 |
+
# 2023-10-14 dbsqlfuzz --sql-fuzz find. rtreecheck() should not call
|
| 790 |
+
# BEGIN/COMMIT because that causes problems with statement transactions,
|
| 791 |
+
# and it is unnecessary.
|
| 792 |
+
#
|
| 793 |
+
reset_db
|
| 794 |
+
do_test 23.0 {
|
| 795 |
+
db eval {CREATE TABLE t1(a,b,c);}
|
| 796 |
+
catch {db eval {CREATE TABLE t2 AS SELECT rtreecheck('t1') AS y;}}
|
| 797 |
+
db eval {PRAGMA integrity_check;}
|
| 798 |
+
} {ok}
|
| 799 |
+
|
| 800 |
+
reset_db
|
| 801 |
+
do_execsql_test 24.0 {
|
| 802 |
+
CREATE VIRTUAL TABLE rt1 USING rtree_i32(rid, c1, c2);
|
| 803 |
+
INSERT INTO rt1(rid, c1, c2) VALUES (9223372036854775807, 10, 18);
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
do_execsql_test 24.1 {
|
| 807 |
+
SELECT (rid = (CAST (9223372036854775807 AS REAL)))
|
| 808 |
+
FROM rt1 WHERE
|
| 809 |
+
(rid = (CAST (9223372036854775807 AS REAL)));
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
do_execsql_test 24.2 {
|
| 813 |
+
DELETE FROM rt1;
|
| 814 |
+
INSERT INTO rt1(rid, c1, c2) VALUES(1,2,3);
|
| 815 |
+
SELECT * FROM rt1 WHERE rid=1.005;
|
| 816 |
+
} {}
|
| 817 |
+
|
| 818 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree4.test
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2008 May 23
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# Randomized test cases for the rtree extension.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
|
| 21 |
+
ifcapable !rtree {
|
| 22 |
+
finish_test
|
| 23 |
+
return
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
set ::NROW 2500
|
| 27 |
+
if {[info exists G(isquick)] && $G(isquick)} {
|
| 28 |
+
set ::NROW 250
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
ifcapable !rtree_int_only {
|
| 32 |
+
# Return a floating point number between -X and X.
|
| 33 |
+
#
|
| 34 |
+
proc rand {X} {
|
| 35 |
+
return [expr {int((rand()-0.5)*1024.0*$X)/512.0}]
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
# Return a positive floating point number less than or equal to X
|
| 39 |
+
#
|
| 40 |
+
proc randincr {X} {
|
| 41 |
+
while 1 {
|
| 42 |
+
set r [expr {int(rand()*$X*32.0)/32.0}]
|
| 43 |
+
if {$r>0.0} {return $r}
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
} else {
|
| 47 |
+
# For rtree_int_only, return an number between -X and X.
|
| 48 |
+
#
|
| 49 |
+
proc rand {X} {
|
| 50 |
+
return [expr {int((rand()-0.5)*2*$X)}]
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
# Return a positive integer less than or equal to X
|
| 54 |
+
#
|
| 55 |
+
proc randincr {X} {
|
| 56 |
+
while 1 {
|
| 57 |
+
set r [expr {int(rand()*$X)+1}]
|
| 58 |
+
if {$r>0} {return $r}
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
# Scramble the $inlist into a random order.
|
| 64 |
+
#
|
| 65 |
+
proc scramble {inlist} {
|
| 66 |
+
set y {}
|
| 67 |
+
foreach x $inlist {
|
| 68 |
+
lappend y [list [expr {rand()}] $x]
|
| 69 |
+
}
|
| 70 |
+
set y [lsort $y]
|
| 71 |
+
set outlist {}
|
| 72 |
+
foreach x $y {
|
| 73 |
+
lappend outlist [lindex $x 1]
|
| 74 |
+
}
|
| 75 |
+
return $outlist
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
# Always use the same random seed so that the sequence of tests
|
| 79 |
+
# is repeatable.
|
| 80 |
+
#
|
| 81 |
+
expr {srand(1234)}
|
| 82 |
+
|
| 83 |
+
# Run these tests for all number of dimensions between 1 and 5.
|
| 84 |
+
#
|
| 85 |
+
for {set nDim 1} {$nDim<=5} {incr nDim} {
|
| 86 |
+
|
| 87 |
+
# Construct an rtree virtual table and an ordinary btree table
|
| 88 |
+
# to mirror it. The ordinary table should be much slower (since
|
| 89 |
+
# it has to do a full table scan) but should give the exact same
|
| 90 |
+
# answers.
|
| 91 |
+
#
|
| 92 |
+
do_test rtree4-$nDim.1 {
|
| 93 |
+
set clist {}
|
| 94 |
+
set cklist {}
|
| 95 |
+
for {set i 0} {$i<$nDim} {incr i} {
|
| 96 |
+
lappend clist mn$i mx$i
|
| 97 |
+
lappend cklist "mn$i<mx$i"
|
| 98 |
+
}
|
| 99 |
+
db eval "DROP TABLE IF EXISTS rx"
|
| 100 |
+
db eval "DROP TABLE IF EXISTS bx"
|
| 101 |
+
db eval "CREATE VIRTUAL TABLE rx USING rtree(id, [join $clist ,])"
|
| 102 |
+
db eval "CREATE TABLE bx(id INTEGER PRIMARY KEY,\
|
| 103 |
+
[join $clist ,], CHECK( [join $cklist { AND }] ))"
|
| 104 |
+
} {}
|
| 105 |
+
|
| 106 |
+
# Do many insertions of small objects. Do both overlapping and
|
| 107 |
+
# contained-within queries after each insert to verify that all
|
| 108 |
+
# is well.
|
| 109 |
+
#
|
| 110 |
+
unset -nocomplain where
|
| 111 |
+
for {set i 1} {$i<$::NROW} {incr i} {
|
| 112 |
+
# Do a random insert
|
| 113 |
+
#
|
| 114 |
+
do_test rtree4-$nDim.2.$i.1 {
|
| 115 |
+
set vlist {}
|
| 116 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 117 |
+
set mn [rand 10000]
|
| 118 |
+
set mx [expr {$mn+[randincr 50]}]
|
| 119 |
+
lappend vlist $mn $mx
|
| 120 |
+
}
|
| 121 |
+
db eval "INSERT INTO rx VALUES(NULL, [join $vlist ,])"
|
| 122 |
+
db eval "INSERT INTO bx VALUES(NULL, [join $vlist ,])"
|
| 123 |
+
} {}
|
| 124 |
+
|
| 125 |
+
# Do a contained-in query on all dimensions
|
| 126 |
+
#
|
| 127 |
+
set where {}
|
| 128 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 129 |
+
set mn [rand 10000]
|
| 130 |
+
set mx [expr {$mn+[randincr 500]}]
|
| 131 |
+
lappend where mn$j>=$mn mx$j<=$mx
|
| 132 |
+
}
|
| 133 |
+
set where "WHERE [join $where { AND }]"
|
| 134 |
+
do_test rtree4-$nDim.2.$i.2 {
|
| 135 |
+
list $where [db eval "SELECT id FROM rx $where ORDER BY id"]
|
| 136 |
+
} [list $where [db eval "SELECT id FROM bx $where ORDER BY id"]]
|
| 137 |
+
|
| 138 |
+
# Do an overlaps query on all dimensions
|
| 139 |
+
#
|
| 140 |
+
set where {}
|
| 141 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 142 |
+
set mn [rand 10000]
|
| 143 |
+
set mx [expr {$mn+[randincr 500]}]
|
| 144 |
+
lappend where mx$j>=$mn mn$j<=$mx
|
| 145 |
+
}
|
| 146 |
+
set where "WHERE [join $where { AND }]"
|
| 147 |
+
do_test rtree4-$nDim.2.$i.3 {
|
| 148 |
+
list $where [db eval "SELECT id FROM rx $where ORDER BY id"]
|
| 149 |
+
} [list $where [db eval "SELECT id FROM bx $where ORDER BY id"]]
|
| 150 |
+
|
| 151 |
+
# Do a contained-in query with surplus contraints at the beginning.
|
| 152 |
+
# This should force a full-table scan on the rtree.
|
| 153 |
+
#
|
| 154 |
+
set where {}
|
| 155 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 156 |
+
lappend where mn$j>-10000 mx$j<10000
|
| 157 |
+
}
|
| 158 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 159 |
+
set mn [rand 10000]
|
| 160 |
+
set mx [expr {$mn+[randincr 500]}]
|
| 161 |
+
lappend where mn$j>=$mn mx$j<=$mx
|
| 162 |
+
}
|
| 163 |
+
set where "WHERE [join $where { AND }]"
|
| 164 |
+
do_test rtree4-$nDim.2.$i.3 {
|
| 165 |
+
list $where [db eval "SELECT id FROM rx $where ORDER BY id"]
|
| 166 |
+
} [list $where [db eval "SELECT id FROM bx $where ORDER BY id"]]
|
| 167 |
+
|
| 168 |
+
# Do an overlaps query with surplus contraints at the beginning.
|
| 169 |
+
# This should force a full-table scan on the rtree.
|
| 170 |
+
#
|
| 171 |
+
set where {}
|
| 172 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 173 |
+
lappend where mn$j>=-10000 mx$j<=10000
|
| 174 |
+
}
|
| 175 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 176 |
+
set mn [rand 10000]
|
| 177 |
+
set mx [expr {$mn+[randincr 500]}]
|
| 178 |
+
lappend where mx$j>$mn mn$j<$mx
|
| 179 |
+
}
|
| 180 |
+
set where "WHERE [join $where { AND }]"
|
| 181 |
+
do_test rtree4-$nDim.2.$i.4 {
|
| 182 |
+
list $where [db eval "SELECT id FROM rx $where ORDER BY id"]
|
| 183 |
+
} [list $where [db eval "SELECT id FROM bx $where ORDER BY id"]]
|
| 184 |
+
|
| 185 |
+
# Do a contained-in query with surplus contraints at the end
|
| 186 |
+
#
|
| 187 |
+
set where {}
|
| 188 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 189 |
+
set mn [rand 10000]
|
| 190 |
+
set mx [expr {$mn+[randincr 500]}]
|
| 191 |
+
lappend where mn$j>=$mn mx$j<$mx
|
| 192 |
+
}
|
| 193 |
+
for {set j [expr {$nDim-1}]} {$j>=0} {incr j -1} {
|
| 194 |
+
lappend where mn$j>=-10000 mx$j<10000
|
| 195 |
+
}
|
| 196 |
+
set where "WHERE [join $where { AND }]"
|
| 197 |
+
do_test rtree4-$nDim.2.$i.5 {
|
| 198 |
+
list $where [db eval "SELECT id FROM rx $where ORDER BY id"]
|
| 199 |
+
} [list $where [db eval "SELECT id FROM bx $where ORDER BY id"]]
|
| 200 |
+
|
| 201 |
+
# Do an overlaps query with surplus contraints at the end
|
| 202 |
+
#
|
| 203 |
+
set where {}
|
| 204 |
+
for {set j [expr {$nDim-1}]} {$j>=0} {incr j -1} {
|
| 205 |
+
set mn [rand 10000]
|
| 206 |
+
set mx [expr {$mn+[randincr 500]}]
|
| 207 |
+
lappend where mx$j>$mn mn$j<=$mx
|
| 208 |
+
}
|
| 209 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 210 |
+
lappend where mx$j>-10000 mn$j<=10000
|
| 211 |
+
}
|
| 212 |
+
set where "WHERE [join $where { AND }]"
|
| 213 |
+
do_test rtree4-$nDim.2.$i.6 {
|
| 214 |
+
list $where [db eval "SELECT id FROM rx $where ORDER BY id"]
|
| 215 |
+
} [list $where [db eval "SELECT id FROM bx $where ORDER BY id"]]
|
| 216 |
+
|
| 217 |
+
# Do a contained-in query with surplus contraints where the
|
| 218 |
+
# constraints appear in a random order.
|
| 219 |
+
#
|
| 220 |
+
set where {}
|
| 221 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 222 |
+
set mn1 [rand 10000]
|
| 223 |
+
set mn2 [expr {$mn1+[randincr 100]}]
|
| 224 |
+
set mx1 [expr {$mn2+[randincr 400]}]
|
| 225 |
+
set mx2 [expr {$mx1+[randincr 100]}]
|
| 226 |
+
lappend where mn$j>=$mn1 mn$j>$mn2 mx$j<$mx1 mx$j<=$mx2
|
| 227 |
+
}
|
| 228 |
+
set where "WHERE [join [scramble $where] { AND }]"
|
| 229 |
+
do_test rtree4-$nDim.2.$i.7 {
|
| 230 |
+
list $where [db eval "SELECT id FROM rx $where ORDER BY id"]
|
| 231 |
+
} [list $where [db eval "SELECT id FROM bx $where ORDER BY id"]]
|
| 232 |
+
|
| 233 |
+
# Do an overlaps query with surplus contraints where the
|
| 234 |
+
# constraints appear in a random order.
|
| 235 |
+
#
|
| 236 |
+
set where {}
|
| 237 |
+
for {set j 0} {$j<$nDim} {incr j} {
|
| 238 |
+
set mn1 [rand 10000]
|
| 239 |
+
set mn2 [expr {$mn1+[randincr 100]}]
|
| 240 |
+
set mx1 [expr {$mn2+[randincr 400]}]
|
| 241 |
+
set mx2 [expr {$mx1+[randincr 100]}]
|
| 242 |
+
lappend where mx$j>=$mn1 mx$j>$mn2 mn$j<$mx1 mn$j<=$mx2
|
| 243 |
+
}
|
| 244 |
+
set where "WHERE [join [scramble $where] { AND }]"
|
| 245 |
+
do_test rtree4-$nDim.2.$i.8 {
|
| 246 |
+
list $where [db eval "SELECT id FROM rx $where ORDER BY id"]
|
| 247 |
+
} [list $where [db eval "SELECT id FROM bx $where ORDER BY id"]]
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2008 Sep 1
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
#
|
| 13 |
+
|
| 14 |
+
if {![info exists testdir]} {
|
| 15 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 16 |
+
}
|
| 17 |
+
source $testdir/tester.tcl
|
| 18 |
+
set testprefix rtree6
|
| 19 |
+
|
| 20 |
+
ifcapable {!rtree || rtree_int_only} {
|
| 21 |
+
finish_test
|
| 22 |
+
return
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# Operator Byte Value
|
| 26 |
+
# ----------------------
|
| 27 |
+
# = 0x41 ('A')
|
| 28 |
+
# <= 0x42 ('B')
|
| 29 |
+
# < 0x43 ('C')
|
| 30 |
+
# >= 0x44 ('D')
|
| 31 |
+
# > 0x45 ('E')
|
| 32 |
+
# ----------------------
|
| 33 |
+
|
| 34 |
+
proc rtree_strategy {sql} {
|
| 35 |
+
set ret [list]
|
| 36 |
+
db eval "explain $sql" a {
|
| 37 |
+
if {$a(opcode) eq "VFilter"} {
|
| 38 |
+
lappend ret $a(p4)
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
set ret
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
proc query_plan {sql} {
|
| 45 |
+
set ret [list]
|
| 46 |
+
db eval "explain query plan $sql" a {
|
| 47 |
+
lappend ret $a(detail)
|
| 48 |
+
}
|
| 49 |
+
set ret
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
do_test rtree6-1.1 {
|
| 53 |
+
execsql {
|
| 54 |
+
CREATE TABLE t2(k INTEGER PRIMARY KEY, v);
|
| 55 |
+
CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
|
| 56 |
+
}
|
| 57 |
+
} {}
|
| 58 |
+
|
| 59 |
+
do_test rtree6-1.2 {
|
| 60 |
+
rtree_strategy {SELECT * FROM t1 WHERE x1>10}
|
| 61 |
+
} {E0}
|
| 62 |
+
do_test rtree6-1.2.1 {
|
| 63 |
+
rtree_strategy {SELECT * FROM t1 WHERE x1>10 AND x2 LIKE '%x%'}
|
| 64 |
+
} {E0}
|
| 65 |
+
|
| 66 |
+
do_test rtree6-1.3 {
|
| 67 |
+
rtree_strategy {SELECT * FROM t1 WHERE x1<10}
|
| 68 |
+
} {C0}
|
| 69 |
+
|
| 70 |
+
do_test rtree6-1.4 {
|
| 71 |
+
rtree_strategy {SELECT * FROM t1,t2 WHERE k=ii AND x1<10}
|
| 72 |
+
} {C0}
|
| 73 |
+
|
| 74 |
+
do_test rtree6-1.5 {
|
| 75 |
+
rtree_strategy {SELECT * FROM t1,t2 WHERE k=+ii AND x1<10}
|
| 76 |
+
} {C0}
|
| 77 |
+
|
| 78 |
+
do_eqp_test rtree6.2.1 {
|
| 79 |
+
SELECT * FROM t1,t2 WHERE k=+ii AND x1<10
|
| 80 |
+
} {
|
| 81 |
+
QUERY PLAN
|
| 82 |
+
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0
|
| 83 |
+
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
do_eqp_test rtree6.2.2 {
|
| 87 |
+
SELECT * FROM t1,t2 WHERE k=ii AND x1<10
|
| 88 |
+
} {
|
| 89 |
+
QUERY PLAN
|
| 90 |
+
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0
|
| 91 |
+
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
do_eqp_test rtree6.2.3 {
|
| 95 |
+
SELECT * FROM t1,t2 WHERE k=ii
|
| 96 |
+
} {
|
| 97 |
+
QUERY PLAN
|
| 98 |
+
|--SCAN t1 VIRTUAL TABLE INDEX 2:
|
| 99 |
+
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
do_eqp_test rtree6.2.4.1 {
|
| 103 |
+
SELECT * FROM t1,t2 WHERE v=+ii and x1<10 and x2>10
|
| 104 |
+
} {
|
| 105 |
+
QUERY PLAN
|
| 106 |
+
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
|
| 107 |
+
|--BLOOM FILTER ON t2 (v=?)
|
| 108 |
+
`--SEARCH t2 USING AUTOMATIC COVERING INDEX (v=?)
|
| 109 |
+
}
|
| 110 |
+
do_eqp_test rtree6.2.4.2 {
|
| 111 |
+
SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10
|
| 112 |
+
} {
|
| 113 |
+
QUERY PLAN
|
| 114 |
+
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
|
| 115 |
+
|--BLOOM FILTER ON t2 (v=?)
|
| 116 |
+
`--SEARCH t2 USING AUTOMATIC PARTIAL COVERING INDEX (v=?)
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
do_eqp_test rtree6.2.5 {
|
| 120 |
+
SELECT * FROM t1,t2 WHERE k=ii AND x1<v
|
| 121 |
+
} {
|
| 122 |
+
QUERY PLAN
|
| 123 |
+
|--SCAN t1 VIRTUAL TABLE INDEX 2:
|
| 124 |
+
`--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
do_execsql_test rtree6-3.1 {
|
| 128 |
+
CREATE VIRTUAL TABLE t3 USING rtree(id, x1, x2, y1, y2);
|
| 129 |
+
INSERT INTO t3 VALUES(NULL, 1, 1, 2, 2);
|
| 130 |
+
SELECT * FROM t3 WHERE
|
| 131 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 132 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 133 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 134 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 135 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 136 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5;
|
| 137 |
+
} {1 1.0 1.0 2.0 2.0}
|
| 138 |
+
|
| 139 |
+
do_test rtree6.3.2 {
|
| 140 |
+
rtree_strategy {
|
| 141 |
+
SELECT * FROM t3 WHERE
|
| 142 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 143 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 144 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 145 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5
|
| 146 |
+
}
|
| 147 |
+
} {E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0}
|
| 148 |
+
do_test rtree6.3.3 {
|
| 149 |
+
rtree_strategy {
|
| 150 |
+
SELECT * FROM t3 WHERE
|
| 151 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 152 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 153 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 154 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 155 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 156 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5
|
| 157 |
+
}
|
| 158 |
+
} {E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0}
|
| 159 |
+
|
| 160 |
+
do_execsql_test rtree6-3.4 {
|
| 161 |
+
SELECT * FROM t3 WHERE x1>0.5 AND x1>0.8 AND x1>1.1
|
| 162 |
+
} {}
|
| 163 |
+
do_execsql_test rtree6-3.5 {
|
| 164 |
+
SELECT * FROM t3 WHERE
|
| 165 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 166 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 167 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 168 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 169 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
|
| 170 |
+
x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>1.1
|
| 171 |
+
} {}
|
| 172 |
+
|
| 173 |
+
#-------------------------------------------------------------------------
|
| 174 |
+
reset_db
|
| 175 |
+
do_execsql_test 4.0 {
|
| 176 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id,x0,x1,y0,y1);
|
| 177 |
+
}
|
| 178 |
+
do_execsql_test 4.1 {
|
| 179 |
+
DELETE FROM t1 WHERE x0>1 AND x1<2 OR y0<92;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
expand_all_sql db
|
| 183 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree7.test
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2010 February 16
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# Test that nothing goes wrong if an rtree table is created, then the
|
| 13 |
+
# database page-size is modified. At one point (3.6.22), this was causing
|
| 14 |
+
# malfunctions.
|
| 15 |
+
#
|
| 16 |
+
|
| 17 |
+
if {![info exists testdir]} {
|
| 18 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 19 |
+
}
|
| 20 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 21 |
+
source $testdir/tester.tcl
|
| 22 |
+
|
| 23 |
+
ifcapable !rtree||!vacuum {
|
| 24 |
+
finish_test
|
| 25 |
+
return
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Like execsql except display output as integer where that can be
|
| 29 |
+
# done without loss of information.
|
| 30 |
+
#
|
| 31 |
+
proc execsql_intout {sql} {
|
| 32 |
+
set out {}
|
| 33 |
+
foreach term [execsql $sql] {
|
| 34 |
+
regsub {\.0$} $term {} term
|
| 35 |
+
lappend out $term
|
| 36 |
+
}
|
| 37 |
+
return $out
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
do_test rtree7-1.1 {
|
| 41 |
+
execsql {
|
| 42 |
+
PRAGMA page_size = 1024;
|
| 43 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2, y1, y2);
|
| 44 |
+
INSERT INTO rt VALUES(1, 1, 2, 3, 4);
|
| 45 |
+
}
|
| 46 |
+
} {}
|
| 47 |
+
do_test rtree7-1.2 {
|
| 48 |
+
execsql_intout { SELECT * FROM rt }
|
| 49 |
+
} {1 1 2 3 4}
|
| 50 |
+
do_test rtree7-1.3 {
|
| 51 |
+
execsql_intout {
|
| 52 |
+
PRAGMA page_size = 2048;
|
| 53 |
+
VACUUM;
|
| 54 |
+
SELECT * FROM rt;
|
| 55 |
+
}
|
| 56 |
+
} {1 1 2 3 4}
|
| 57 |
+
do_test rtree7-1.4 {
|
| 58 |
+
for {set i 2} {$i <= 51} {incr i} {
|
| 59 |
+
execsql { INSERT INTO rt VALUES($i, 1, 2, 3, 4) }
|
| 60 |
+
}
|
| 61 |
+
execsql_intout { SELECT sum(x1), sum(x2), sum(y1), sum(y2) FROM rt }
|
| 62 |
+
} {51 102 153 204}
|
| 63 |
+
do_test rtree7-1.5 {
|
| 64 |
+
execsql_intout {
|
| 65 |
+
PRAGMA page_size = 512;
|
| 66 |
+
VACUUM;
|
| 67 |
+
SELECT sum(x1), sum(x2), sum(y1), sum(y2) FROM rt
|
| 68 |
+
}
|
| 69 |
+
} {51 102 153 204}
|
| 70 |
+
|
| 71 |
+
do_rtree_integrity_test rtree7-1.6 rt
|
| 72 |
+
|
| 73 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree8.test
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2010 February 16
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
#
|
| 13 |
+
|
| 14 |
+
if {![info exists testdir]} {
|
| 15 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 16 |
+
}
|
| 17 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 18 |
+
source $testdir/tester.tcl
|
| 19 |
+
ifcapable !rtree { finish_test ; return }
|
| 20 |
+
|
| 21 |
+
#-------------------------------------------------------------------------
|
| 22 |
+
# The following block of tests - rtree8-1.* - feature reading and writing
|
| 23 |
+
# an r-tree table while there exist open cursors on it.
|
| 24 |
+
#
|
| 25 |
+
proc populate_t1 {n} {
|
| 26 |
+
execsql { DELETE FROM t1 }
|
| 27 |
+
for {set i 1} {$i <= $n} {incr i} {
|
| 28 |
+
execsql { INSERT INTO t1 VALUES($i, $i, $i+2) }
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
# A DELETE while a cursor is reading the table.
|
| 33 |
+
#
|
| 34 |
+
do_test rtree8-1.1.1 {
|
| 35 |
+
execsql { PRAGMA page_size = 512 }
|
| 36 |
+
execsql { CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2) }
|
| 37 |
+
populate_t1 5
|
| 38 |
+
} {}
|
| 39 |
+
do_test rtree8-1.1.2 {
|
| 40 |
+
set res [list]
|
| 41 |
+
set rc [catch {
|
| 42 |
+
db eval { SELECT * FROM t1 } {
|
| 43 |
+
lappend res $x1 $x2
|
| 44 |
+
if {$id==3} { db eval { DELETE FROM t1 WHERE id>3 } }
|
| 45 |
+
}
|
| 46 |
+
} msg];
|
| 47 |
+
lappend rc $msg
|
| 48 |
+
set rc
|
| 49 |
+
} {1 {database table is locked}}
|
| 50 |
+
do_test rtree8-1.1.2b {
|
| 51 |
+
db eval { SELECT * FROM t1 ORDER BY +id } {
|
| 52 |
+
if {$id==3} { db eval { DELETE FROM t1 WHERE id>3 } }
|
| 53 |
+
}
|
| 54 |
+
db eval {SELECT x1, x2 FROM t1}
|
| 55 |
+
} {1 3 2 4 3 5}
|
| 56 |
+
do_test rtree8-1.1.3 {
|
| 57 |
+
execsql { SELECT * FROM t1 }
|
| 58 |
+
} {1 1 3 2 2 4 3 3 5}
|
| 59 |
+
|
| 60 |
+
# Many SELECTs on the same small table.
|
| 61 |
+
#
|
| 62 |
+
proc nested_select {n} {
|
| 63 |
+
set ::max $n
|
| 64 |
+
db eval { SELECT * FROM t1 } {
|
| 65 |
+
if {$id == $n} { nested_select [expr $n+1] }
|
| 66 |
+
}
|
| 67 |
+
return $::max
|
| 68 |
+
}
|
| 69 |
+
do_test rtree8-1.2.1 { populate_t1 50 } {}
|
| 70 |
+
do_test rtree8-1.2.2 { nested_select 1 } {51}
|
| 71 |
+
|
| 72 |
+
# This test runs many SELECT queries simultaneously against a large
|
| 73 |
+
# table, causing a collision in the hash-table used to store r-tree
|
| 74 |
+
# nodes internally.
|
| 75 |
+
#
|
| 76 |
+
populate_t1 1500
|
| 77 |
+
do_rtree_integrity_test rtree8-1.3.0 t1
|
| 78 |
+
do_execsql_test rtree8-1.3.1 { SELECT max(nodeno) FROM t1_node } {183}
|
| 79 |
+
do_test rtree8-1.3.2 {
|
| 80 |
+
set rowids [execsql {SELECT min(rowid) FROM t1_rowid GROUP BY nodeno}]
|
| 81 |
+
set stmt_list [list]
|
| 82 |
+
foreach row $rowids {
|
| 83 |
+
set stmt [sqlite3_prepare db "SELECT * FROM t1 WHERE id = $row" -1 tail]
|
| 84 |
+
sqlite3_step $stmt
|
| 85 |
+
lappend res_list [sqlite3_column_int $stmt 0]
|
| 86 |
+
lappend stmt_list $stmt
|
| 87 |
+
}
|
| 88 |
+
} {}
|
| 89 |
+
do_test rtree8-1.3.3 { set res_list } $rowids
|
| 90 |
+
do_execsql_test rtree8-1.3.4 { SELECT count(*) FROM t1 } {1500}
|
| 91 |
+
do_test rtree8-1.3.5 {
|
| 92 |
+
foreach stmt $stmt_list { sqlite3_finalize $stmt }
|
| 93 |
+
} {}
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
#-------------------------------------------------------------------------
|
| 97 |
+
# The following block of tests - rtree8-2.* - test a couple of database
|
| 98 |
+
# corruption cases. In this case things are not corrupted at the b-tree
|
| 99 |
+
# level, but the contents of the various tables used internally by an
|
| 100 |
+
# r-tree table are inconsistent.
|
| 101 |
+
#
|
| 102 |
+
populate_t1 50
|
| 103 |
+
do_execsql_test rtree8-2.1.1 { SELECT max(nodeno) FROM t1_node } {5}
|
| 104 |
+
sqlite3_db_config db DEFENSIVE 0
|
| 105 |
+
do_execsql_test rtree8-2.1.2 { DELETE FROM t1_node } {}
|
| 106 |
+
for {set i 1} {$i <= 50} {incr i} {
|
| 107 |
+
do_catchsql_test rtree8-2.1.3.$i {
|
| 108 |
+
SELECT * FROM t1 WHERE id = $i
|
| 109 |
+
} {1 {database disk image is malformed}}
|
| 110 |
+
}
|
| 111 |
+
do_catchsql_test rtree8-2.1.4 {
|
| 112 |
+
SELECT * FROM t1
|
| 113 |
+
} {1 {database disk image is malformed}}
|
| 114 |
+
do_catchsql_test rtree8-2.1.5 {
|
| 115 |
+
DELETE FROM t1
|
| 116 |
+
} {1 {database disk image is malformed}}
|
| 117 |
+
|
| 118 |
+
do_execsql_test rtree8-2.1.6 {
|
| 119 |
+
DROP TABLE t1;
|
| 120 |
+
CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
|
| 121 |
+
} {}
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
populate_t1 50
|
| 125 |
+
sqlite3_db_config db DEFENSIVE 0
|
| 126 |
+
do_execsql_test rtree8-2.2.1 {
|
| 127 |
+
DELETE FROM t1_parent
|
| 128 |
+
} {}
|
| 129 |
+
do_catchsql_test rtree8-2.2.2 {
|
| 130 |
+
DELETE FROM t1 WHERE id=25
|
| 131 |
+
} {1 {database disk image is malformed}}
|
| 132 |
+
do_execsql_test rtree8-2.2.3 {
|
| 133 |
+
DROP TABLE t1;
|
| 134 |
+
CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
|
| 135 |
+
} {}
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
#-------------------------------------------------------------------------
|
| 139 |
+
# Test that trying to use the MATCH operator with the r-tree module does
|
| 140 |
+
# not confuse it.
|
| 141 |
+
#
|
| 142 |
+
populate_t1 10
|
| 143 |
+
do_catchsql_test rtree8-3.1 {
|
| 144 |
+
SELECT * FROM t1 WHERE x1 MATCH '1234'
|
| 145 |
+
} {1 {SQL logic error}}
|
| 146 |
+
|
| 147 |
+
#-------------------------------------------------------------------------
|
| 148 |
+
# Test a couple of invalid arguments to rtreedepth().
|
| 149 |
+
#
|
| 150 |
+
do_catchsql_test rtree8-4.1 {
|
| 151 |
+
SELECT rtreedepth('hello world')
|
| 152 |
+
} {1 {Invalid argument to rtreedepth()}}
|
| 153 |
+
do_catchsql_test rtree8-4.2 {
|
| 154 |
+
SELECT rtreedepth(X'00')
|
| 155 |
+
} {1 {Invalid argument to rtreedepth()}}
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
#-------------------------------------------------------------------------
|
| 159 |
+
# Delete half of a lopsided tree.
|
| 160 |
+
#
|
| 161 |
+
do_execsql_test rtree8-5.1 {
|
| 162 |
+
CREATE VIRTUAL TABLE t2 USING rtree_i32(id, x1, x2)
|
| 163 |
+
} {}
|
| 164 |
+
do_test rtree8-5.2 {
|
| 165 |
+
execsql BEGIN
|
| 166 |
+
for {set i 0} {$i < 100} {incr i} {
|
| 167 |
+
execsql { INSERT INTO t2 VALUES($i, 100, 101) }
|
| 168 |
+
}
|
| 169 |
+
for {set i 100} {$i < 200} {incr i} {
|
| 170 |
+
execsql { INSERT INTO t2 VALUES($i, 1000, 1001) }
|
| 171 |
+
}
|
| 172 |
+
execsql COMMIT
|
| 173 |
+
} {}
|
| 174 |
+
do_rtree_integrity_test rtree8-5.3 t2
|
| 175 |
+
do_test rtree8-5.4 {
|
| 176 |
+
execsql BEGIN
|
| 177 |
+
for {set i 0} {$i < 200} {incr i} {
|
| 178 |
+
execsql { DELETE FROM t2 WHERE id = $i }
|
| 179 |
+
}
|
| 180 |
+
execsql COMMIT
|
| 181 |
+
} {}
|
| 182 |
+
do_rtree_integrity_test rtree8-5.5 t2
|
| 183 |
+
|
| 184 |
+
# 2018-05-24
|
| 185 |
+
# The following script caused an assertion fault and/or segfault
|
| 186 |
+
# prior to the fix that prevents simultaneous reads and writes on
|
| 187 |
+
# the same rtree virtual table.
|
| 188 |
+
#
|
| 189 |
+
do_test rtree8-6.1 {
|
| 190 |
+
db close
|
| 191 |
+
sqlite3 db :memory:
|
| 192 |
+
db eval {
|
| 193 |
+
PRAGMA page_size=512;
|
| 194 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id,x1,x2,y1,y2);
|
| 195 |
+
WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<49)
|
| 196 |
+
INSERT INTO t1 SELECT x, x, x+1, x, x+1 FROM c;
|
| 197 |
+
}
|
| 198 |
+
set rc [catch {
|
| 199 |
+
db eval {SELECT id FROM t1} x {
|
| 200 |
+
db eval {DELETE FROM t1 WHERE id=$x(id)}
|
| 201 |
+
}
|
| 202 |
+
} msg]
|
| 203 |
+
lappend rc $msg
|
| 204 |
+
} {1 {database table is locked}}
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree9.test
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2010 August 28
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
# This file contains tests for the r-tree module. Specifically, it tests
|
| 12 |
+
# that custom r-tree queries (geometry callbacks) work.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
ifcapable !rtree { finish_test ; return }
|
| 21 |
+
ifcapable rtree_int_only { finish_test; return }
|
| 22 |
+
|
| 23 |
+
register_cube_geom db
|
| 24 |
+
|
| 25 |
+
do_execsql_test rtree9-1.1 {
|
| 26 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2, y1, y2, z1, z2);
|
| 27 |
+
INSERT INTO rt VALUES(1, 1, 2, 1, 2, 1, 2);
|
| 28 |
+
} {}
|
| 29 |
+
do_execsql_test rtree9-1.2 {
|
| 30 |
+
SELECT * FROM rt WHERE id MATCH cube(0, 0, 0, 2, 2, 2);
|
| 31 |
+
} {1 1.0 2.0 1.0 2.0 1.0 2.0}
|
| 32 |
+
do_execsql_test rtree9-1.3 {
|
| 33 |
+
SELECT * FROM rt WHERE id MATCH cube(3, 3, 3, 2, 2, 2);
|
| 34 |
+
} {}
|
| 35 |
+
do_execsql_test rtree9-1.4 {
|
| 36 |
+
DELETE FROM rt;
|
| 37 |
+
} {}
|
| 38 |
+
|
| 39 |
+
unset -nocomplain x
|
| 40 |
+
for {set i 0} {$i < 1000} {incr i} {
|
| 41 |
+
set x [expr $i%10]
|
| 42 |
+
set y [expr ($i/10)%10]
|
| 43 |
+
set z [expr ($i/100)%10]
|
| 44 |
+
execsql { INSERT INTO rt VALUES($i, $x, $x+1, $y, $y+1, $z, $z+1) }
|
| 45 |
+
}
|
| 46 |
+
do_rtree_integrity_test rtree9-2.0 rt
|
| 47 |
+
do_execsql_test rtree9-2.1 {
|
| 48 |
+
SELECT id FROM rt WHERE id MATCH cube(2.5, 2.5, 2.5, 1, 1, 1) ORDER BY id;
|
| 49 |
+
} {222 223 232 233 322 323 332 333}
|
| 50 |
+
do_execsql_test rtree9-2.2 {
|
| 51 |
+
SELECT id FROM rt WHERE id MATCH cube(5.5, 5.5, 5.5, 1, 1, 1) ORDER BY id;
|
| 52 |
+
} {555 556 565 566 655 656 665 666}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
do_execsql_test rtree9-3.0 {
|
| 56 |
+
CREATE VIRTUAL TABLE rt32 USING rtree_i32(id, x1, x2, y1, y2, z1, z2);
|
| 57 |
+
} {}
|
| 58 |
+
for {set i 0} {$i < 1000} {incr i} {
|
| 59 |
+
set x [expr $i%10]
|
| 60 |
+
set y [expr ($i/10)%10]
|
| 61 |
+
set z [expr ($i/100)%10]
|
| 62 |
+
execsql { INSERT INTO rt32 VALUES($i, $x, $x+1, $y, $y+1, $z, $z+1) }
|
| 63 |
+
}
|
| 64 |
+
do_rtree_integrity_test rtree9-3.1 rt32
|
| 65 |
+
do_execsql_test rtree9-3.2 {
|
| 66 |
+
SELECT id FROM rt32 WHERE id MATCH cube(3, 3, 3, 1, 1, 1) ORDER BY id;
|
| 67 |
+
} {222 223 224 232 233 234 242 243 244 322 323 324 332 333 334 342 343 344 422 423 424 432 433 434 442 443 444}
|
| 68 |
+
do_execsql_test rtree9-3.3 {
|
| 69 |
+
SELECT id FROM rt32 WHERE id MATCH cube(5.5, 5.5, 5.5, 1, 1, 1) ORDER BY id;
|
| 70 |
+
} {555 556 565 566 655 656 665 666}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
do_catchsql_test rtree9-4.1 {
|
| 74 |
+
SELECT id FROM rt32 WHERE id MATCH cube(5.5, 5.5, 1, 1, 1) ORDER BY id;
|
| 75 |
+
} {1 {SQL logic error}}
|
| 76 |
+
for {set x 2} {$x<200} {incr x 2} {
|
| 77 |
+
do_catchsql_test rtree9-4.2.[expr $x/2] {
|
| 78 |
+
SELECT id FROM rt WHERE id MATCH randomblob($x)
|
| 79 |
+
} {1 {SQL logic error}}
|
| 80 |
+
}
|
| 81 |
+
do_catchsql_test rtree9-4.3 {
|
| 82 |
+
SELECT id FROM rt WHERE id MATCH CAST(
|
| 83 |
+
(cube(5.5, 5.5, 5.5, 1, 1, 1) || X'1234567812345678') AS blob
|
| 84 |
+
)
|
| 85 |
+
} {1 {SQL logic error}}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
#-------------------------------------------------------------------------
|
| 89 |
+
# Test the example 2d "circle" geometry callback.
|
| 90 |
+
#
|
| 91 |
+
register_circle_geom db
|
| 92 |
+
|
| 93 |
+
do_execsql_test rtree9-5.1 {
|
| 94 |
+
CREATE VIRTUAL TABLE rt2 USING rtree(id, xmin, xmax, ymin, ymax);
|
| 95 |
+
|
| 96 |
+
INSERT INTO rt2 VALUES(1, 1, 2, 1, 2);
|
| 97 |
+
INSERT INTO rt2 VALUES(2, 1, 2, -2, -1);
|
| 98 |
+
INSERT INTO rt2 VALUES(3, -2, -1, -2, -1);
|
| 99 |
+
INSERT INTO rt2 VALUES(4, -2, -1, 1, 2);
|
| 100 |
+
|
| 101 |
+
INSERT INTO rt2 VALUES(5, 2, 3, 2, 3);
|
| 102 |
+
INSERT INTO rt2 VALUES(6, 2, 3, -3, -2);
|
| 103 |
+
INSERT INTO rt2 VALUES(7, -3, -2, -3, -2);
|
| 104 |
+
INSERT INTO rt2 VALUES(8, -3, -2, 2, 3);
|
| 105 |
+
|
| 106 |
+
INSERT INTO rt2 VALUES(9, 1.8, 3, 1.8, 3);
|
| 107 |
+
INSERT INTO rt2 VALUES(10, 1.8, 3, -3, -1.8);
|
| 108 |
+
INSERT INTO rt2 VALUES(11, -3, -1.8, -3, -1.8);
|
| 109 |
+
INSERT INTO rt2 VALUES(12, -3, -1.8, 1.8, 3);
|
| 110 |
+
|
| 111 |
+
INSERT INTO rt2 VALUES(13, -15, 15, 1.8, 2.2);
|
| 112 |
+
INSERT INTO rt2 VALUES(14, -15, 15, -2.2, -1.8);
|
| 113 |
+
INSERT INTO rt2 VALUES(15, 1.8, 2.2, -15, 15);
|
| 114 |
+
INSERT INTO rt2 VALUES(16, -2.2, -1.8, -15, 15);
|
| 115 |
+
|
| 116 |
+
INSERT INTO rt2 VALUES(17, -100, 100, -100, 100);
|
| 117 |
+
} {}
|
| 118 |
+
|
| 119 |
+
do_execsql_test rtree9-5.2 {
|
| 120 |
+
SELECT id FROM rt2 WHERE id MATCH circle(0.0, 0.0, 2.0);
|
| 121 |
+
} {1 2 3 4 13 14 15 16 17}
|
| 122 |
+
|
| 123 |
+
do_execsql_test rtree9-5.3 {
|
| 124 |
+
UPDATE rt2 SET xmin=xmin+5, ymin=ymin+5, xmax=xmax+5, ymax=ymax+5;
|
| 125 |
+
SELECT id FROM rt2 WHERE id MATCH circle(5.0, 5.0, 2.0);
|
| 126 |
+
} {1 2 3 4 13 14 15 16 17}
|
| 127 |
+
do_rtree_integrity_test rtree9-5.4 rt2
|
| 128 |
+
|
| 129 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeA.test
ADDED
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2010 September 22
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
# This file contains tests for the r-tree module. Specifically, it tests
|
| 12 |
+
# that corrupt or inconsistent databases do not cause crashes in the r-tree
|
| 13 |
+
# module.
|
| 14 |
+
#
|
| 15 |
+
|
| 16 |
+
if {![info exists testdir]} {
|
| 17 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 18 |
+
}
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
ifcapable !rtree { finish_test ; return }
|
| 21 |
+
|
| 22 |
+
proc create_t1 {} {
|
| 23 |
+
db close
|
| 24 |
+
forcedelete test.db
|
| 25 |
+
sqlite3 db test.db
|
| 26 |
+
execsql {
|
| 27 |
+
PRAGMA page_size = 1024;
|
| 28 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2, y1, y2);
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
proc populate_t1 {} {
|
| 32 |
+
execsql BEGIN
|
| 33 |
+
for {set i 0} {$i < 500} {incr i} {
|
| 34 |
+
set x2 [expr $i+5]
|
| 35 |
+
set y2 [expr $i+5]
|
| 36 |
+
execsql { INSERT INTO t1 VALUES($i, $i, $x2, $i, $y2) }
|
| 37 |
+
}
|
| 38 |
+
execsql COMMIT
|
| 39 |
+
sqlite3_db_config db DEFENSIVE 0
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
proc truncate_node {nodeno nTrunc} {
|
| 43 |
+
set blob [db one {SELECT data FROM t1_node WHERE nodeno=$nodeno}]
|
| 44 |
+
if {$nTrunc<0} {set nTrunc "end-$nTrunc"}
|
| 45 |
+
set blob [string range $blob 0 $nTrunc]
|
| 46 |
+
db eval { UPDATE t1_node SET data = $blob WHERE nodeno=$nodeno }
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
proc set_tree_depth {tbl {newvalue ""}} {
|
| 50 |
+
set blob [db one "SELECT data FROM ${tbl}_node WHERE nodeno=1"]
|
| 51 |
+
|
| 52 |
+
if {$newvalue == ""} {
|
| 53 |
+
binary scan $blob Su oldvalue
|
| 54 |
+
return $oldvalue
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
set blob [binary format Sua* $newvalue [string range $blob 2 end]]
|
| 58 |
+
db eval "UPDATE ${tbl}_node SET data = \$blob WHERE nodeno=1"
|
| 59 |
+
return [set_tree_depth $tbl]
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
proc set_entry_count {tbl nodeno {newvalue ""}} {
|
| 63 |
+
set blob [db one "SELECT data FROM ${tbl}_node WHERE nodeno=$nodeno"]
|
| 64 |
+
|
| 65 |
+
if {$newvalue == ""} {
|
| 66 |
+
binary scan [string range $blob 2 end] Su oldvalue
|
| 67 |
+
return $oldvalue
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
set blob [binary format a*Sua* \
|
| 71 |
+
[string range $blob 0 1] $newvalue [string range $blob 4 end]
|
| 72 |
+
]
|
| 73 |
+
db eval "UPDATE ${tbl}_node SET data = \$blob WHERE nodeno=$nodeno"
|
| 74 |
+
return [set_entry_count $tbl $nodeno]
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
proc do_corruption_tests {prefix args} {
|
| 79 |
+
set testarray [lindex $args end]
|
| 80 |
+
set errormsg {database disk image is malformed}
|
| 81 |
+
|
| 82 |
+
foreach {z value} [lrange $args 0 end-1] {
|
| 83 |
+
set n [string length $z]
|
| 84 |
+
if {$n>=2 && [string equal -length $n $z "-error"]} {
|
| 85 |
+
set errormsg $value
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
foreach {tn sql} $testarray {
|
| 90 |
+
do_catchsql_test $prefix.$tn $sql [list 1 $errormsg]
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
#-------------------------------------------------------------------------
|
| 95 |
+
# Test the libraries response if the %_node table is completely empty
|
| 96 |
+
# (i.e. the root node is missing), or has been removed from the database
|
| 97 |
+
# entirely.
|
| 98 |
+
#
|
| 99 |
+
create_t1
|
| 100 |
+
populate_t1
|
| 101 |
+
do_execsql_test rtreeA-1.0 {
|
| 102 |
+
DELETE FROM t1_node;
|
| 103 |
+
} {}
|
| 104 |
+
|
| 105 |
+
do_corruption_tests rtreeA-1.1 {
|
| 106 |
+
1 "SELECT * FROM t1"
|
| 107 |
+
2 "SELECT * FROM t1 WHERE rowid=5"
|
| 108 |
+
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
| 109 |
+
4 "SELECT * FROM t1 WHERE x1<10 AND x2>12"
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
do_execsql_test rtreeA-1.1.1 {
|
| 113 |
+
SELECT rtreecheck('main', 't1')
|
| 114 |
+
} {{Node 1 missing from database
|
| 115 |
+
Wrong number of entries in %_rowid table - expected 0, actual 500
|
| 116 |
+
Wrong number of entries in %_parent table - expected 0, actual 25}}
|
| 117 |
+
|
| 118 |
+
do_execsql_test rtreeA-1.2.0 { DROP TABLE t1_node } {}
|
| 119 |
+
do_corruption_tests rtreeA-1.2 -error "database disk image is malformed" {
|
| 120 |
+
1 "SELECT * FROM t1"
|
| 121 |
+
2 "SELECT * FROM t1 WHERE rowid=5"
|
| 122 |
+
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
| 123 |
+
4 "SELECT * FROM t1 WHERE x1<10 AND x2>12"
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
#-------------------------------------------------------------------------
|
| 127 |
+
# Test the libraries response if some of the entries in the %_node table
|
| 128 |
+
# are the wrong size.
|
| 129 |
+
#
|
| 130 |
+
create_t1
|
| 131 |
+
populate_t1
|
| 132 |
+
do_test rtreeA-2.1.0 {
|
| 133 |
+
set nodes [db eval {select nodeno FROM t1_node}]
|
| 134 |
+
foreach {a b c} $nodes { truncate_node $c 200 }
|
| 135 |
+
} {}
|
| 136 |
+
do_corruption_tests rtreeA-2.1 {
|
| 137 |
+
1 "SELECT * FROM t1"
|
| 138 |
+
2 "SELECT * FROM t1 WHERE rowid=5"
|
| 139 |
+
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
| 140 |
+
4 "SELECT * FROM t1 WHERE x1<10 AND x2>12"
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
create_t1
|
| 144 |
+
populate_t1
|
| 145 |
+
do_test rtreeA-2.2.0 { truncate_node 1 200 } {}
|
| 146 |
+
do_corruption_tests rtreeA-2.2 {
|
| 147 |
+
1 "SELECT * FROM t1"
|
| 148 |
+
2 "SELECT * FROM t1 WHERE +rowid=5"
|
| 149 |
+
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
| 150 |
+
4 "SELECT * FROM t1 WHERE x1<10 AND x2>12"
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
#-------------------------------------------------------------------------
|
| 154 |
+
# Set the "depth" of the tree stored on the root node incorrectly. Test
|
| 155 |
+
# that this does not cause any problems.
|
| 156 |
+
#
|
| 157 |
+
create_t1
|
| 158 |
+
populate_t1
|
| 159 |
+
do_test rtreeA-3.1.0.1 { set_tree_depth t1 } {1}
|
| 160 |
+
do_test rtreeA-3.1.0.2 { set_tree_depth t1 3 } {3}
|
| 161 |
+
do_corruption_tests rtreeA-3.1 {
|
| 162 |
+
1 "SELECT * FROM t1"
|
| 163 |
+
2 "SELECT * FROM t1 WHERE +rowid=5"
|
| 164 |
+
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
do_execsql_test rtreeA-3.1.0.3 {
|
| 168 |
+
SELECT rtreecheck('main', 't1')!='ok'
|
| 169 |
+
} {1}
|
| 170 |
+
|
| 171 |
+
do_test rtreeA-3.2.0 { set_tree_depth t1 1000 } {1000}
|
| 172 |
+
do_corruption_tests rtreeA-3.2 {
|
| 173 |
+
1 "SELECT * FROM t1"
|
| 174 |
+
2 "SELECT * FROM t1 WHERE +rowid=5"
|
| 175 |
+
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
create_t1
|
| 179 |
+
populate_t1
|
| 180 |
+
do_test rtreeA-3.3.0 {
|
| 181 |
+
execsql { DELETE FROM t1 WHERE rowid = 0 }
|
| 182 |
+
set_tree_depth t1 65535
|
| 183 |
+
} {65535}
|
| 184 |
+
do_corruption_tests rtreeA-3.3 {
|
| 185 |
+
1 "SELECT * FROM t1"
|
| 186 |
+
2 "SELECT * FROM t1 WHERE +rowid=5"
|
| 187 |
+
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
do_execsql_test rtreeA-3.3.3.4 {
|
| 191 |
+
SELECT rtreecheck('main', 't1')
|
| 192 |
+
} {{Rtree depth out of range (65535)
|
| 193 |
+
Wrong number of entries in %_rowid table - expected 0, actual 499
|
| 194 |
+
Wrong number of entries in %_parent table - expected 0, actual 25}}
|
| 195 |
+
|
| 196 |
+
#-------------------------------------------------------------------------
|
| 197 |
+
# Set the "number of entries" field on some nodes incorrectly.
|
| 198 |
+
#
|
| 199 |
+
create_t1
|
| 200 |
+
populate_t1
|
| 201 |
+
do_test rtreeA-4.1.0 {
|
| 202 |
+
set_entry_count t1 1 4000
|
| 203 |
+
} {4000}
|
| 204 |
+
do_corruption_tests rtreeA-4.1 {
|
| 205 |
+
1 "SELECT * FROM t1"
|
| 206 |
+
2 "SELECT * FROM t1 WHERE +rowid=5"
|
| 207 |
+
3 "INSERT INTO t1 VALUES(1000, 1, 2, 3, 4)"
|
| 208 |
+
4 "SELECT * FROM t1 WHERE x1<10 AND x2>12"
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
#-------------------------------------------------------------------------
|
| 212 |
+
# Remove entries from the %_parent table and check that this does not
|
| 213 |
+
# cause a crash.
|
| 214 |
+
#
|
| 215 |
+
create_t1
|
| 216 |
+
populate_t1
|
| 217 |
+
do_execsql_test rtreeA-5.1.0 { DELETE FROM t1_parent } {}
|
| 218 |
+
do_corruption_tests rtreeA-5.1 {
|
| 219 |
+
1 "DELETE FROM t1 WHERE +rowid = 5"
|
| 220 |
+
2 "DELETE FROM t1"
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
do_execsql_test rtreeA-5.2 {
|
| 224 |
+
SELECT rtreecheck('main', 't1')!='ok'
|
| 225 |
+
} {1}
|
| 226 |
+
|
| 227 |
+
#-------------------------------------------------------------------------
|
| 228 |
+
# Add some bad entries to the %_parent table.
|
| 229 |
+
#
|
| 230 |
+
create_t1
|
| 231 |
+
populate_t1
|
| 232 |
+
do_execsql_test rtreeA-6.1.0 {
|
| 233 |
+
UPDATE t1_parent set parentnode = parentnode+1
|
| 234 |
+
} {}
|
| 235 |
+
do_corruption_tests rtreeA-6.1 {
|
| 236 |
+
1 "DELETE FROM t1 WHERE rowid = 5"
|
| 237 |
+
2 "UPDATE t1 SET x1=x1+1, x2=x2+1"
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
do_execsql_test rtreeA-6.2 {
|
| 241 |
+
SELECT rtreecheck('main', 't1')!='ok'
|
| 242 |
+
} {1}
|
| 243 |
+
|
| 244 |
+
#-------------------------------------------------------------------------
|
| 245 |
+
# Truncated blobs in the _node table.
|
| 246 |
+
#
|
| 247 |
+
create_t1
|
| 248 |
+
populate_t1
|
| 249 |
+
sqlite3 db test.db
|
| 250 |
+
sqlite3_db_config db DEFENSIVE 0
|
| 251 |
+
do_execsql_test rtreeA-7.100 {
|
| 252 |
+
UPDATE t1_node SET data=x'' WHERE rowid=1;
|
| 253 |
+
} {}
|
| 254 |
+
do_catchsql_test rtreeA-7.110 {
|
| 255 |
+
SELECT * FROM t1 WHERE x1>0 AND x1<100 AND x2>0 AND x2<100;
|
| 256 |
+
} {1 {undersize RTree blobs in "t1_node"}}
|
| 257 |
+
do_test rtreeA-7.120 {
|
| 258 |
+
sqlite3_extended_errcode db
|
| 259 |
+
} {SQLITE_CORRUPT_VTAB}
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeC.test
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2011 March 2
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
# Make sure the rtreenode() testing function can handle entries with
|
| 12 |
+
# 64-bit rowids.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
ifcapable !rtree { finish_test ; return }
|
| 21 |
+
set testprefix rtreeC
|
| 22 |
+
|
| 23 |
+
do_execsql_test 1.0 {
|
| 24 |
+
CREATE VIRTUAL TABLE r_tree USING rtree(id, min_x, max_x, min_y, max_y);
|
| 25 |
+
CREATE TABLE t(x, y);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
do_eqp_test 1.1 {
|
| 29 |
+
SELECT * FROM r_tree, t
|
| 30 |
+
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y
|
| 31 |
+
} {
|
| 32 |
+
QUERY PLAN
|
| 33 |
+
|--SCAN t
|
| 34 |
+
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
do_eqp_test 1.2 {
|
| 38 |
+
SELECT * FROM t, r_tree
|
| 39 |
+
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y
|
| 40 |
+
} {
|
| 41 |
+
QUERY PLAN
|
| 42 |
+
|--SCAN t
|
| 43 |
+
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
do_eqp_test 1.3 {
|
| 47 |
+
SELECT * FROM t, r_tree
|
| 48 |
+
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND ?<=max_y
|
| 49 |
+
} {
|
| 50 |
+
QUERY PLAN
|
| 51 |
+
|--SCAN t
|
| 52 |
+
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
do_eqp_test 1.5 {
|
| 56 |
+
SELECT * FROM t, r_tree
|
| 57 |
+
} {
|
| 58 |
+
QUERY PLAN
|
| 59 |
+
|--SCAN r_tree VIRTUAL TABLE INDEX 2:
|
| 60 |
+
`--SCAN t
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
do_execsql_test 2.0 {
|
| 64 |
+
INSERT INTO t VALUES(0, 0);
|
| 65 |
+
INSERT INTO t VALUES(0, 1);
|
| 66 |
+
INSERT INTO t VALUES(0, 2);
|
| 67 |
+
INSERT INTO t VALUES(0, 3);
|
| 68 |
+
INSERT INTO t VALUES(0, 4);
|
| 69 |
+
INSERT INTO t VALUES(0, 5);
|
| 70 |
+
INSERT INTO t VALUES(0, 6);
|
| 71 |
+
INSERT INTO t VALUES(0, 7);
|
| 72 |
+
INSERT INTO t VALUES(0, 8);
|
| 73 |
+
INSERT INTO t VALUES(0, 9);
|
| 74 |
+
|
| 75 |
+
INSERT INTO t SELECT x+1, y FROM t;
|
| 76 |
+
INSERT INTO t SELECT x+2, y FROM t;
|
| 77 |
+
INSERT INTO t SELECT x+4, y FROM t;
|
| 78 |
+
INSERT INTO r_tree SELECT NULL, x-1, x+1, y-1, y+1 FROM t;
|
| 79 |
+
ANALYZE;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
db close
|
| 83 |
+
sqlite3 db test.db
|
| 84 |
+
|
| 85 |
+
do_eqp_test 2.1 {
|
| 86 |
+
SELECT * FROM r_tree, t
|
| 87 |
+
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y
|
| 88 |
+
} {
|
| 89 |
+
QUERY PLAN
|
| 90 |
+
|--SCAN t
|
| 91 |
+
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
do_eqp_test 2.2 {
|
| 95 |
+
SELECT * FROM t, r_tree
|
| 96 |
+
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y
|
| 97 |
+
} {
|
| 98 |
+
QUERY PLAN
|
| 99 |
+
|--SCAN t
|
| 100 |
+
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
do_eqp_test 2.3 {
|
| 104 |
+
SELECT * FROM t, r_tree
|
| 105 |
+
WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND ?<=max_y
|
| 106 |
+
} {
|
| 107 |
+
QUERY PLAN
|
| 108 |
+
|--SCAN t
|
| 109 |
+
`--SCAN r_tree VIRTUAL TABLE INDEX 2:D3B2D1B0
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
do_eqp_test 2.5 {
|
| 113 |
+
SELECT * FROM t, r_tree
|
| 114 |
+
} {
|
| 115 |
+
QUERY PLAN
|
| 116 |
+
|--SCAN r_tree VIRTUAL TABLE INDEX 2:
|
| 117 |
+
`--SCAN t
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
#-------------------------------------------------------------------------
|
| 121 |
+
# Test that the special CROSS JOIN handling works with rtree tables.
|
| 122 |
+
#
|
| 123 |
+
do_execsql_test 3.1 {
|
| 124 |
+
CREATE TABLE t1(x);
|
| 125 |
+
CREATE TABLE t2(y);
|
| 126 |
+
CREATE VIRTUAL TABLE t3 USING rtree(z, x1,x2, y1,y2);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
do_eqp_test 3.2.1 { SELECT * FROM t1 CROSS JOIN t2 } {
|
| 130 |
+
QUERY PLAN
|
| 131 |
+
|--SCAN t1
|
| 132 |
+
`--SCAN t2
|
| 133 |
+
}
|
| 134 |
+
do_eqp_test 3.2.2 { SELECT * FROM t2 CROSS JOIN t1 } {
|
| 135 |
+
QUERY PLAN
|
| 136 |
+
|--SCAN t2
|
| 137 |
+
`--SCAN t1
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
do_eqp_test 3.3.1 { SELECT * FROM t1 CROSS JOIN t3 } {
|
| 141 |
+
QUERY PLAN
|
| 142 |
+
|--SCAN t1
|
| 143 |
+
`--SCAN t3 VIRTUAL TABLE INDEX 2:
|
| 144 |
+
}
|
| 145 |
+
do_eqp_test 3.3.2 { SELECT * FROM t3 CROSS JOIN t1 } {
|
| 146 |
+
QUERY PLAN
|
| 147 |
+
|--SCAN t3 VIRTUAL TABLE INDEX 2:
|
| 148 |
+
`--SCAN t1
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
#--------------------------------------------------------------------
|
| 152 |
+
# Test that LEFT JOINs are not reordered if the right-hand-side is
|
| 153 |
+
# a virtual table.
|
| 154 |
+
#
|
| 155 |
+
reset_db
|
| 156 |
+
do_execsql_test 4.1 {
|
| 157 |
+
CREATE TABLE t1(a);
|
| 158 |
+
CREATE VIRTUAL TABLE t2 USING rtree(b, x1,x2);
|
| 159 |
+
|
| 160 |
+
INSERT INTO t1 VALUES(1);
|
| 161 |
+
INSERT INTO t1 VALUES(2);
|
| 162 |
+
|
| 163 |
+
INSERT INTO t2 VALUES(1, 0.0, 0.1);
|
| 164 |
+
INSERT INTO t2 VALUES(3, 0.0, 0.1);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
do_execsql_test 4.2 {
|
| 168 |
+
SELECT a, b FROM t1 LEFT JOIN t2 ON (+a = +b);
|
| 169 |
+
} {1 1 2 {}}
|
| 170 |
+
|
| 171 |
+
do_execsql_test 4.3 {
|
| 172 |
+
SELECT b, a FROM t2 LEFT JOIN t1 ON (+a = +b);
|
| 173 |
+
} {1 1 3 {}}
|
| 174 |
+
|
| 175 |
+
#--------------------------------------------------------------------
|
| 176 |
+
# Test that the sqlite_stat1 data is used correctly.
|
| 177 |
+
#
|
| 178 |
+
reset_db
|
| 179 |
+
do_execsql_test 5.1 {
|
| 180 |
+
CREATE TABLE t1(x INT PRIMARY KEY, y);
|
| 181 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2, +d1);
|
| 182 |
+
|
| 183 |
+
INSERT INTO t1(x) VALUES(1);
|
| 184 |
+
INSERT INTO t1(x) SELECT x+1 FROM t1; -- 2
|
| 185 |
+
INSERT INTO t1(x) SELECT x+2 FROM t1; -- 4
|
| 186 |
+
INSERT INTO t1(x) SELECT x+4 FROM t1; -- 8
|
| 187 |
+
INSERT INTO t1(x) SELECT x+8 FROM t1; -- 16
|
| 188 |
+
INSERT INTO t1(x) SELECT x+16 FROM t1; -- 32
|
| 189 |
+
INSERT INTO t1(x) SELECT x+32 FROM t1; -- 64
|
| 190 |
+
INSERT INTO t1(x) SELECT x+64 FROM t1; -- 128
|
| 191 |
+
INSERT INTO t1(x) SELECT x+128 FROM t1; -- 256
|
| 192 |
+
INSERT INTO t1(x) SELECT x+256 FROM t1; -- 512
|
| 193 |
+
INSERT INTO t1(x) SELECT x+512 FROM t1; --1024
|
| 194 |
+
|
| 195 |
+
INSERT INTO rt SELECT x, x, x+1, printf('x%04xy',x) FROM t1 WHERE x<=5;
|
| 196 |
+
}
|
| 197 |
+
do_rtree_integrity_test 5.1.1 rt
|
| 198 |
+
|
| 199 |
+
# First test a query with no ANALYZE data at all. The outer loop is
|
| 200 |
+
# real table "t1".
|
| 201 |
+
#
|
| 202 |
+
do_eqp_test 5.2 {
|
| 203 |
+
SELECT * FROM t1, rt WHERE x==id;
|
| 204 |
+
} {
|
| 205 |
+
QUERY PLAN
|
| 206 |
+
|--SCAN t1
|
| 207 |
+
`--SCAN rt VIRTUAL TABLE INDEX 1:
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
# Now create enough ANALYZE data to tell SQLite that virtual table "rt"
|
| 211 |
+
# contains very few rows. This causes it to move "rt" to the outer loop.
|
| 212 |
+
#
|
| 213 |
+
do_execsql_test 5.3 {
|
| 214 |
+
ANALYZE;
|
| 215 |
+
DELETE FROM sqlite_stat1 WHERE tbl='t1';
|
| 216 |
+
}
|
| 217 |
+
db close
|
| 218 |
+
sqlite3 db test.db
|
| 219 |
+
do_eqp_test 5.4 {
|
| 220 |
+
SELECT * FROM t1, rt WHERE x==id;
|
| 221 |
+
} {
|
| 222 |
+
QUERY PLAN
|
| 223 |
+
|--SCAN rt VIRTUAL TABLE INDEX 2:
|
| 224 |
+
`--SEARCH t1 USING INDEX sqlite_autoindex_t1_1 (x=?)
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
# Delete the ANALYZE data. "t1" should be the outer loop again.
|
| 228 |
+
#
|
| 229 |
+
do_execsql_test 5.5 { DROP TABLE sqlite_stat1; }
|
| 230 |
+
db close
|
| 231 |
+
sqlite3 db test.db
|
| 232 |
+
do_eqp_test 5.6 {
|
| 233 |
+
SELECT * FROM t1, rt WHERE x==id;
|
| 234 |
+
} {
|
| 235 |
+
QUERY PLAN
|
| 236 |
+
|--SCAN t1
|
| 237 |
+
`--SCAN rt VIRTUAL TABLE INDEX 1:
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
# This time create and attach a database that contains ANALYZE data for
|
| 241 |
+
# tables of the same names as those used internally by virtual table
|
| 242 |
+
# "rt". Check that the rtree module is not fooled into using this data.
|
| 243 |
+
# Table "t1" should remain the outer loop.
|
| 244 |
+
#
|
| 245 |
+
do_test 5.7 {
|
| 246 |
+
db backup test.db2
|
| 247 |
+
sqlite3 db2 test.db2
|
| 248 |
+
db2 eval {
|
| 249 |
+
ANALYZE;
|
| 250 |
+
DELETE FROM sqlite_stat1 WHERE tbl='t1';
|
| 251 |
+
}
|
| 252 |
+
db2 close
|
| 253 |
+
db close
|
| 254 |
+
sqlite3 db test.db
|
| 255 |
+
execsql { ATTACH 'test.db2' AS aux; }
|
| 256 |
+
} {}
|
| 257 |
+
do_eqp_test 5.8 {
|
| 258 |
+
SELECT * FROM t1, rt WHERE x==id;
|
| 259 |
+
} {
|
| 260 |
+
QUERY PLAN
|
| 261 |
+
|--SCAN t1
|
| 262 |
+
`--SCAN rt VIRTUAL TABLE INDEX 1:
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
#--------------------------------------------------------------------
|
| 266 |
+
# Test that having a second connection drop the sqlite_stat1 table
|
| 267 |
+
# before it is required by rtreeConnect() does not cause problems.
|
| 268 |
+
#
|
| 269 |
+
ifcapable rtree {
|
| 270 |
+
reset_db
|
| 271 |
+
do_execsql_test 6.1 {
|
| 272 |
+
CREATE TABLE t1(x);
|
| 273 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2);
|
| 274 |
+
INSERT INTO t1 VALUES(1);
|
| 275 |
+
INSERT INTO rt VALUES(1,2,3);
|
| 276 |
+
ANALYZE;
|
| 277 |
+
}
|
| 278 |
+
db close
|
| 279 |
+
sqlite3 db test.db
|
| 280 |
+
do_execsql_test 6.2 { SELECT * FROM t1 } {1}
|
| 281 |
+
|
| 282 |
+
do_test 6.3 {
|
| 283 |
+
sqlite3 db2 test.db
|
| 284 |
+
db2 eval { DROP TABLE sqlite_stat1 }
|
| 285 |
+
db2 close
|
| 286 |
+
execsql { SELECT * FROM rt }
|
| 287 |
+
} {1 2.0 3.0}
|
| 288 |
+
db close
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
#--------------------------------------------------------------------
|
| 292 |
+
# Test that queries featuring LEFT or CROSS JOINS are handled correctly.
|
| 293 |
+
# Handled correctly in this case means:
|
| 294 |
+
#
|
| 295 |
+
# * Terms with prereqs that appear to the left of a LEFT JOIN against
|
| 296 |
+
# the virtual table are always available to xBestIndex.
|
| 297 |
+
#
|
| 298 |
+
# * Terms with prereqs that appear to the right of a LEFT JOIN against
|
| 299 |
+
# the virtual table are never available to xBestIndex.
|
| 300 |
+
#
|
| 301 |
+
# And the same behaviour for CROSS joins.
|
| 302 |
+
#
|
| 303 |
+
reset_db
|
| 304 |
+
do_execsql_test 7.0 {
|
| 305 |
+
CREATE TABLE xdir(x1);
|
| 306 |
+
CREATE TABLE ydir(y1);
|
| 307 |
+
CREATE VIRTUAL TABLE rt USING rtree_i32(id, xmin, xmax, ymin, ymax);
|
| 308 |
+
|
| 309 |
+
INSERT INTO xdir VALUES(5);
|
| 310 |
+
INSERT INTO ydir VALUES(10);
|
| 311 |
+
|
| 312 |
+
INSERT INTO rt VALUES(1, 2, 7, 12, 14); -- Not a hit
|
| 313 |
+
INSERT INTO rt VALUES(2, 2, 7, 8, 12); -- A hit!
|
| 314 |
+
INSERT INTO rt VALUES(3, 7, 11, 8, 12); -- Not a hit!
|
| 315 |
+
INSERT INTO rt VALUES(4, 5, 5, 10, 10); -- A hit!
|
| 316 |
+
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
proc do_eqp_execsql_test {tn sql res1 res2} {
|
| 320 |
+
do_eqp_test $tn.1 $sql $res1
|
| 321 |
+
do_execsql_test $tn.2 $sql $res2
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
do_eqp_execsql_test 7.1 {
|
| 325 |
+
SELECT id FROM xdir, rt, ydir
|
| 326 |
+
ON (y1 BETWEEN ymin AND ymax)
|
| 327 |
+
WHERE (x1 BETWEEN xmin AND xmax);
|
| 328 |
+
} {
|
| 329 |
+
QUERY PLAN
|
| 330 |
+
|--SCAN xdir
|
| 331 |
+
|--SCAN ydir
|
| 332 |
+
`--SCAN rt VIRTUAL TABLE INDEX 2:B2D3B0D1
|
| 333 |
+
} {
|
| 334 |
+
2 4
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
do_eqp_execsql_test 7.2 {
|
| 338 |
+
SELECT * FROM xdir, rt LEFT JOIN ydir
|
| 339 |
+
ON (y1 BETWEEN ymin AND ymax)
|
| 340 |
+
WHERE (x1 BETWEEN xmin AND xmax);
|
| 341 |
+
} {
|
| 342 |
+
QUERY PLAN
|
| 343 |
+
|--SCAN xdir
|
| 344 |
+
|--SCAN rt VIRTUAL TABLE INDEX 2:B0D1
|
| 345 |
+
`--SCAN ydir LEFT-JOIN
|
| 346 |
+
} {
|
| 347 |
+
5 1 2 7 12 14 {}
|
| 348 |
+
5 2 2 7 8 12 10
|
| 349 |
+
5 4 5 5 10 10 10
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
do_eqp_execsql_test 7.3 {
|
| 353 |
+
SELECT id FROM xdir, rt CROSS JOIN ydir
|
| 354 |
+
ON (y1 BETWEEN ymin AND ymax)
|
| 355 |
+
WHERE (x1 BETWEEN xmin AND xmax);
|
| 356 |
+
} {
|
| 357 |
+
QUERY PLAN
|
| 358 |
+
|--SCAN xdir
|
| 359 |
+
|--SCAN rt VIRTUAL TABLE INDEX 2:B0D1
|
| 360 |
+
`--SCAN ydir
|
| 361 |
+
} {
|
| 362 |
+
2 4
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
do_eqp_execsql_test 7.4 {
|
| 366 |
+
SELECT id FROM rt, xdir CROSS JOIN ydir
|
| 367 |
+
ON (y1 BETWEEN ymin AND ymax)
|
| 368 |
+
WHERE (x1 BETWEEN xmin AND xmax);
|
| 369 |
+
} {
|
| 370 |
+
QUERY PLAN
|
| 371 |
+
|--SCAN xdir
|
| 372 |
+
|--SCAN rt VIRTUAL TABLE INDEX 2:B0D1
|
| 373 |
+
`--SCAN ydir
|
| 374 |
+
} {
|
| 375 |
+
2 4
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeE.test
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2010 August 28
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
# This file contains tests for the r-tree module. Specifically, it tests
|
| 12 |
+
# that new-style custom r-tree queries (geometry callbacks) work.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
ifcapable !rtree { finish_test ; return }
|
| 21 |
+
ifcapable rtree_int_only { finish_test; return }
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
#-------------------------------------------------------------------------
|
| 25 |
+
# Test the example 2d "circle" geometry callback.
|
| 26 |
+
#
|
| 27 |
+
register_circle_geom db
|
| 28 |
+
|
| 29 |
+
do_execsql_test rtreeE-1.0.0 {
|
| 30 |
+
PRAGMA page_size=512;
|
| 31 |
+
CREATE VIRTUAL TABLE rt1 USING rtree(id,x0,x1,y0,y1);
|
| 32 |
+
|
| 33 |
+
/* A tight pattern of small boxes near 0,0 */
|
| 34 |
+
WITH RECURSIVE
|
| 35 |
+
x(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM x WHERE x<4),
|
| 36 |
+
y(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM y WHERE y<4)
|
| 37 |
+
INSERT INTO rt1 SELECT x+5*y, x, x+2, y, y+2 FROM x, y;
|
| 38 |
+
|
| 39 |
+
/* A looser pattern of small boxes near 100, 0 */
|
| 40 |
+
WITH RECURSIVE
|
| 41 |
+
x(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM x WHERE x<4),
|
| 42 |
+
y(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM y WHERE y<4)
|
| 43 |
+
INSERT INTO rt1 SELECT 100+x+5*y, x*3+100, x*3+102, y*3, y*3+2 FROM x, y;
|
| 44 |
+
|
| 45 |
+
/* A looser pattern of larger boxes near 0, 200 */
|
| 46 |
+
WITH RECURSIVE
|
| 47 |
+
x(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM x WHERE x<4),
|
| 48 |
+
y(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM y WHERE y<4)
|
| 49 |
+
INSERT INTO rt1 SELECT 200+x+5*y, x*7, x*7+15, y*7+200, y*7+215 FROM x, y;
|
| 50 |
+
} {}
|
| 51 |
+
do_rtree_integrity_test rtreeE-1.0.1 rt1
|
| 52 |
+
|
| 53 |
+
# Queries against each of the three clusters */
|
| 54 |
+
do_execsql_test rtreeE-1.1 {
|
| 55 |
+
SELECT id FROM rt1 WHERE id MATCH Qcircle(0.0, 0.0, 50.0, 3) ORDER BY id;
|
| 56 |
+
} {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24}
|
| 57 |
+
do_execsql_test rtreeE-1.1x {
|
| 58 |
+
SELECT id FROM rt1 WHERE id MATCH Qcircle('x:0 y:0 r:50.0 e:3') ORDER BY id;
|
| 59 |
+
} {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24}
|
| 60 |
+
do_execsql_test rtreeE-1.2 {
|
| 61 |
+
SELECT id FROM rt1 WHERE id MATCH Qcircle(100.0, 0.0, 50.0, 3) ORDER BY id;
|
| 62 |
+
} {100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124}
|
| 63 |
+
do_execsql_test rtreeE-1.3 {
|
| 64 |
+
SELECT id FROM rt1 WHERE id MATCH Qcircle(0.0, 200.0, 50.0, 3) ORDER BY id;
|
| 65 |
+
} {200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224}
|
| 66 |
+
|
| 67 |
+
# The Qcircle geometry function gives a lower score to larger leaf-nodes.
|
| 68 |
+
# This causes the 200s to sort before the 100s and the 0s to sort before
|
| 69 |
+
# last.
|
| 70 |
+
#
|
| 71 |
+
do_execsql_test rtreeE-1.4 {
|
| 72 |
+
SELECT id FROM rt1 WHERE id MATCH Qcircle('r:1000 e:3') AND id%100==0
|
| 73 |
+
} {200 100 0}
|
| 74 |
+
|
| 75 |
+
# Exclude odd rowids on a depth-first search
|
| 76 |
+
do_execsql_test rtreeE-1.5 {
|
| 77 |
+
SELECT id FROM rt1 WHERE id MATCH Qcircle('r:1000 e:4') ORDER BY +id
|
| 78 |
+
} {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120 122 124 200 202 204 206 208 210 212 214 216 218 220 222 224}
|
| 79 |
+
|
| 80 |
+
# Exclude odd rowids on a breadth-first search.
|
| 81 |
+
do_execsql_test rtreeE-1.6 {
|
| 82 |
+
SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,5) ORDER BY +id
|
| 83 |
+
} {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120 122 124 200 202 204 206 208 210 212 214 216 218 220 222 224}
|
| 84 |
+
|
| 85 |
+
# Test that rtree prefers MATCH to lookup-by-rowid.
|
| 86 |
+
#
|
| 87 |
+
do_execsql_test rtreeE-1.7 {
|
| 88 |
+
SELECT id FROM rt1 WHERE id=18 AND id MATCH Qcircle(0,0,1000,5)
|
| 89 |
+
} {18}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# Construct a large 2-D RTree with thousands of random entries.
|
| 93 |
+
#
|
| 94 |
+
do_test rtreeE-2.1 {
|
| 95 |
+
db eval {
|
| 96 |
+
CREATE TABLE t2(id,x0,x1,y0,y1);
|
| 97 |
+
CREATE VIRTUAL TABLE rt2 USING rtree(id,x0,x1,y0,y1);
|
| 98 |
+
BEGIN;
|
| 99 |
+
}
|
| 100 |
+
expr srand(0)
|
| 101 |
+
for {set i 1} {$i<=10000} {incr i} {
|
| 102 |
+
set dx [expr {int(rand()*40)+1}]
|
| 103 |
+
set dy [expr {int(rand()*40)+1}]
|
| 104 |
+
set x0 [expr {int(rand()*(10000 - $dx))}]
|
| 105 |
+
set x1 [expr {$x0+$dx}]
|
| 106 |
+
set y0 [expr {int(rand()*(10000 - $dy))}]
|
| 107 |
+
set y1 [expr {$y0+$dy}]
|
| 108 |
+
set id [expr {$i+10000}]
|
| 109 |
+
db eval {INSERT INTO t2 VALUES($id,$x0,$x1,$y0,$y1)}
|
| 110 |
+
}
|
| 111 |
+
db eval {
|
| 112 |
+
INSERT INTO rt2 SELECT * FROM t2;
|
| 113 |
+
COMMIT;
|
| 114 |
+
}
|
| 115 |
+
} {}
|
| 116 |
+
do_rtree_integrity_test rtreeE-2.1.1 rt2
|
| 117 |
+
|
| 118 |
+
for {set i 1} {$i<=200} {incr i} {
|
| 119 |
+
set dx [expr {int(rand()*100)}]
|
| 120 |
+
set dy [expr {int(rand()*100)}]
|
| 121 |
+
set x0 [expr {int(rand()*(10000 - $dx))}]
|
| 122 |
+
set x1 [expr {$x0+$dx}]
|
| 123 |
+
set y0 [expr {int(rand()*(10000 - $dy))}]
|
| 124 |
+
set y1 [expr {$y0+$dy}]
|
| 125 |
+
set ans [db eval {SELECT id FROM t2 WHERE x1>=$x0 AND x0<=$x1 AND y1>=$y0 AND y0<=$y1 ORDER BY id}]
|
| 126 |
+
do_execsql_test rtreeE-2.2.$i {
|
| 127 |
+
SELECT id FROM rt2 WHERE id MATCH breadthfirstsearch($x0,$x1,$y0,$y1) ORDER BY id
|
| 128 |
+
} $ans
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
# Run query that have very deep priority queues
|
| 132 |
+
#
|
| 133 |
+
set ans [db eval {SELECT id FROM t2 WHERE x1>=0 AND x0<=5000 AND y1>=0 AND y0<=5000 ORDER BY id}]
|
| 134 |
+
do_execsql_test rtreeE-2.3 {
|
| 135 |
+
SELECT id FROM rt2 WHERE id MATCH breadthfirstsearch(0,5000,0,5000) ORDER BY id
|
| 136 |
+
} $ans
|
| 137 |
+
set ans [db eval {SELECT id FROM t2 WHERE x1>=0 AND x0<=10000 AND y1>=0 AND y0<=10000 ORDER BY id}]
|
| 138 |
+
do_execsql_test rtreeE-2.4 {
|
| 139 |
+
SELECT id FROM rt2 WHERE id MATCH breadthfirstsearch(0,10000,0,10000) ORDER BY id
|
| 140 |
+
} $ans
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeG.test
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2016-05-32
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
# This file contains tests for the r-tree module.
|
| 12 |
+
#
|
| 13 |
+
# Verify that no invalid SQL is run during initialization
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
ifcapable !rtree { finish_test ; return }
|
| 21 |
+
|
| 22 |
+
db close
|
| 23 |
+
sqlite3_shutdown
|
| 24 |
+
test_sqlite3_log [list lappend ::log]
|
| 25 |
+
set ::log [list]
|
| 26 |
+
sqlite3 db test.db
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
set ::log {}
|
| 30 |
+
do_execsql_test rtreeG-1.1 {
|
| 31 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id,x0,x1,y0,y1);
|
| 32 |
+
} {}
|
| 33 |
+
do_test rtreeG-1.1log {
|
| 34 |
+
set ::log
|
| 35 |
+
} {}
|
| 36 |
+
|
| 37 |
+
do_execsql_test rtreeG-1.2 {
|
| 38 |
+
INSERT INTO t1 VALUES(1,10,15,5,23),(2,20,21,5,23),(3,10,15,20,30);
|
| 39 |
+
SELECT id from t1 WHERE x0>8 AND x1<16 AND y0>2 AND y1<25;
|
| 40 |
+
} {1}
|
| 41 |
+
do_rtree_integrity_test rtreeG-1.2.integrity t1
|
| 42 |
+
do_test rtreeG-1.2log {
|
| 43 |
+
set ::log
|
| 44 |
+
} {}
|
| 45 |
+
|
| 46 |
+
db close
|
| 47 |
+
sqlite3 db test.db
|
| 48 |
+
do_execsql_test rtreeG-1.3 {
|
| 49 |
+
SELECT id from t1 WHERE x0>8 AND x1<16 AND y0>2 AND y1<25;
|
| 50 |
+
} {1}
|
| 51 |
+
do_test rtreeG-1.3log {
|
| 52 |
+
set ::log
|
| 53 |
+
} {}
|
| 54 |
+
|
| 55 |
+
do_execsql_test rtreeG-1.4 {
|
| 56 |
+
DROP TABLE t1;
|
| 57 |
+
} {}
|
| 58 |
+
do_test rtreeG-1.4log {
|
| 59 |
+
set ::log
|
| 60 |
+
} {}
|
| 61 |
+
|
| 62 |
+
expand_all_sql db
|
| 63 |
+
db close
|
| 64 |
+
sqlite3_shutdown
|
| 65 |
+
test_sqlite3_log
|
| 66 |
+
sqlite3_initialize
|
| 67 |
+
sqlite3 db test.db
|
| 68 |
+
|
| 69 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeH.test
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2018-05-16
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
# This file contains tests for the r-tree module, specifically the
|
| 12 |
+
# auxiliary column mechanism.
|
| 13 |
+
|
| 14 |
+
if {![info exists testdir]} {
|
| 15 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 16 |
+
}
|
| 17 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 18 |
+
source $testdir/tester.tcl
|
| 19 |
+
ifcapable !rtree { finish_test ; return }
|
| 20 |
+
|
| 21 |
+
do_execsql_test rtreeH-100 {
|
| 22 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id,x0,x1,y0,y1,+label,+other);
|
| 23 |
+
INSERT INTO t1(x0,x1,y0,y1,label) VALUES
|
| 24 |
+
(0,10,0,10,'lower-left corner'),
|
| 25 |
+
(0,10,90,100,'upper-left corner'),
|
| 26 |
+
(90,100,0,10,'lower-right corner'),
|
| 27 |
+
(90,100,90,100,'upper-right corner'),
|
| 28 |
+
(40,60,40,60,'center'),
|
| 29 |
+
(0,5,0,100,'left edge'),
|
| 30 |
+
(95,100,0,100,'right edge'),
|
| 31 |
+
(0,100,0,5,'bottom edge'),
|
| 32 |
+
(0,100,95,100,'top edge'),
|
| 33 |
+
(0,100,0,100,'the whole thing'),
|
| 34 |
+
(0,50,0,100,'left half'),
|
| 35 |
+
(51,100,0,100,'right half'),
|
| 36 |
+
(0,100,0,50,'bottom half'),
|
| 37 |
+
(0,100,51,100,'top half');
|
| 38 |
+
} {}
|
| 39 |
+
do_execsql_test rtreeH-101 {
|
| 40 |
+
SELECT * FROM t1_rowid ORDER BY rowid
|
| 41 |
+
} {1 1 {lower-left corner} {} 2 1 {upper-left corner} {} 3 1 {lower-right corner} {} 4 1 {upper-right corner} {} 5 1 center {} 6 1 {left edge} {} 7 1 {right edge} {} 8 1 {bottom edge} {} 9 1 {top edge} {} 10 1 {the whole thing} {} 11 1 {left half} {} 12 1 {right half} {} 13 1 {bottom half} {} 14 1 {top half} {}}
|
| 42 |
+
|
| 43 |
+
do_execsql_test rtreeH-102 {
|
| 44 |
+
SELECT * FROM t1 WHERE rowid=5;
|
| 45 |
+
} {5 40.0 60.0 40.0 60.0 center {}}
|
| 46 |
+
do_execsql_test rtreeH-102b {
|
| 47 |
+
SELECT * FROM t1 WHERE rowid=5.0;
|
| 48 |
+
} {5 40.0 60.0 40.0 60.0 center {}}
|
| 49 |
+
do_execsql_test rtreeH-102c {
|
| 50 |
+
SELECT * FROM t1 WHERE rowid='5';
|
| 51 |
+
} {5 40.0 60.0 40.0 60.0 center {}}
|
| 52 |
+
do_execsql_test rtreeH-102d {
|
| 53 |
+
SELECT * FROM t1 WHERE rowid='0005';
|
| 54 |
+
} {5 40.0 60.0 40.0 60.0 center {}}
|
| 55 |
+
do_execsql_test rtreeH-102e {
|
| 56 |
+
SELECT * FROM t1 WHERE rowid='+5.0e+0';
|
| 57 |
+
} {5 40.0 60.0 40.0 60.0 center {}}
|
| 58 |
+
do_execsql_test rtreeH-103 {
|
| 59 |
+
SELECT * FROM t1 WHERE label='center';
|
| 60 |
+
} {5 40.0 60.0 40.0 60.0 center {}}
|
| 61 |
+
|
| 62 |
+
do_execsql_test rtreeH-104 {
|
| 63 |
+
SELECT * FROM t1 WHERE rowid='+5.0e+0x';
|
| 64 |
+
} {}
|
| 65 |
+
do_execsql_test rtreeH-105 {
|
| 66 |
+
SELECT * FROM t1 WHERE rowid=x'35';
|
| 67 |
+
} {}
|
| 68 |
+
do_execsql_test rtreeH-106 {
|
| 69 |
+
SELECT * FROM t1 WHERE rowid=null;
|
| 70 |
+
} {}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
do_rtree_integrity_test rtreeH-110 t1
|
| 74 |
+
|
| 75 |
+
do_execsql_test rtreeH-120 {
|
| 76 |
+
SELECT label FROM t1 WHERE x1<=50 ORDER BY id
|
| 77 |
+
} {{lower-left corner} {upper-left corner} {left edge} {left half}}
|
| 78 |
+
do_execsql_test rtreeH-121 {
|
| 79 |
+
SELECT label FROM t1 WHERE x1<=50 AND label NOT LIKE '%corner%' ORDER BY id
|
| 80 |
+
} {{left edge} {left half}}
|
| 81 |
+
|
| 82 |
+
do_execsql_test rtreeH-200 {
|
| 83 |
+
WITH RECURSIVE
|
| 84 |
+
c1(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c1 WHERE x<99),
|
| 85 |
+
c2(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM c2 WHERE y<99)
|
| 86 |
+
INSERT INTO t1(id, x0,x1,y0,y1,label)
|
| 87 |
+
SELECT 1000+x+y*100, x, x+1, y, y+1, printf('box-%d,%d',x,y) FROM c1, c2;
|
| 88 |
+
} {}
|
| 89 |
+
|
| 90 |
+
do_execsql_test rtreeH-210 {
|
| 91 |
+
SELECT label FROM t1 WHERE x0>=48 AND x1<=50 AND y0>=48 AND y1<=50
|
| 92 |
+
ORDER BY id;
|
| 93 |
+
} {box-48,48 box-49,48 box-48,49 box-49,49}
|
| 94 |
+
|
| 95 |
+
do_execsql_test rtreeH-300 {
|
| 96 |
+
UPDATE t1 SET label='x'||label
|
| 97 |
+
WHERE x0>=49 AND x1<=50 AND y0>=49 AND y1<=50;
|
| 98 |
+
SELECT label FROM t1 WHERE x0>=48 AND x1<=50 AND y0>=48 AND y1<=50
|
| 99 |
+
ORDER BY id;
|
| 100 |
+
} {box-48,48 box-49,48 box-48,49 xbox-49,49}
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreeI.test
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2019-12-05
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
# Additional test cases
|
| 12 |
+
|
| 13 |
+
if {![info exists testdir]} {
|
| 14 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 15 |
+
}
|
| 16 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 17 |
+
source $testdir/tester.tcl
|
| 18 |
+
ifcapable !rtree { finish_test ; return }
|
| 19 |
+
|
| 20 |
+
# The following is a test of rowvalue handling on virtual tables that
|
| 21 |
+
# deal with inequalities and that set the OMIT flag on terms of the
|
| 22 |
+
# WHERE clause. This is not specific to rtree. We just use rtree because
|
| 23 |
+
# it is a convenient test platform since it has all the right
|
| 24 |
+
# characteristics.
|
| 25 |
+
#
|
| 26 |
+
do_execsql_test rtreeI-1.10 {
|
| 27 |
+
CREATE TABLE t1(a);
|
| 28 |
+
INSERT INTO t1 VALUES(2);
|
| 29 |
+
CREATE VIRTUAL TABLE t2 USING rtree(id,x0,x1);
|
| 30 |
+
INSERT INTO t2(id,x0,x1) VALUES(1,2,3);
|
| 31 |
+
} {}
|
| 32 |
+
do_execsql_test rtreeI-1.20 {
|
| 33 |
+
SELECT 123 FROM t1, t2 WHERE (a,0)>(x0,0);
|
| 34 |
+
} {}
|
| 35 |
+
do_execsql_test rtreeI-1.21 {
|
| 36 |
+
SELECT 123 FROM t1, t2 WHERE (a,0.1)>(x0,0);
|
| 37 |
+
} {123}
|
| 38 |
+
do_execsql_test rtreeI-1.22 {
|
| 39 |
+
SELECT 123 FROM t1, t2 WHERE (a,0)>=(x0,0);
|
| 40 |
+
} {123}
|
| 41 |
+
do_execsql_test rtreeI-1.23 {
|
| 42 |
+
SELECT 123 FROM t1, t2 WHERE (a,0)<=(x0,0);
|
| 43 |
+
} {123}
|
| 44 |
+
do_execsql_test rtreeI-1.24 {
|
| 45 |
+
SELECT 123 FROM t1, t2 WHERE (a,0)<(x0,0);
|
| 46 |
+
} {}
|
| 47 |
+
do_execsql_test rtreeI-1.30 {
|
| 48 |
+
SELECT 123 FROM t1, t2 WHERE (x0,0)<(a,0);
|
| 49 |
+
} {}
|
| 50 |
+
do_execsql_test rtreeI-1.31 {
|
| 51 |
+
SELECT 123 FROM t1, t2 WHERE (x0,0)<(a,0.1);
|
| 52 |
+
} {123}
|
| 53 |
+
do_execsql_test rtreeI-1.40 {
|
| 54 |
+
SELECT 123 FROM t1, t2 WHERE x1<5 AND id<99 AND (a,0)>(x0,0);
|
| 55 |
+
} {}
|
| 56 |
+
do_execsql_test rtreeI-1.41 {
|
| 57 |
+
SELECT 123 FROM t1, t2 WHERE x1<5 AND id<99 AND (a,0.5)>(x0,0);
|
| 58 |
+
} {123}
|
| 59 |
+
do_execsql_test rtreeI-1.42 {
|
| 60 |
+
SELECT 123 FROM t1, t2 WHERE x1<5 AND id<99 AND (a,0)>=(x0,0);
|
| 61 |
+
} {123}
|
| 62 |
+
do_execsql_test rtreeI-1.43 {
|
| 63 |
+
SELECT 123 FROM t1, t2 WHERE x1<5 AND id<99 AND (a,0)<(x0,0);
|
| 64 |
+
} {}
|
| 65 |
+
do_execsql_test rtreeI-1.50 {
|
| 66 |
+
SELECT 123 FROM t1, t2 WHERE 5>x1 AND 99>id AND (x0,0)<(a,0);
|
| 67 |
+
} {}
|
| 68 |
+
do_execsql_test rtreeI-1.51 {
|
| 69 |
+
SELECT 123 FROM t1, t2 WHERE 5>x1 AND 99>id AND (x0,0)<(a,0.5);
|
| 70 |
+
} {123}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sq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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2024-02-03
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# ROLLBACK in the middle of an RTREE query
|
| 13 |
+
#
|
| 14 |
+
if {![info exists testdir]} {
|
| 15 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 16 |
+
}
|
| 17 |
+
source $testdir/tester.tcl
|
| 18 |
+
set testprefix rtreeJ
|
| 19 |
+
ifcapable !rtree { finish_test ; return }
|
| 20 |
+
|
| 21 |
+
do_execsql_test 1.0 {
|
| 22 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2);
|
| 23 |
+
INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2);
|
| 24 |
+
} {}
|
| 25 |
+
|
| 26 |
+
do_execsql_test 1.1 {
|
| 27 |
+
SELECT * FROM t1
|
| 28 |
+
} {1 1.0 1.0 2 2.0 2.0}
|
| 29 |
+
|
| 30 |
+
# If a ROLLBACK occurs that backs out changes to the RTREE, then
|
| 31 |
+
# all pending queries to the RTREE are aborted.
|
| 32 |
+
#
|
| 33 |
+
do_test 1.2 {
|
| 34 |
+
db eval {
|
| 35 |
+
BEGIN;
|
| 36 |
+
INSERT INTO t1 VALUES(3, 3, 3);
|
| 37 |
+
INSERT INTO t1 VALUES(4, 4, 4);
|
| 38 |
+
}
|
| 39 |
+
set rc [catch {
|
| 40 |
+
db eval { SELECT * FROM t1 } {
|
| 41 |
+
if {$id==1} {
|
| 42 |
+
db eval { ROLLBACK }
|
| 43 |
+
}
|
| 44 |
+
lappend res $id $x1 $x2
|
| 45 |
+
}
|
| 46 |
+
} msg]
|
| 47 |
+
list $rc $msg
|
| 48 |
+
} {1 {query aborted}}
|
| 49 |
+
|
| 50 |
+
do_execsql_test 1.3 {
|
| 51 |
+
SELECT * FROM t1;
|
| 52 |
+
} {1 1.0 1.0 2 2.0 2.0}
|
| 53 |
+
|
| 54 |
+
# A COMMIT of changes to the RTREE does not affect pending queries
|
| 55 |
+
#
|
| 56 |
+
do_test 1.4 {
|
| 57 |
+
set res {}
|
| 58 |
+
db eval {
|
| 59 |
+
BEGIN;
|
| 60 |
+
INSERT INTO t1 VALUES(5, 5, 5);
|
| 61 |
+
INSERT INTO t1 VALUES(6, 6, 6);
|
| 62 |
+
}
|
| 63 |
+
db eval { SELECT * FROM t1 } {
|
| 64 |
+
if {$id==1} {
|
| 65 |
+
db eval { COMMIT }
|
| 66 |
+
}
|
| 67 |
+
lappend res $id $x1 $x2
|
| 68 |
+
}
|
| 69 |
+
set res
|
| 70 |
+
} {1 1.0 1.0 2 2.0 2.0 5 5.0 5.0 6 6.0 6.0}
|
| 71 |
+
|
| 72 |
+
do_execsql_test 1.5 {
|
| 73 |
+
SELECT * FROM t1;
|
| 74 |
+
} {1 1.0 1.0 2 2.0 2.0 5 5.0 5.0 6 6.0 6.0}
|
| 75 |
+
|
| 76 |
+
do_execsql_test 1.6 {
|
| 77 |
+
DELETE FROM t1;
|
| 78 |
+
INSERT INTO t1 VALUES(1,1,1),(2,2,2),(3,3,3),(4,4,4);
|
| 79 |
+
CREATE TABLE t2(x);
|
| 80 |
+
SELECT * FROM t1;
|
| 81 |
+
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0 4 4.0 4.0}
|
| 82 |
+
|
| 83 |
+
# A rollback that does not affect the rtree table because
|
| 84 |
+
# the rtree table has not been written to does not cause
|
| 85 |
+
# a query abort.
|
| 86 |
+
#
|
| 87 |
+
do_test 1.7 {
|
| 88 |
+
set res {}
|
| 89 |
+
db eval {
|
| 90 |
+
BEGIN;
|
| 91 |
+
INSERT INTO t2(x) VALUES(12345);
|
| 92 |
+
}
|
| 93 |
+
db eval { SELECT * FROM t1 } {
|
| 94 |
+
if {$id==1} {
|
| 95 |
+
db eval { ROLLBACK }
|
| 96 |
+
}
|
| 97 |
+
lappend res $id $x1 $x2
|
| 98 |
+
}
|
| 99 |
+
set res
|
| 100 |
+
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0 4 4.0 4.0}
|
| 101 |
+
|
| 102 |
+
# ROLLBACK TO that affects the RTREE does cause a query abort.
|
| 103 |
+
#
|
| 104 |
+
do_test 1.8 {
|
| 105 |
+
db eval {
|
| 106 |
+
DELETE FROM t1 WHERE rowid>1;
|
| 107 |
+
BEGIN;
|
| 108 |
+
DELETE FROM t2;
|
| 109 |
+
INSERT INTO t2(x) VALUES(23456);
|
| 110 |
+
SAVEPOINT 'one';
|
| 111 |
+
INSERT INTO t1 VALUES(2,2,2),(3,3,3);
|
| 112 |
+
}
|
| 113 |
+
set rc [catch {
|
| 114 |
+
db eval { SELECT * FROM t1 } {
|
| 115 |
+
if {$id==1} {
|
| 116 |
+
db eval { ROLLBACK TO 'one'; }
|
| 117 |
+
}
|
| 118 |
+
lappend res $id $x1 $x2
|
| 119 |
+
}
|
| 120 |
+
} msg]
|
| 121 |
+
list $rc $msg
|
| 122 |
+
} {1 {query aborted}}
|
| 123 |
+
|
| 124 |
+
do_execsql_test 1.9 {
|
| 125 |
+
COMMIT;
|
| 126 |
+
SELECT * FROM t1;
|
| 127 |
+
} {1 1.0 1.0}
|
| 128 |
+
|
| 129 |
+
# ROLLBACK TO that does not affect the RTREE does not cause a query abort.
|
| 130 |
+
#
|
| 131 |
+
do_execsql_test 1.10 {
|
| 132 |
+
DELETE FROM t1;
|
| 133 |
+
INSERT INTO t1 VALUES(1,1,1),(2,2,2),(3,3,3);
|
| 134 |
+
BEGIN;
|
| 135 |
+
DELETE FROM t2;
|
| 136 |
+
INSERT INTO t2(x) VALUES(34567);
|
| 137 |
+
SAVEPOINT 'one';
|
| 138 |
+
INSERT INTO t2(x) VALUES('a string');
|
| 139 |
+
SELECT * FROM t1;
|
| 140 |
+
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}
|
| 141 |
+
do_test 1.11 {
|
| 142 |
+
set rc [catch {
|
| 143 |
+
set res {}
|
| 144 |
+
db eval { SELECT * FROM t1 } {
|
| 145 |
+
if {$id==2} {
|
| 146 |
+
# db eval { ROLLBACK TO 'one'; }
|
| 147 |
+
}
|
| 148 |
+
lappend res $id $x1 $x2
|
| 149 |
+
}
|
| 150 |
+
set res
|
| 151 |
+
} msg]
|
| 152 |
+
list $rc $msg
|
| 153 |
+
} {0 {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}}
|
| 154 |
+
|
| 155 |
+
do_execsql_test 1.12 {
|
| 156 |
+
COMMIT;
|
| 157 |
+
SELECT * FROM t1;
|
| 158 |
+
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}
|
| 159 |
+
|
| 160 |
+
#----------------------------------------------------------------------
|
| 161 |
+
|
| 162 |
+
reset_db
|
| 163 |
+
do_execsql_test 2.0 {
|
| 164 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2);
|
| 165 |
+
INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2);
|
| 166 |
+
CREATE TABLE t2(x);
|
| 167 |
+
} {}
|
| 168 |
+
|
| 169 |
+
do_test 2.1 {
|
| 170 |
+
db eval {
|
| 171 |
+
BEGIN;
|
| 172 |
+
INSERT INTO t1 VALUES(3, 3, 3);
|
| 173 |
+
PRAGMA writable_schema = RESET;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
set rc [catch {
|
| 177 |
+
db eval { SELECT x1, x2 FROM t1 } {
|
| 178 |
+
if {$x1==1} {
|
| 179 |
+
db eval { ROLLBACK }
|
| 180 |
+
}
|
| 181 |
+
lappend res $x1 $x2
|
| 182 |
+
}
|
| 183 |
+
} msg]
|
| 184 |
+
list $rc $msg
|
| 185 |
+
} {1 {query aborted}}
|
| 186 |
+
|
| 187 |
+
do_execsql_test 2.1 {
|
| 188 |
+
CREATE TABLE bak_node(nodeno, data);
|
| 189 |
+
CREATE TABLE bak_parent(nodeno, parentnode);
|
| 190 |
+
CREATE TABLE bak_rowid(rowid, nodeno);
|
| 191 |
+
}
|
| 192 |
+
proc save_t1 {} {
|
| 193 |
+
db eval {
|
| 194 |
+
DELETE FROM bak_node;
|
| 195 |
+
DELETE FROM bak_parent;
|
| 196 |
+
DELETE FROM bak_rowid;
|
| 197 |
+
INSERT INTO bak_node SELECT * FROM t1_node;
|
| 198 |
+
INSERT INTO bak_parent SELECT * FROM t1_parent;
|
| 199 |
+
INSERT INTO bak_rowid SELECT * FROM t1_rowid;
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
proc restore_t1 {} {
|
| 203 |
+
db eval {
|
| 204 |
+
DELETE FROM t1_node;
|
| 205 |
+
DELETE FROM t1_parent;
|
| 206 |
+
DELETE FROM t1_rowid;
|
| 207 |
+
INSERT INTO t1_node SELECT * FROM bak_node;
|
| 208 |
+
INSERT INTO t1_parent SELECT * FROM bak_parent;
|
| 209 |
+
INSERT INTO t1_rowid SELECT * FROM bak_rowid;
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
do_test 2.3 {
|
| 214 |
+
save_t1
|
| 215 |
+
db eval {
|
| 216 |
+
INSERT INTO t1 VALUES(3, 3, 3);
|
| 217 |
+
}
|
| 218 |
+
set rc [catch {
|
| 219 |
+
db eval { SELECT rowid, x1, x2 FROM t1 } {
|
| 220 |
+
if {$x1==1} {
|
| 221 |
+
restore_t1
|
| 222 |
+
}
|
| 223 |
+
lappend res $x1 $x2
|
| 224 |
+
}
|
| 225 |
+
} msg]
|
| 226 |
+
list $rc $msg
|
| 227 |
+
} {1 {query aborted}}
|
| 228 |
+
do_execsql_test 2.4 {
|
| 229 |
+
SELECT * FROM t1
|
| 230 |
+
} {1 1.0 1.0 2 2.0 2.0}
|
| 231 |
+
|
| 232 |
+
do_test 2.5 {
|
| 233 |
+
save_t1
|
| 234 |
+
db eval {
|
| 235 |
+
INSERT INTO t1 VALUES(3, 3, 3);
|
| 236 |
+
}
|
| 237 |
+
set rc [catch {
|
| 238 |
+
db eval { SELECT x1 FROM t1 } {
|
| 239 |
+
if {$x1==1} {
|
| 240 |
+
restore_t1
|
| 241 |
+
}
|
| 242 |
+
lappend res $x1 $x2
|
| 243 |
+
}
|
| 244 |
+
} msg]
|
| 245 |
+
list $rc $msg
|
| 246 |
+
} {1 {query aborted}}
|
| 247 |
+
do_execsql_test 2.6 {
|
| 248 |
+
SELECT * FROM t1
|
| 249 |
+
} {1 1.0 1.0 2 2.0 2.0}
|
| 250 |
+
|
| 251 |
+
do_test 2.7 {
|
| 252 |
+
save_t1
|
| 253 |
+
db eval {
|
| 254 |
+
INSERT INTO t1 VALUES(3, 3, 3);
|
| 255 |
+
}
|
| 256 |
+
set ::res [list]
|
| 257 |
+
set rc [catch {
|
| 258 |
+
db eval { SELECT 'abc' FROM t1 } {
|
| 259 |
+
if {$::res==[list]} {
|
| 260 |
+
restore_t1
|
| 261 |
+
set ::bDone 1
|
| 262 |
+
}
|
| 263 |
+
lappend res abc
|
| 264 |
+
}
|
| 265 |
+
} msg]
|
| 266 |
+
set res
|
| 267 |
+
} {abc abc abc}
|
| 268 |
+
do_execsql_test 2.6 {
|
| 269 |
+
SELECT * FROM t1
|
| 270 |
+
} {1 1.0 1.0 2 2.0 2.0}
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtree_util.tcl
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2008 Feb 19
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# This file contains Tcl code that may be useful for testing or
|
| 13 |
+
# analyzing r-tree structures created with this module. It is
|
| 14 |
+
# used by both test procedures and the r-tree viewer application.
|
| 15 |
+
#
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#--------------------------------------------------------------------------
|
| 19 |
+
# PUBLIC API:
|
| 20 |
+
#
|
| 21 |
+
# rtree_depth
|
| 22 |
+
# rtree_ndim
|
| 23 |
+
# rtree_node
|
| 24 |
+
# rtree_mincells
|
| 25 |
+
# rtree_check
|
| 26 |
+
# rtree_dump
|
| 27 |
+
# rtree_treedump
|
| 28 |
+
#
|
| 29 |
+
|
| 30 |
+
proc rtree_depth {db zTab} {
|
| 31 |
+
$db one "SELECT rtreedepth(data) FROM ${zTab}_node WHERE nodeno=1"
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
proc rtree_nodedepth {db zTab iNode} {
|
| 35 |
+
set iDepth [rtree_depth $db $zTab]
|
| 36 |
+
|
| 37 |
+
set ii $iNode
|
| 38 |
+
while {$ii != 1} {
|
| 39 |
+
set sql "SELECT parentnode FROM ${zTab}_parent WHERE nodeno = $ii"
|
| 40 |
+
set ii [db one $sql]
|
| 41 |
+
incr iDepth -1
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
return $iDepth
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
# Return the number of dimensions of the rtree.
|
| 48 |
+
#
|
| 49 |
+
proc rtree_ndim {db zTab} {
|
| 50 |
+
set nDim [expr {(([llength [$db eval "pragma table_info($zTab)"]]/6)-1)/2}]
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
# Return the contents of rtree node $iNode.
|
| 54 |
+
#
|
| 55 |
+
proc rtree_node {db zTab iNode {iPrec 6}} {
|
| 56 |
+
set nDim [rtree_ndim $db $zTab]
|
| 57 |
+
set sql "
|
| 58 |
+
SELECT rtreenode($nDim, data) FROM ${zTab}_node WHERE nodeno = $iNode
|
| 59 |
+
"
|
| 60 |
+
set node [db one $sql]
|
| 61 |
+
|
| 62 |
+
set nCell [llength $node]
|
| 63 |
+
set nCoord [expr $nDim*2]
|
| 64 |
+
for {set ii 0} {$ii < $nCell} {incr ii} {
|
| 65 |
+
for {set jj 1} {$jj <= $nCoord} {incr jj} {
|
| 66 |
+
set newval [format "%.${iPrec}f" [lindex $node $ii $jj]]
|
| 67 |
+
lset node $ii $jj $newval
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
set node
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
proc rtree_mincells {db zTab} {
|
| 74 |
+
set n [$db one "select length(data) FROM ${zTab}_node LIMIT 1"]
|
| 75 |
+
set nMax [expr {int(($n-4)/(8+[rtree_ndim $db $zTab]*2*4))}]
|
| 76 |
+
return [expr {int($nMax/3)}]
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
# An integrity check for the rtree $zTab accessible via database
|
| 80 |
+
# connection $db.
|
| 81 |
+
#
|
| 82 |
+
proc rtree_check {db zTab} {
|
| 83 |
+
array unset ::checked
|
| 84 |
+
|
| 85 |
+
# Check each r-tree node.
|
| 86 |
+
set rc [catch {
|
| 87 |
+
rtree_node_check $db $zTab 1 [rtree_depth $db $zTab]
|
| 88 |
+
} msg]
|
| 89 |
+
if {$rc && $msg ne ""} { error $msg }
|
| 90 |
+
|
| 91 |
+
# Check that the _rowid and _parent tables have the right
|
| 92 |
+
# number of entries.
|
| 93 |
+
set nNode [$db one "SELECT count(*) FROM ${zTab}_node"]
|
| 94 |
+
set nRow [$db one "SELECT count(*) FROM ${zTab}"]
|
| 95 |
+
set nRowid [$db one "SELECT count(*) FROM ${zTab}_rowid"]
|
| 96 |
+
set nParent [$db one "SELECT count(*) FROM ${zTab}_parent"]
|
| 97 |
+
|
| 98 |
+
if {$nNode != ($nParent+1)} {
|
| 99 |
+
error "Wrong number of entries in ${zTab}_parent"
|
| 100 |
+
}
|
| 101 |
+
if {$nRow != $nRowid} {
|
| 102 |
+
error "Wrong number of entries in ${zTab}_rowid"
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
return $rc
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
proc rtree_node_check {db zTab iNode iDepth} {
|
| 109 |
+
if {[info exists ::checked($iNode)]} { error "Second ref to $iNode" }
|
| 110 |
+
set ::checked($iNode) 1
|
| 111 |
+
|
| 112 |
+
set node [rtree_node $db $zTab $iNode]
|
| 113 |
+
if {$iNode!=1 && [llength $node]==0} { error "No such node: $iNode" }
|
| 114 |
+
|
| 115 |
+
if {$iNode != 1 && [llength $node]<[rtree_mincells $db $zTab]} {
|
| 116 |
+
puts "Node $iNode: Has only [llength $node] cells"
|
| 117 |
+
error ""
|
| 118 |
+
}
|
| 119 |
+
if {$iNode == 1 && [llength $node]==1 && [rtree_depth $db $zTab]>0} {
|
| 120 |
+
set depth [rtree_depth $db $zTab]
|
| 121 |
+
puts "Node $iNode: Has only 1 child (tree depth is $depth)"
|
| 122 |
+
error ""
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
set nDim [expr {([llength [lindex $node 0]]-1)/2}]
|
| 126 |
+
|
| 127 |
+
if {$iDepth > 0} {
|
| 128 |
+
set d [expr $iDepth-1]
|
| 129 |
+
foreach cell $node {
|
| 130 |
+
set shouldbe [rtree_node_check $db $zTab [lindex $cell 0] $d]
|
| 131 |
+
if {$cell ne $shouldbe} {
|
| 132 |
+
puts "Node $iNode: Cell is: {$cell}, should be {$shouldbe}"
|
| 133 |
+
error ""
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
set mapping_table "${zTab}_parent"
|
| 139 |
+
set mapping_sql "SELECT parentnode FROM $mapping_table WHERE rowid = \$rowid"
|
| 140 |
+
if {$iDepth==0} {
|
| 141 |
+
set mapping_table "${zTab}_rowid"
|
| 142 |
+
set mapping_sql "SELECT nodeno FROM $mapping_table WHERE rowid = \$rowid"
|
| 143 |
+
}
|
| 144 |
+
foreach cell $node {
|
| 145 |
+
set rowid [lindex $cell 0]
|
| 146 |
+
set mapping [db one $mapping_sql]
|
| 147 |
+
if {$mapping != $iNode} {
|
| 148 |
+
puts "Node $iNode: $mapping_table entry for cell $rowid is $mapping"
|
| 149 |
+
error ""
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
set ret [list $iNode]
|
| 154 |
+
for {set ii 1} {$ii <= $nDim*2} {incr ii} {
|
| 155 |
+
set f [lindex $node 0 $ii]
|
| 156 |
+
foreach cell $node {
|
| 157 |
+
set f2 [lindex $cell $ii]
|
| 158 |
+
if {($ii%2)==1 && $f2<$f} {set f $f2}
|
| 159 |
+
if {($ii%2)==0 && $f2>$f} {set f $f2}
|
| 160 |
+
}
|
| 161 |
+
lappend ret $f
|
| 162 |
+
}
|
| 163 |
+
return $ret
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
proc rtree_dump {db zTab} {
|
| 167 |
+
set zRet ""
|
| 168 |
+
set nDim [expr {(([llength [$db eval "pragma table_info($zTab)"]]/6)-1)/2}]
|
| 169 |
+
set sql "SELECT nodeno, rtreenode($nDim, data) AS node FROM ${zTab}_node"
|
| 170 |
+
$db eval $sql {
|
| 171 |
+
append zRet [format "% -10s %s\n" $nodeno $node]
|
| 172 |
+
}
|
| 173 |
+
set zRet
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
proc rtree_nodetreedump {db zTab zIndent iDepth iNode} {
|
| 177 |
+
set ret ""
|
| 178 |
+
set node [rtree_node $db $zTab $iNode 1]
|
| 179 |
+
append ret [format "%-3d %s%s\n" $iNode $zIndent $node]
|
| 180 |
+
if {$iDepth>0} {
|
| 181 |
+
foreach cell $node {
|
| 182 |
+
set i [lindex $cell 0]
|
| 183 |
+
append ret [rtree_nodetreedump $db $zTab "$zIndent " [expr $iDepth-1] $i]
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
set ret
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
proc rtree_treedump {db zTab} {
|
| 190 |
+
set d [rtree_depth $db $zTab]
|
| 191 |
+
rtree_nodetreedump $db $zTab "" $d 1
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
proc do_rtree_integrity_test {tn tbl} {
|
| 195 |
+
uplevel [list do_execsql_test $tn.1 "SELECT rtreecheck('$tbl')" ok]
|
| 196 |
+
uplevel [list do_execsql_test $tn.2 "PRAG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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2017 August 17
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
#
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source $testdir/tester.tcl
|
| 19 |
+
set testprefix rtreecheck
|
| 20 |
+
|
| 21 |
+
ifcapable !rtree {
|
| 22 |
+
finish_test
|
| 23 |
+
return
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
proc swap_int32 {blob i0 i1} {
|
| 27 |
+
binary scan $blob I* L
|
| 28 |
+
|
| 29 |
+
set a [lindex $L $i0]
|
| 30 |
+
set b [lindex $L $i1]
|
| 31 |
+
|
| 32 |
+
lset L $i0 $b
|
| 33 |
+
lset L $i1 $a
|
| 34 |
+
|
| 35 |
+
binary format I* $L
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
proc set_int32 {blob idx val} {
|
| 39 |
+
binary scan $blob I* L
|
| 40 |
+
lset L $idx $val
|
| 41 |
+
binary format I* $L
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
do_catchsql_test 1.0 {
|
| 45 |
+
SELECT rtreecheck();
|
| 46 |
+
} {1 {wrong number of arguments to function rtreecheck()}}
|
| 47 |
+
|
| 48 |
+
do_catchsql_test 1.1 {
|
| 49 |
+
SELECT rtreecheck(0,0,0);
|
| 50 |
+
} {1 {wrong number of arguments to function rtreecheck()}}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
proc setup_simple_db {{module rtree}} {
|
| 54 |
+
reset_db
|
| 55 |
+
db func swap_int32 swap_int32
|
| 56 |
+
execsql "
|
| 57 |
+
CREATE VIRTUAL TABLE r1 USING $module (id, x1, x2, y1, y2);
|
| 58 |
+
INSERT INTO r1 VALUES(1, 5, 5, 5, 5); -- 3
|
| 59 |
+
INSERT INTO r1 VALUES(2, 6, 6, 6, 6); -- 9
|
| 60 |
+
INSERT INTO r1 VALUES(3, 7, 7, 7, 7); -- 15
|
| 61 |
+
INSERT INTO r1 VALUES(4, 8, 8, 8, 8); -- 21
|
| 62 |
+
INSERT INTO r1 VALUES(5, 9, 9, 9, 9); -- 27
|
| 63 |
+
"
|
| 64 |
+
sqlite3_db_config db DEFENSIVE 0
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
setup_simple_db
|
| 68 |
+
do_execsql_test 2.1 {
|
| 69 |
+
SELECT rtreecheck('r1')
|
| 70 |
+
} {ok}
|
| 71 |
+
|
| 72 |
+
do_execsql_test 2.2 {
|
| 73 |
+
UPDATE r1_node SET data = swap_int32(data, 3, 9);
|
| 74 |
+
UPDATE r1_node SET data = swap_int32(data, 23, 29);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
do_execsql_test 2.3 {
|
| 78 |
+
SELECT rtreecheck('r1')
|
| 79 |
+
} {{Dimension 0 of cell 0 on node 1 is corrupt
|
| 80 |
+
Dimension 1 of cell 3 on node 1 is corrupt}}
|
| 81 |
+
do_execsql_test 2.3b {
|
| 82 |
+
PRAGMA integrity_check;
|
| 83 |
+
} {{In RTree main.r1:
|
| 84 |
+
Dimension 0 of cell 0 on node 1 is corrupt
|
| 85 |
+
Dimension 1 of cell 3 on node 1 is corrupt}}
|
| 86 |
+
|
| 87 |
+
setup_simple_db
|
| 88 |
+
do_execsql_test 2.4 {
|
| 89 |
+
DELETE FROM r1_rowid WHERE rowid = 3;
|
| 90 |
+
SELECT rtreecheck('r1')
|
| 91 |
+
} {{Mapping (3 -> 1) missing from %_rowid table
|
| 92 |
+
Wrong number of entries in %_rowid table - expected 5, actual 4}}
|
| 93 |
+
do_execsql_test 2.4b {
|
| 94 |
+
PRAGMA integrity_check
|
| 95 |
+
} {{In RTree main.r1:
|
| 96 |
+
Mapping (3 -> 1) missing from %_rowid table
|
| 97 |
+
Wrong number of entries in %_rowid table - expected 5, actual 4}}
|
| 98 |
+
|
| 99 |
+
setup_simple_db
|
| 100 |
+
do_execsql_test 2.5 {
|
| 101 |
+
UPDATE r1_rowid SET nodeno=2 WHERE rowid=3;
|
| 102 |
+
SELECT rtreecheck('r1')
|
| 103 |
+
} {{Found (3 -> 2) in %_rowid table, expected (3 -> 1)}}
|
| 104 |
+
do_execsql_test 2.5b {
|
| 105 |
+
PRAGMA integrity_check
|
| 106 |
+
} {{In RTree main.r1:
|
| 107 |
+
Found (3 -> 2) in %_rowid table, expected (3 -> 1)}}
|
| 108 |
+
|
| 109 |
+
reset_db
|
| 110 |
+
do_execsql_test 3.0 {
|
| 111 |
+
CREATE VIRTUAL TABLE r1 USING rtree_i32(id, x1, x2);
|
| 112 |
+
INSERT INTO r1 VALUES(1, 0x7FFFFFFF*-1, 0x7FFFFFFF);
|
| 113 |
+
INSERT INTO r1 VALUES(2, 0x7FFFFFFF*-1, 5);
|
| 114 |
+
INSERT INTO r1 VALUES(3, -5, 5);
|
| 115 |
+
INSERT INTO r1 VALUES(4, 5, 0x11111111);
|
| 116 |
+
INSERT INTO r1 VALUES(5, 5, 0x00800000);
|
| 117 |
+
INSERT INTO r1 VALUES(6, 5, 0x00008000);
|
| 118 |
+
INSERT INTO r1 VALUES(7, 5, 0x00000080);
|
| 119 |
+
INSERT INTO r1 VALUES(8, 5, 0x40490fdb);
|
| 120 |
+
INSERT INTO r1 VALUES(9, 0x7f800000, 0x7f900000);
|
| 121 |
+
SELECT rtreecheck('r1');
|
| 122 |
+
PRAGMA integrity_check;
|
| 123 |
+
} {ok ok}
|
| 124 |
+
|
| 125 |
+
do_execsql_test 3.1 {
|
| 126 |
+
CREATE VIRTUAL TABLE r2 USING rtree_i32(id, x1, x2);
|
| 127 |
+
INSERT INTO r2 VALUES(2, -1*(1<<31), -1*(1<<31)+5);
|
| 128 |
+
SELECT rtreecheck('r2');
|
| 129 |
+
PRAGMA integrity_check;
|
| 130 |
+
} {ok ok}
|
| 131 |
+
|
| 132 |
+
sqlite3_db_config db DEFENSIVE 0
|
| 133 |
+
do_execsql_test 3.2 {
|
| 134 |
+
BEGIN;
|
| 135 |
+
UPDATE r2_node SET data = X'123456';
|
| 136 |
+
SELECT rtreecheck('r2')!='ok';
|
| 137 |
+
} {1}
|
| 138 |
+
|
| 139 |
+
do_execsql_test 3.3 {
|
| 140 |
+
ROLLBACK;
|
| 141 |
+
UPDATE r2_node SET data = X'00001234';
|
| 142 |
+
SELECT rtreecheck('r2')!='ok';
|
| 143 |
+
} {1}
|
| 144 |
+
do_execsql_test 3.4 {
|
| 145 |
+
PRAGMA integrity_check;
|
| 146 |
+
} {{In RTree main.r2:
|
| 147 |
+
Node 1 is too small for cell count of 4660 (4 bytes)
|
| 148 |
+
Wrong number of entries in %_rowid table - expected 0, actual 1}}
|
| 149 |
+
|
| 150 |
+
do_execsql_test 4.0 {
|
| 151 |
+
CREATE TABLE notanrtree(i);
|
| 152 |
+
SELECT rtreecheck('notanrtree');
|
| 153 |
+
} {{Schema corrupt or not an rtree}}
|
| 154 |
+
|
| 155 |
+
#-------------------------------------------------------------------------
|
| 156 |
+
#
|
| 157 |
+
reset_db
|
| 158 |
+
db func set_int32 set_int32
|
| 159 |
+
do_execsql_test 5.0 {
|
| 160 |
+
CREATE VIRTUAL TABLE r3 USING rtree_i32(id, x1, x2, y1, y2);
|
| 161 |
+
WITH x(i) AS (
|
| 162 |
+
SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<1000
|
| 163 |
+
)
|
| 164 |
+
INSERT INTO r3 SELECT i, i, i, i, i FROM x;
|
| 165 |
+
}
|
| 166 |
+
sqlite3_db_config db DEFENSIVE 0
|
| 167 |
+
do_execsql_test 5.1 {
|
| 168 |
+
BEGIN;
|
| 169 |
+
UPDATE r3_node SET data = set_int32(data, 3, 5000);
|
| 170 |
+
UPDATE r3_node SET data = set_int32(data, 4, 5000);
|
| 171 |
+
SELECT rtreecheck('r3')=='ok'
|
| 172 |
+
} 0
|
| 173 |
+
do_execsql_test 5.2 {
|
| 174 |
+
ROLLBACK;
|
| 175 |
+
BEGIN;
|
| 176 |
+
UPDATE r3_node SET data = set_int32(data, 3, 0);
|
| 177 |
+
UPDATE r3_node SET data = set_int32(data, 4, 0);
|
| 178 |
+
SELECT rtreecheck('r3')=='ok'
|
| 179 |
+
} 0
|
| 180 |
+
|
| 181 |
+
#-------------------------------------------------------------------------
|
| 182 |
+
# dbsqlfuzz 4a1399d39bf9feccbf6b290da51d3b30103a4bf6
|
| 183 |
+
#
|
| 184 |
+
reset_db
|
| 185 |
+
do_execsql_test 6.0 {
|
| 186 |
+
PRAGMA encoding = 'utf16';
|
| 187 |
+
CREATE VIRTUAL TABLE t1 USING rtree(id, x, y);
|
| 188 |
+
}
|
| 189 |
+
db close
|
| 190 |
+
sqlite3 db test.db
|
| 191 |
+
|
| 192 |
+
if {[permutation]=="inmemory_journal"} {
|
| 193 |
+
# This doesn't hit an SQLITE_LOCKED in this permutation as the schema
|
| 194 |
+
# has already been loaded.
|
| 195 |
+
do_catchsql_test 6.1.inmemory_journal {
|
| 196 |
+
SELECT ( 'elvis' IN(SELECT rtreecheck('t1')) ) FROM (SELECT 1) GROUP BY 1;
|
| 197 |
+
} {0 0}
|
| 198 |
+
} else {
|
| 199 |
+
do_catchsql_test 6.1 {
|
| 200 |
+
SELECT ( 'elvis' IN(SELECT rtreecheck('t1')) ) FROM (SELECT 1) GROUP BY 1;
|
| 201 |
+
} {0 0}
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreecirc.test
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2018 Dec 22
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#*************************************************************************
|
| 11 |
+
# This file implements regression tests for SQLite library. The
|
| 12 |
+
# focus of this script is testing the FTS5 module.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
set testprefix rtreecirc
|
| 21 |
+
|
| 22 |
+
ifcapable !rtree {
|
| 23 |
+
finish_test
|
| 24 |
+
return
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
do_execsql_test 1.0 {
|
| 28 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2, y1, y2);
|
| 29 |
+
SELECT name FROM sqlite_master ORDER BY 1;
|
| 30 |
+
} {
|
| 31 |
+
rt rt_node rt_parent rt_rowid
|
| 32 |
+
}
|
| 33 |
+
db_save_and_close
|
| 34 |
+
|
| 35 |
+
foreach {tn schema sql} {
|
| 36 |
+
1 {
|
| 37 |
+
CREATE TRIGGER tr1 AFTER INSERT ON rt_node BEGIN
|
| 38 |
+
SELECT * FROM rt;
|
| 39 |
+
END;
|
| 40 |
+
} {
|
| 41 |
+
INSERT INTO rt VALUES(1, 2, 3, 4, 5);
|
| 42 |
+
}
|
| 43 |
+
2 {
|
| 44 |
+
CREATE TRIGGER tr1 AFTER INSERT ON rt_parent BEGIN
|
| 45 |
+
SELECT * FROM rt;
|
| 46 |
+
END;
|
| 47 |
+
} {
|
| 48 |
+
INSERT INTO rt VALUES(1, 2, 3, 4, 5);
|
| 49 |
+
}
|
| 50 |
+
3 {
|
| 51 |
+
CREATE TRIGGER tr1 AFTER INSERT ON rt_rowid BEGIN
|
| 52 |
+
SELECT * FROM rt;
|
| 53 |
+
END;
|
| 54 |
+
} {
|
| 55 |
+
INSERT INTO rt VALUES(1, 2, 3, 4, 5);
|
| 56 |
+
}
|
| 57 |
+
} {
|
| 58 |
+
db_restore_and_reopen
|
| 59 |
+
do_execsql_test 1.1.$tn.1 $schema
|
| 60 |
+
do_catchsql_test 1.1.$tn.2 $sql {1 {no such table: main.rt}}
|
| 61 |
+
db close
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
finish_test
|
| 66 |
+
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/r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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2021 September 13
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# The focus of this file is testing the r-tree extension.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
set testprefix rtreedoc
|
| 21 |
+
|
| 22 |
+
ifcapable !rtree {
|
| 23 |
+
finish_test
|
| 24 |
+
return
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
# This command returns the number of columns in table $tbl within the
|
| 28 |
+
# database opened by database handle $db
|
| 29 |
+
proc column_count {db tbl} {
|
| 30 |
+
set nCol 0
|
| 31 |
+
$db eval "PRAGMA table_info = $tbl" { incr nCol }
|
| 32 |
+
return $nCol
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
proc column_name_list {db tbl} {
|
| 36 |
+
set lCol [list]
|
| 37 |
+
$db eval "PRAGMA table_info = $tbl" {
|
| 38 |
+
lappend lCol $name
|
| 39 |
+
}
|
| 40 |
+
return $lCol
|
| 41 |
+
}
|
| 42 |
+
unset -nocomplain res
|
| 43 |
+
|
| 44 |
+
#-------------------------------------------------------------------------
|
| 45 |
+
#-------------------------------------------------------------------------
|
| 46 |
+
# Section 3 of documentation.
|
| 47 |
+
#-------------------------------------------------------------------------
|
| 48 |
+
#-------------------------------------------------------------------------
|
| 49 |
+
set testprefix rtreedoc-1
|
| 50 |
+
|
| 51 |
+
# EVIDENCE-OF: R-15060-13876 A 1-dimensional R*Tree thus has 3 columns.
|
| 52 |
+
do_execsql_test 1.1.1 { CREATE VIRTUAL TABLE rt1 USING rtree(id, x1,x2) }
|
| 53 |
+
do_test 1.1.2 { column_count db rt1 } 3
|
| 54 |
+
|
| 55 |
+
# EVIDENCE-OF: R-19353-19546 A 2-dimensional R*Tree has 5 columns.
|
| 56 |
+
do_execsql_test 1.2.1 { CREATE VIRTUAL TABLE rt2 USING rtree(id,x1,x2, y1,y2) }
|
| 57 |
+
do_test 1.2.2 { column_count db rt2 } 5
|
| 58 |
+
|
| 59 |
+
# EVIDENCE-OF: R-13615-19528 A 3-dimensional R*Tree has 7 columns.
|
| 60 |
+
do_execsql_test 1.3.1 {
|
| 61 |
+
CREATE VIRTUAL TABLE rt3 USING rtree(id, x1,x2, y1,y2, z1,z2)
|
| 62 |
+
}
|
| 63 |
+
do_test 1.3.2 { column_count db rt3 } 7
|
| 64 |
+
|
| 65 |
+
# EVIDENCE-OF: R-53479-41922 A 4-dimensional R*Tree has 9 columns.
|
| 66 |
+
do_execsql_test 1.4.1 {
|
| 67 |
+
CREATE VIRTUAL TABLE rt4 USING rtree(id, x1,x2, y1,y2, z1,z2, v1,v2)
|
| 68 |
+
}
|
| 69 |
+
do_test 1.4.2 { column_count db rt4 } 9
|
| 70 |
+
|
| 71 |
+
# EVIDENCE-OF: R-13981-28768 And a 5-dimensional R*Tree has 11 columns.
|
| 72 |
+
do_execsql_test 1.5.1 {
|
| 73 |
+
CREATE VIRTUAL TABLE rt5 USING rtree(id, x1,x2, y1,y2, z1,z2, v1,v2, w1,w2)
|
| 74 |
+
}
|
| 75 |
+
do_test 1.5.2 { column_count db rt5 } 11
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
# Attempt to create r-tree tables with 6 and 7 dimensions.
|
| 79 |
+
#
|
| 80 |
+
# EVIDENCE-OF: R-61533-25862 The SQLite R*Tree implementation does not
|
| 81 |
+
# support R*Trees wider than 5 dimensions.
|
| 82 |
+
do_catchsql_test 2.1.1 {
|
| 83 |
+
CREATE VIRTUAL TABLE rt6 USING rtree(
|
| 84 |
+
id, x1,x2, y1,y2, z1,z2, v1,v2, w1,w2, a1,a2
|
| 85 |
+
)
|
| 86 |
+
} {1 {Too many columns for an rtree table}}
|
| 87 |
+
do_catchsql_test 2.1.2 {
|
| 88 |
+
CREATE VIRTUAL TABLE rt6 USING rtree(
|
| 89 |
+
id, x1,x2, y1,y2, z1,z2, v1,v2, w1,w2, a1,a2, b1, b2
|
| 90 |
+
)
|
| 91 |
+
} {1 {Too many columns for an rtree table}}
|
| 92 |
+
|
| 93 |
+
# Attempt to create r-tree tables with no columns, a single column, or
|
| 94 |
+
# an even number of columns. This and the tests above establish that:
|
| 95 |
+
#
|
| 96 |
+
# EVIDENCE-OF: R-16717-50504 Each R*Tree index is a virtual table with
|
| 97 |
+
# an odd number of columns between 3 and 11.
|
| 98 |
+
foreach {tn cols err} {
|
| 99 |
+
1 "" "Too few columns for an rtree table"
|
| 100 |
+
2 "x" "Too few columns for an rtree table"
|
| 101 |
+
3 "x,y" "Too few columns for an rtree table"
|
| 102 |
+
4 "a,b,c,d" "Wrong number of columns for an rtree table"
|
| 103 |
+
5 "a,b,c,d,e,f" "Wrong number of columns for an rtree table"
|
| 104 |
+
6 "a,b,c,d,e,f,g,h" "Wrong number of columns for an rtree table"
|
| 105 |
+
7 "a,b,c,d,e,f,g,h,i,j" "Wrong number of columns for an rtree table"
|
| 106 |
+
8 "a,b,c,d,e,f,g,h,i,j,k,l" "Too many columns for an rtree table"
|
| 107 |
+
} {
|
| 108 |
+
do_catchsql_test 3.$tn "
|
| 109 |
+
CREATE VIRTUAL TABLE xyz USING rtree($cols)
|
| 110 |
+
" [list 1 $err]
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
# EVIDENCE-OF: R-17874-21123 The first column of an SQLite R*Tree is
|
| 114 |
+
# similar to an integer primary key column of a normal SQLite table.
|
| 115 |
+
#
|
| 116 |
+
# EVIDENCE-OF: R-46619-65417 The first column is always a 64-bit signed
|
| 117 |
+
# integer primary key.
|
| 118 |
+
#
|
| 119 |
+
# EVIDENCE-OF: R-46866-24036 It may only store a 64-bit signed integer
|
| 120 |
+
# value.
|
| 121 |
+
#
|
| 122 |
+
# EVIDENCE-OF: R-00250-64843 If an attempt is made to insert any other
|
| 123 |
+
# non-integer value into this column, the r-tree module silently
|
| 124 |
+
# converts it to an integer before writing it into the database.
|
| 125 |
+
#
|
| 126 |
+
do_execsql_test 4.0 { CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2) }
|
| 127 |
+
foreach {tn val res} {
|
| 128 |
+
1 10 10
|
| 129 |
+
2 10.6 10
|
| 130 |
+
3 10.99 10
|
| 131 |
+
4 '123' 123
|
| 132 |
+
5 X'313233' 123
|
| 133 |
+
6 -10 -10
|
| 134 |
+
7 9223372036854775807 9223372036854775807
|
| 135 |
+
8 -9223372036854775808 -9223372036854775808
|
| 136 |
+
9 '9223372036854775807' 9223372036854775807
|
| 137 |
+
10 '-9223372036854775808' -9223372036854775808
|
| 138 |
+
11 'hello+world' 0
|
| 139 |
+
} {
|
| 140 |
+
do_execsql_test 4.$tn.1 "
|
| 141 |
+
DELETE FROM rt;
|
| 142 |
+
INSERT INTO rt VALUES($val, 10, 20);
|
| 143 |
+
"
|
| 144 |
+
do_execsql_test 4.$tn.2 {
|
| 145 |
+
SELECT typeof(id), id FROM rt
|
| 146 |
+
} [list integer $res]
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
# EVIDENCE-OF: R-15544-29079 Inserting a NULL value into this column
|
| 150 |
+
# causes SQLite to automatically generate a new unique primary key
|
| 151 |
+
# value.
|
| 152 |
+
do_execsql_test 5.1 {
|
| 153 |
+
DELETE FROM rt;
|
| 154 |
+
INSERT INTO rt VALUES(100, 1, 2);
|
| 155 |
+
INSERT INTO rt VALUES(NULL, 1, 2);
|
| 156 |
+
}
|
| 157 |
+
do_execsql_test 5.2 { SELECT id FROM rt } {100 101}
|
| 158 |
+
do_execsql_test 5.3 {
|
| 159 |
+
INSERT INTO rt VALUES(9223372036854775807, 1, 2);
|
| 160 |
+
INSERT INTO rt VALUES(NULL, 1, 2);
|
| 161 |
+
}
|
| 162 |
+
do_execsql_test 5.4 {
|
| 163 |
+
SELECT count(*) FROM rt;
|
| 164 |
+
} 4
|
| 165 |
+
do_execsql_test 5.5 {
|
| 166 |
+
SELECT id IN(100, 101, 9223372036854775807) FROM rt ORDER BY 1;
|
| 167 |
+
} {0 1 1 1}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
# EVIDENCE-OF: R-64317-38978 The other columns are pairs, one pair per
|
| 171 |
+
# dimension, containing the minimum and maximum values for that
|
| 172 |
+
# dimension, respectively.
|
| 173 |
+
#
|
| 174 |
+
# Show this by observing that attempts to insert rows with max>min fail.
|
| 175 |
+
#
|
| 176 |
+
do_execsql_test 6.1 {
|
| 177 |
+
CREATE VIRTUAL TABLE rtF USING rtree(id, x1,x2, y1,y2);
|
| 178 |
+
CREATE VIRTUAL TABLE rtI USING rtree_i32(id, x1,x2, y1,y2, z1,z2);
|
| 179 |
+
}
|
| 180 |
+
foreach {tn x1 x2 y1 y2 ok} {
|
| 181 |
+
1 10.3 20.1 30.9 40.2 1
|
| 182 |
+
2 10.3 20.1 40.2 30.9 0
|
| 183 |
+
3 10.3 30.9 20.1 40.2 1
|
| 184 |
+
4 20.1 10.3 30.9 40.2 0
|
| 185 |
+
} {
|
| 186 |
+
do_test 6.2.$tn {
|
| 187 |
+
catch { db eval { INSERT INTO rtF VALUES(NULL, $x1, $x2, $y1, $y2) } }
|
| 188 |
+
} [expr $ok==0]
|
| 189 |
+
}
|
| 190 |
+
foreach {tn x1 x2 y1 y2 z1 z2 ok} {
|
| 191 |
+
1 10 20 30 40 50 60 1
|
| 192 |
+
2 10 20 30 40 60 50 0
|
| 193 |
+
3 10 20 30 50 40 60 1
|
| 194 |
+
4 10 20 40 30 50 60 0
|
| 195 |
+
5 10 30 20 40 50 60 1
|
| 196 |
+
6 20 10 30 40 50 60 0
|
| 197 |
+
} {
|
| 198 |
+
do_test 6.3.$tn {
|
| 199 |
+
catch { db eval { INSERT INTO rtI VALUES(NULL,$x1,$x2,$y1,$y2,$z1,$z2) } }
|
| 200 |
+
} [expr $ok==0]
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
# EVIDENCE-OF: R-08054-15429 The min/max-value pair columns are stored
|
| 204 |
+
# as 32-bit floating point values for "rtree" virtual tables or as
|
| 205 |
+
# 32-bit signed integers in "rtree_i32" virtual tables.
|
| 206 |
+
#
|
| 207 |
+
# Show this by showing that large values are rounded in ways consistent
|
| 208 |
+
# with those two 32-bit types.
|
| 209 |
+
do_execsql_test 7.1 {
|
| 210 |
+
DELETE FROM rtI;
|
| 211 |
+
INSERT INTO rtI VALUES(
|
| 212 |
+
0, -2000000000, 2000000000, -5000000000, 5000000000,
|
| 213 |
+
-1000000000000, 10000000000000
|
| 214 |
+
);
|
| 215 |
+
SELECT * FROM rtI;
|
| 216 |
+
} {
|
| 217 |
+
0 -2000000000 2000000000 -705032704 705032704 727379968 1316134912
|
| 218 |
+
}
|
| 219 |
+
do_execsql_test 7.2 {
|
| 220 |
+
DELETE FROM rtF;
|
| 221 |
+
INSERT INTO rtF VALUES(
|
| 222 |
+
0, -2000000000, 2000000000,
|
| 223 |
+
-1000000000000, 10000000000000
|
| 224 |
+
);
|
| 225 |
+
SELECT * FROM rtF;
|
| 226 |
+
} {
|
| 227 |
+
0 -2000000000.0 2000000000.0 -1000000126976.0 10000000876544.0
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
# EVIDENCE-OF: R-47371-54529 Unlike regular SQLite tables which can
|
| 231 |
+
# store data in a variety of datatypes and formats, the R*Tree rigidly
|
| 232 |
+
# enforce these storage types.
|
| 233 |
+
#
|
| 234 |
+
# EVIDENCE-OF: R-39153-14977 If any other type of value is inserted into
|
| 235 |
+
# such a column, the r-tree module silently converts it to the required
|
| 236 |
+
# type before writing the new record to the database.
|
| 237 |
+
do_execsql_test 8.1 {
|
| 238 |
+
DELETE FROM rtI;
|
| 239 |
+
INSERT INTO rtI VALUES(
|
| 240 |
+
1, 'hello world', X'616263', NULL, 44.5, 1000, 9999.9999
|
| 241 |
+
);
|
| 242 |
+
SELECT * FROM rtI;
|
| 243 |
+
} {
|
| 244 |
+
1 0 0 0 44 1000 9999
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
do_execsql_test 8.2 {
|
| 248 |
+
SELECT
|
| 249 |
+
typeof(x1), typeof(x2), typeof(y1), typeof(y2), typeof(z1), typeof(z2)
|
| 250 |
+
FROM rtI
|
| 251 |
+
} {integer integer integer integer integer integer}
|
| 252 |
+
|
| 253 |
+
do_execsql_test 8.3 {
|
| 254 |
+
DELETE FROM rtF;
|
| 255 |
+
INSERT INTO rtF VALUES(
|
| 256 |
+
1, 'hello world', X'616263', NULL, 44
|
| 257 |
+
);
|
| 258 |
+
SELECT * FROM rtF;
|
| 259 |
+
} {
|
| 260 |
+
1 0.0 0.0 0.0 44.0
|
| 261 |
+
}
|
| 262 |
+
do_execsql_test 8.4 {
|
| 263 |
+
SELECT
|
| 264 |
+
typeof(x1), typeof(x2), typeof(y1), typeof(y2)
|
| 265 |
+
FROM rtF
|
| 266 |
+
} {real real real real}
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
#-------------------------------------------------------------------------
|
| 272 |
+
#-------------------------------------------------------------------------
|
| 273 |
+
# Section 3.1 of documentation.
|
| 274 |
+
#-------------------------------------------------------------------------
|
| 275 |
+
#-------------------------------------------------------------------------
|
| 276 |
+
set testprefix rtreedoc-2
|
| 277 |
+
reset_db
|
| 278 |
+
|
| 279 |
+
foreach {tn name clist} {
|
| 280 |
+
1 t1 "id x1 x2"
|
| 281 |
+
2 t2 "id x1 x2 y1 y2 z1 z2"
|
| 282 |
+
} {
|
| 283 |
+
# EVIDENCE-OF: R-15142-18077 A new R*Tree index is created as follows:
|
| 284 |
+
# CREATE VIRTUAL TABLE <name> USING rtree(<column-names>);
|
| 285 |
+
do_execsql_test 1.$tn.1 "
|
| 286 |
+
CREATE VIRTUAL TABLE $name USING rtree([join $clist ,])
|
| 287 |
+
"
|
| 288 |
+
|
| 289 |
+
# EVIDENCE-OF: R-51698-09302 The <name> is the name your
|
| 290 |
+
# application chooses for the R*Tree index and <column-names> is a
|
| 291 |
+
# comma separated list of between 3 and 11 columns.
|
| 292 |
+
do_test 1.$tn.2 { column_name_list db $name } [list {*}$clist]
|
| 293 |
+
|
| 294 |
+
# EVIDENCE-OF: R-50130-53472 The virtual <name> table creates
|
| 295 |
+
# three shadow tables to actually store its content.
|
| 296 |
+
do_execsql_test 1.$tn.3 {
|
| 297 |
+
SELECT count(*) FROM sqlite_schema
|
| 298 |
+
} [expr 1+3]
|
| 299 |
+
|
| 300 |
+
# EVIDENCE-OF: R-45256-35998 The names of these shadow tables are:
|
| 301 |
+
# <name>_node <name>_rowid <name>_parent
|
| 302 |
+
do_execsql_test 1.$tn.4 {
|
| 303 |
+
SELECT name FROM sqlite_schema WHERE rootpage>0 ORDER BY 1
|
| 304 |
+
} [list ${name}_node ${name}_parent ${name}_rowid]
|
| 305 |
+
|
| 306 |
+
do_execsql_test 1.$tn.5 "DROP TABLE $name"
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
# EVIDENCE-OF: R-11241-54478 As an example, consider creating a
|
| 310 |
+
# two-dimensional R*Tree index for use in spatial queries: CREATE
|
| 311 |
+
# VIRTUAL TABLE demo_index USING rtree( id, -- Integer primary key minX,
|
| 312 |
+
# maxX, -- Minimum and maximum X coordinate minY, maxY -- Minimum and
|
| 313 |
+
# maximum Y coordinate );
|
| 314 |
+
do_execsql_test 2.0 {
|
| 315 |
+
CREATE VIRTUAL TABLE demo_index USING rtree(
|
| 316 |
+
id, -- Integer primary key
|
| 317 |
+
minX, maxX, -- Minimum and maximum X coordinate
|
| 318 |
+
minY, maxY -- Minimum and maximum Y coordinate
|
| 319 |
+
);
|
| 320 |
+
INSERT INTO demo_index VALUES(1,2,3,4,5);
|
| 321 |
+
INSERT INTO demo_index VALUES(6,7,8,9,10);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
# EVIDENCE-OF: R-02287-33529 The shadow tables are ordinary SQLite data
|
| 325 |
+
# tables.
|
| 326 |
+
#
|
| 327 |
+
# Ordinary tables. With ordinary sqlite_schema entries.
|
| 328 |
+
do_execsql_test 2.1 {
|
| 329 |
+
SELECT type, name, sql FROM sqlite_schema WHERE sql NOT LIKE '%virtual%'
|
| 330 |
+
} {
|
| 331 |
+
table demo_index_rowid
|
| 332 |
+
{CREATE TABLE "demo_index_rowid"(rowid INTEGER PRIMARY KEY,nodeno)}
|
| 333 |
+
table demo_index_node
|
| 334 |
+
{CREATE TABLE "demo_index_node"(nodeno INTEGER PRIMARY KEY,data)}
|
| 335 |
+
table demo_index_parent
|
| 336 |
+
{CREATE TABLE "demo_index_parent"(nodeno INTEGER PRIMARY KEY,parentnode)}
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
# EVIDENCE-OF: R-10863-13089 You can query them directly if you like,
|
| 340 |
+
# though this unlikely to reveal anything particularly useful.
|
| 341 |
+
#
|
| 342 |
+
# Querying:
|
| 343 |
+
do_execsql_test 2.2 {
|
| 344 |
+
SELECT count(*) FROM demo_index_node;
|
| 345 |
+
SELECT count(*) FROM demo_index_rowid;
|
| 346 |
+
SELECT count(*) FROM demo_index_parent;
|
| 347 |
+
} {1 2 0}
|
| 348 |
+
|
| 349 |
+
# EVIDENCE-OF: R-05650-46070 And you can UPDATE, DELETE, INSERT or even
|
| 350 |
+
# DROP the shadow tables, though doing so will corrupt your R*Tree
|
| 351 |
+
# index.
|
| 352 |
+
do_execsql_test 2.3 {
|
| 353 |
+
DELETE FROM demo_index_rowid;
|
| 354 |
+
INSERT INTO demo_index_parent VALUES(2, 3);
|
| 355 |
+
UPDATE demo_index_node SET data = 'hello world'
|
| 356 |
+
}
|
| 357 |
+
do_catchsql_test 2.4 {
|
| 358 |
+
SELECT * FROM demo_index WHERE minX>10 AND maxX<30
|
| 359 |
+
} {1 {database disk image is malformed}}
|
| 360 |
+
do_execsql_test 2.5 {
|
| 361 |
+
DROP TABLE demo_index_rowid
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
#-------------------------------------------------------------------------
|
| 365 |
+
#-------------------------------------------------------------------------
|
| 366 |
+
# Section 3.1.1 of documentation.
|
| 367 |
+
#-------------------------------------------------------------------------
|
| 368 |
+
#-------------------------------------------------------------------------
|
| 369 |
+
set testprefix rtreedoc-3
|
| 370 |
+
reset_db
|
| 371 |
+
|
| 372 |
+
# EVIDENCE-OF: R-44253-50720 In the argments to "rtree" in the CREATE
|
| 373 |
+
# VIRTUAL TABLE statement, the names of the columns are taken from the
|
| 374 |
+
# first token of each argument. All subsequent tokens within each
|
| 375 |
+
# argument are silently ignored.
|
| 376 |
+
#
|
| 377 |
+
foreach {tn cols lCol} {
|
| 378 |
+
1 {(id TEXT, x1 TEXT, x2 TEXT, y1 TEXT, y2 TEXT)} {id x1 x2 y1 y2}
|
| 379 |
+
2 {(id TEXT, x1 UNIQUE, x2 TEXT, y1 NOT NULL, y2 TEXT)} {id x1 x2 y1 y2}
|
| 380 |
+
3 {(id, x1 DEFAULT 4, x2 TEXT, y1 NOT NULL, y2 TEXT)} {id x1 x2 y1 y2}
|
| 381 |
+
} {
|
| 382 |
+
do_execsql_test 1.$tn.1 " CREATE VIRTUAL TABLE abc USING rtree $cols "
|
| 383 |
+
do_test 1.$tn.2 { column_name_list db abc } $lCol
|
| 384 |
+
|
| 385 |
+
# EVIDENCE-OF: R-52032-06717 This means, for example, that if you try to
|
| 386 |
+
# give a column a type affinity or add a constraint such as UNIQUE or
|
| 387 |
+
# NOT NULL or DEFAULT to a column, those extra tokens are accepted as
|
| 388 |
+
# valid, but they do not change the behavior of the rtree.
|
| 389 |
+
|
| 390 |
+
# Show there are no UNIQUE constraints
|
| 391 |
+
do_execsql_test 1.$tn.3 {
|
| 392 |
+
INSERT INTO abc VALUES(1, 10.0, 20.0, 10.0, 20.0);
|
| 393 |
+
INSERT INTO abc VALUES(2, 10.0, 20.0, 10.0, 20.0);
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
# Show the default values have not been modified
|
| 397 |
+
do_execsql_test 1.$tn.4 {
|
| 398 |
+
INSERT INTO abc DEFAULT VALUES;
|
| 399 |
+
SELECT * FROM abc WHERE rowid NOT IN (1,2)
|
| 400 |
+
} {3 0.0 0.0 0.0 0.0}
|
| 401 |
+
|
| 402 |
+
# Show that there are no NOT NULL constraints
|
| 403 |
+
do_execsql_test 1.$tn.5 {
|
| 404 |
+
INSERT INTO abc VALUES(NULL, NULL, NULL, NULL, NULL);
|
| 405 |
+
SELECT * FROM abc WHERE rowid NOT IN (1,2,3)
|
| 406 |
+
} {4 0.0 0.0 0.0 0.0}
|
| 407 |
+
|
| 408 |
+
# EVIDENCE-OF: R-06893-30579 In an RTREE virtual table, the first column
|
| 409 |
+
# always has a type affinity of INTEGER and all other data columns have
|
| 410 |
+
# a type affinity of REAL.
|
| 411 |
+
do_execsql_test 1.$tn.5 {
|
| 412 |
+
INSERT INTO abc VALUES('5', '5', '5', '5', '5');
|
| 413 |
+
SELECT * FROM abc WHERE rowid NOT IN (1,2,3,4)
|
| 414 |
+
} {5 5.0 5.0 5.0 5.0}
|
| 415 |
+
do_execsql_test 1.$tn.6 {
|
| 416 |
+
SELECT type FROM pragma_table_info('abc') ORDER BY cid
|
| 417 |
+
} {INT REAL REAL REAL REAL}
|
| 418 |
+
|
| 419 |
+
do_execsql_test 1.$tn.7 " CREATE VIRTUAL TABLE abc2 USING rtree_i32 $cols "
|
| 420 |
+
|
| 421 |
+
# EVIDENCE-OF: R-06224-52418 In an RTREE_I32 virtual table, all columns
|
| 422 |
+
# have type affinity of INTEGER.
|
| 423 |
+
do_execsql_test 1.$tn.8 {
|
| 424 |
+
INSERT INTO abc2 VALUES('6.0', '6.0', '6.0', '6.0', '6.0');
|
| 425 |
+
SELECT * FROM abc2
|
| 426 |
+
} {6 6 6 6 6}
|
| 427 |
+
do_execsql_test 1.$tn.9 {
|
| 428 |
+
SELECT type FROM pragma_table_info('abc2') ORDER BY cid
|
| 429 |
+
} {INT INT INT INT INT}
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
do_execsql_test 1.$tn.10 {
|
| 433 |
+
DROP TABLE abc;
|
| 434 |
+
DROP TABLE abc2;
|
| 435 |
+
}
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
#-------------------------------------------------------------------------
|
| 439 |
+
#-------------------------------------------------------------------------
|
| 440 |
+
# Section 3.2 of documentation.
|
| 441 |
+
#-------------------------------------------------------------------------
|
| 442 |
+
#-------------------------------------------------------------------------
|
| 443 |
+
set testprefix rtreedoc-4
|
| 444 |
+
reset_db
|
| 445 |
+
|
| 446 |
+
# EVIDENCE-OF: R-36195-31555 The usual INSERT, UPDATE, and DELETE
|
| 447 |
+
# commands work on an R*Tree index just like on regular tables.
|
| 448 |
+
#
|
| 449 |
+
# Create a regular table and an rtree table. Perform INSERT, UPDATE and
|
| 450 |
+
# DELETE operations, then observe that the contents of the two tables
|
| 451 |
+
# are identical.
|
| 452 |
+
do_execsql_test 1.0 {
|
| 453 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2);
|
| 454 |
+
CREATE TABLE t1(id INTEGER PRIMARY KEY, x1 REAL, x2 REAL);
|
| 455 |
+
}
|
| 456 |
+
foreach {tn sql} {
|
| 457 |
+
1 "INSERT INTO %TBL% VALUES(5, 11,12)"
|
| 458 |
+
2 "INSERT INTO %TBL% VALUES(11, -11,14.5)"
|
| 459 |
+
3 "UPDATE %TBL% SET x1=-99 WHERE id=11"
|
| 460 |
+
4 "DELETE FROM %TBL% WHERE x2=14.5"
|
| 461 |
+
5 "DELETE FROM %TBL%"
|
| 462 |
+
} {
|
| 463 |
+
set sql1 [string map {%TBL% rt} $sql]
|
| 464 |
+
set sql2 [string map {%TBL% t1} $sql]
|
| 465 |
+
do_execsql_test 1.$tn.0 $sql1
|
| 466 |
+
do_execsql_test 1.$tn.1 $sql2
|
| 467 |
+
|
| 468 |
+
set data1 [execsql {SELECT * FROM rt ORDER BY 1}]
|
| 469 |
+
set data2 [execsql {SELECT * FROM t1 ORDER BY 1}]
|
| 470 |
+
|
| 471 |
+
set res [expr {$data1==$data2}]
|
| 472 |
+
do_test 1.$tn.2 {set res} 1
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
# EVIDENCE-OF: R-56987-45305
|
| 476 |
+
do_execsql_test 2.0 {
|
| 477 |
+
CREATE VIRTUAL TABLE demo_index USING rtree(
|
| 478 |
+
id, -- Integer primary key
|
| 479 |
+
minX, maxX, -- Minimum and maximum X coordinate
|
| 480 |
+
minY, maxY -- Minimum and maximum Y coordinate
|
| 481 |
+
);
|
| 482 |
+
|
| 483 |
+
INSERT INTO demo_index VALUES
|
| 484 |
+
(28215, -80.781227, -80.604706, 35.208813, 35.297367),
|
| 485 |
+
(28216, -80.957283, -80.840599, 35.235920, 35.367825),
|
| 486 |
+
(28217, -80.960869, -80.869431, 35.133682, 35.208233),
|
| 487 |
+
(28226, -80.878983, -80.778275, 35.060287, 35.154446),
|
| 488 |
+
(28227, -80.745544, -80.555382, 35.130215, 35.236916),
|
| 489 |
+
(28244, -80.844208, -80.841988, 35.223728, 35.225471),
|
| 490 |
+
(28262, -80.809074, -80.682938, 35.276207, 35.377747),
|
| 491 |
+
(28269, -80.851471, -80.735718, 35.272560, 35.407925),
|
| 492 |
+
(28270, -80.794983, -80.728966, 35.059872, 35.161823),
|
| 493 |
+
(28273, -80.994766, -80.875259, 35.074734, 35.172836),
|
| 494 |
+
(28277, -80.876793, -80.767586, 35.001709, 35.101063),
|
| 495 |
+
(28278, -81.058029, -80.956375, 35.044701, 35.223812),
|
| 496 |
+
(28280, -80.844208, -80.841972, 35.225468, 35.227203),
|
| 497 |
+
(28282, -80.846382, -80.844193, 35.223972, 35.225655);
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
#-------------------------------------------------------------------------
|
| 501 |
+
#-------------------------------------------------------------------------
|
| 502 |
+
# Section 3.3 of documentation.
|
| 503 |
+
#-------------------------------------------------------------------------
|
| 504 |
+
#-------------------------------------------------------------------------
|
| 505 |
+
set testprefix rtreedoc-5
|
| 506 |
+
|
| 507 |
+
do_execsql_test 1.0 {
|
| 508 |
+
INSERT INTO demo_index
|
| 509 |
+
SELECT NULL, minX, maxX, minY+0.2, maxY+0.2 FROM demo_index;
|
| 510 |
+
INSERT INTO demo_index
|
| 511 |
+
SELECT NULL, minX+0.2, maxX+0.2, minY, maxY FROM demo_index;
|
| 512 |
+
INSERT INTO demo_index
|
| 513 |
+
SELECT NULL, minX, maxX, minY+0.4, maxY+0.4 FROM demo_index;
|
| 514 |
+
INSERT INTO demo_index
|
| 515 |
+
SELECT NULL, minX+0.4, maxX+0.4, minY, maxY FROM demo_index;
|
| 516 |
+
INSERT INTO demo_index
|
| 517 |
+
SELECT NULL, minX, maxX, minY+0.8, maxY+0.8 FROM demo_index;
|
| 518 |
+
INSERT INTO demo_index
|
| 519 |
+
SELECT NULL, minX+0.8, maxX+0.8, minY, maxY FROM demo_index;
|
| 520 |
+
|
| 521 |
+
SELECT count(*) FROM demo_index;
|
| 522 |
+
} {896}
|
| 523 |
+
|
| 524 |
+
proc do_vmstep_test {tn sql expr} {
|
| 525 |
+
execsql $sql
|
| 526 |
+
set step [db status vmstep]
|
| 527 |
+
do_test $tn.$step "expr {[subst $expr]}" 1
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
# EVIDENCE-OF: R-45880-07724 Any valid query will work against an R*Tree
|
| 531 |
+
# index.
|
| 532 |
+
do_execsql_test 1.1.0 {
|
| 533 |
+
CREATE TABLE demo_tbl AS SELECT * FROM demo_index;
|
| 534 |
+
}
|
| 535 |
+
foreach {tn sql} {
|
| 536 |
+
1 {SELECT * FROM %TBL% ORDER BY 1}
|
| 537 |
+
2 {SELECT max(minX) FROM %TBL% ORDER BY 1}
|
| 538 |
+
3 {SELECT max(minX) FROM %TBL% GROUP BY round(minY) ORDER BY 1}
|
| 539 |
+
} {
|
| 540 |
+
set sql1 [string map {%TBL% demo_index} $sql]
|
| 541 |
+
set sql2 [string map {%TBL% demo_tbl} $sql]
|
| 542 |
+
|
| 543 |
+
do_execsql_test 1.1.$tn $sql1 [execsql $sql2]
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
# EVIDENCE-OF: R-60814-18273 The R*Tree implementation just makes some
|
| 547 |
+
# kinds of queries especially efficient.
|
| 548 |
+
#
|
| 549 |
+
# The second query is more efficient than the first.
|
| 550 |
+
do_vmstep_test 1.2.1 {SELECT * FROM demo_index WHERE +rowid=28269} {$step>2000}
|
| 551 |
+
do_vmstep_test 1.2.2 {SELECT * FROM demo_index WHERE rowid=28269} {$step<100}
|
| 552 |
+
|
| 553 |
+
# EVIDENCE-OF: R-37800-50174 Queries against the primary key are
|
| 554 |
+
# efficient: SELECT * FROM demo_index WHERE id=28269;
|
| 555 |
+
do_vmstep_test 2.2 { SELECT * FROM demo_index WHERE id=28269 } {$step < 100}
|
| 556 |
+
|
| 557 |
+
# EVIDENCE-OF: R-35847-18866 The big reason for using an R*Tree is so
|
| 558 |
+
# that you can efficiently do range queries against the coordinate
|
| 559 |
+
# ranges.
|
| 560 |
+
#
|
| 561 |
+
# EVIDENCE-OF: R-49927-54202
|
| 562 |
+
do_vmstep_test 2.3 {
|
| 563 |
+
SELECT id FROM demo_index
|
| 564 |
+
WHERE minX<=-80.77470 AND maxX>=-80.77470
|
| 565 |
+
AND minY<=35.37785 AND maxY>=35.37785;
|
| 566 |
+
} {$step < 100}
|
| 567 |
+
|
| 568 |
+
# EVIDENCE-OF: R-12823-37176 The query above will quickly locate all
|
| 569 |
+
# zipcodes that contain the SQLite main office in their bounding box,
|
| 570 |
+
# even if the R*Tree contains many entries.
|
| 571 |
+
#
|
| 572 |
+
do_execsql_test 2.4 {
|
| 573 |
+
SELECT id FROM demo_index
|
| 574 |
+
WHERE minX<=-80.77470 AND maxX>=-80.77470
|
| 575 |
+
AND minY<=35.37785 AND maxY>=35.37785;
|
| 576 |
+
} {
|
| 577 |
+
28322 28269
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
# EVIDENCE-OF: R-07351-00257 For example, to find all zipcode bounding
|
| 581 |
+
# boxes that overlap with the 28269 zipcode: SELECT A.id FROM demo_index
|
| 582 |
+
# AS A, demo_index AS B WHERE A.maxX>=B.minX AND A.minX<=B.maxX
|
| 583 |
+
# AND A.maxY>=B.minY AND A.minY<=B.maxY AND B.id=28269;
|
| 584 |
+
#
|
| 585 |
+
# Also check that it is efficient
|
| 586 |
+
#
|
| 587 |
+
# EVIDENCE-OF: R-39094-01937 This second query will find both 28269
|
| 588 |
+
# entry (since every bounding box overlaps with itself) and also other
|
| 589 |
+
# zipcode that is close enough to 28269 that their bounding boxes
|
| 590 |
+
# overlap.
|
| 591 |
+
#
|
| 592 |
+
# 28269 is there in the result.
|
| 593 |
+
#
|
| 594 |
+
do_vmstep_test 2.5.1 {
|
| 595 |
+
SELECT A.id FROM demo_index AS A, demo_index AS B
|
| 596 |
+
WHERE A.maxX>=B.minX AND A.minX<=B.maxX
|
| 597 |
+
AND A.maxY>=B.minY AND A.minY<=B.maxY
|
| 598 |
+
AND B.id=28269
|
| 599 |
+
} {$step < 100}
|
| 600 |
+
do_execsql_test 2.5.2 {
|
| 601 |
+
SELECT A.id FROM demo_index AS A, demo_index AS B
|
| 602 |
+
WHERE A.maxX>=B.minX AND A.minX<=B.maxX
|
| 603 |
+
AND A.maxY>=B.minY AND A.minY<=B.maxY
|
| 604 |
+
AND B.id=28269 ORDER BY +A.id;
|
| 605 |
+
} {
|
| 606 |
+
28215
|
| 607 |
+
28216
|
| 608 |
+
28262
|
| 609 |
+
28269
|
| 610 |
+
28286
|
| 611 |
+
28287
|
| 612 |
+
28291
|
| 613 |
+
28293
|
| 614 |
+
28298
|
| 615 |
+
28313
|
| 616 |
+
28320
|
| 617 |
+
28322
|
| 618 |
+
28336
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
# EVIDENCE-OF: R-02723-34107 Note that it is not necessary for all
|
| 622 |
+
# coordinates in an R*Tree index to be constrained in order for the
|
| 623 |
+
# index search to be efficient.
|
| 624 |
+
#
|
| 625 |
+
# EVIDENCE-OF: R-22490-27246 One might, for example, want to query all
|
| 626 |
+
# objects that overlap with the 35th parallel: SELECT id FROM demo_index
|
| 627 |
+
# WHERE maxY>=35.0 AND minY<=35.0;
|
| 628 |
+
do_vmstep_test 2.6.1 {
|
| 629 |
+
SELECT id FROM demo_index
|
| 630 |
+
WHERE maxY>=35.0 AND minY<=35.0;
|
| 631 |
+
} {$step < 100}
|
| 632 |
+
do_execsql_test 2.6.2 {
|
| 633 |
+
SELECT id FROM demo_index
|
| 634 |
+
WHERE maxY>=35.0 AND minY<=35.0;
|
| 635 |
+
} {}
|
| 636 |
+
|
| 637 |
+
|
| 638 |
+
#-------------------------------------------------------------------------
|
| 639 |
+
#-------------------------------------------------------------------------
|
| 640 |
+
# Section 3.4 of documentation.
|
| 641 |
+
#-------------------------------------------------------------------------
|
| 642 |
+
#-------------------------------------------------------------------------
|
| 643 |
+
set testprefix rtreedoc-6
|
| 644 |
+
reset_db
|
| 645 |
+
|
| 646 |
+
# EVIDENCE-OF: R-08327-00674 By default, coordinates are stored in an
|
| 647 |
+
# R*Tree using 32-bit floating point values.
|
| 648 |
+
#
|
| 649 |
+
# EVIDENCE-OF: R-22000-53613 The default virtual table ("rtree") stores
|
| 650 |
+
# coordinates as single-precision (4-byte) floating point numbers.
|
| 651 |
+
#
|
| 652 |
+
# Show this by showing that rounding is consistent with 32-bit float
|
| 653 |
+
# rounding.
|
| 654 |
+
do_execsql_test 1.0 {
|
| 655 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, a,b);
|
| 656 |
+
}
|
| 657 |
+
do_execsql_test 1.1 {
|
| 658 |
+
INSERT INTO rt VALUES(14, -1000000000000, 1000000000000);
|
| 659 |
+
SELECT * FROM rt;
|
| 660 |
+
} {14 -1000000126976.0 1000000126976.0}
|
| 661 |
+
|
| 662 |
+
# EVIDENCE-OF: R-39127-51288 When a coordinate cannot be exactly
|
| 663 |
+
# represented by a 32-bit floating point number, the lower-bound
|
| 664 |
+
# coordinates are rounded down and the upper-bound coordinates are
|
| 665 |
+
# rounded up.
|
| 666 |
+
foreach {tn val} {
|
| 667 |
+
1 100000000000
|
| 668 |
+
2 200000000000
|
| 669 |
+
3 300000000000
|
| 670 |
+
4 400000000000
|
| 671 |
+
|
| 672 |
+
5 -100000000000
|
| 673 |
+
6 -200000000000
|
| 674 |
+
7 -300000000000
|
| 675 |
+
8 -400000000000
|
| 676 |
+
} {
|
| 677 |
+
set val [expr $val]
|
| 678 |
+
do_execsql_test 2.$tn.0 {DELETE FROM rt}
|
| 679 |
+
do_execsql_test 2.$tn.1 {INSERT INTO rt VALUES(23, $val, $val)}
|
| 680 |
+
do_execsql_test 2.$tn.2 {
|
| 681 |
+
SELECT $val>=a, $val<=b, a!=b FROM rt
|
| 682 |
+
} {1 1 1}
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
do_execsql_test 3.0 {
|
| 686 |
+
DROP TABLE rt;
|
| 687 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, x1,x2, y1,y2);
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
# EVIDENCE-OF: R-45870-62834 Thus, bounding boxes might be slightly
|
| 691 |
+
# larger than specified, but will never be any smaller.
|
| 692 |
+
foreach {tn x1 x2 y1 y2} {
|
| 693 |
+
1 100000000000 200000000000 300000000000 400000000000
|
| 694 |
+
} {
|
| 695 |
+
set val [expr $val]
|
| 696 |
+
do_execsql_test 3.$tn.0 {DELETE FROM rt}
|
| 697 |
+
do_execsql_test 3.$tn.1 {INSERT INTO rt VALUES(23, $x1, $x2, $y1, $y2)}
|
| 698 |
+
do_execsql_test 3.$tn.2 {
|
| 699 |
+
SELECT (x2-x1)*(y2-y1) >= ($x2-$x1)*($y2-$y1) FROM rt
|
| 700 |
+
} {1}
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
#-------------------------------------------------------------------------
|
| 704 |
+
#-------------------------------------------------------------------------
|
| 705 |
+
# Section 3.5 of documentation.
|
| 706 |
+
#-------------------------------------------------------------------------
|
| 707 |
+
#-------------------------------------------------------------------------
|
| 708 |
+
set testprefix rtreedoc-7
|
| 709 |
+
reset_db
|
| 710 |
+
|
| 711 |
+
# EVIDENCE-OF: R-55979-39402 It is the nature of the Guttman R-Tree
|
| 712 |
+
# algorithm that any write might radically restructure the tree, and in
|
| 713 |
+
# the process change the scan order of the nodes.
|
| 714 |
+
#
|
| 715 |
+
# In the test below, the INSERT marked "THIS INSERT!!" does not affect
|
| 716 |
+
# the results of queries with an ORDER BY, but does affect the results
|
| 717 |
+
# of one without an ORDER BY. Therefore the INSERT changed the scan
|
| 718 |
+
# order.
|
| 719 |
+
do_execsql_test 1.0 {
|
| 720 |
+
CREATE VIRTUAL TABLE rt USING rtree(id, minX, maxX);
|
| 721 |
+
WITH s(i) AS (
|
| 722 |
+
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<51
|
| 723 |
+
)
|
| 724 |
+
INSERT INTO rt SELECT NULL, i%10, (i%10)+5 FROM s
|
| 725 |
+
}
|
| 726 |
+
do_execsql_test 1.1 { SELECT count(*) FROM rt_node } 1
|
| 727 |
+
do_test 1.2 {
|
| 728 |
+
set res1 [db eval {SELECT * FROM rt WHERE maxX < 30}]
|
| 729 |
+
set res1o [db eval {SELECT * FROM rt WHERE maxX < 30 ORDER BY +id}]
|
| 730 |
+
|
| 731 |
+
db eval { INSERT INTO rt VALUES(NULL, 50, 50) } ;# THIS INSERT!!
|
| 732 |
+
|
| 733 |
+
set res2 [db eval {SELECT * FROM rt WHERE maxX < 30}]
|
| 734 |
+
set res2o [db eval {SELECT * FROM rt WHERE maxX < 30 ORDER BY +id}]
|
| 735 |
+
list [expr {$res1==$res2}] [expr {$res1o==$res2o}]
|
| 736 |
+
} {0 1}
|
| 737 |
+
|
| 738 |
+
do_execsql_test 1.3 { SELECT count(*) FROM rt_node } 3
|
| 739 |
+
|
| 740 |
+
# EVIDENCE-OF: R-00683-48865 For this reason, it is not generally
|
| 741 |
+
# possible to modify the R-Tree in the middle of a query of the R-Tree.
|
| 742 |
+
# Attempts to do so will fail with a SQLITE_LOCKED "database table is
|
| 743 |
+
# locked" error.
|
| 744 |
+
#
|
| 745 |
+
# SQLITE_LOCKED==6
|
| 746 |
+
#
|
| 747 |
+
do_test 1.4 {
|
| 748 |
+
set nCnt 3
|
| 749 |
+
db eval { SELECT * FROM rt WHERE minX>0 AND maxX<12 } {
|
| 750 |
+
incr nCnt -1
|
| 751 |
+
if {$nCnt==0} {
|
| 752 |
+
set rc [catch {db eval {
|
| 753 |
+
INSERT INTO rt VALUES(NULL, 51, 51);
|
| 754 |
+
}} msg]
|
| 755 |
+
set errorcode [db errorcode]
|
| 756 |
+
break
|
| 757 |
+
}
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
list $errorcode $rc $msg
|
| 761 |
+
} {6 1 {database table is locked}}
|
| 762 |
+
|
| 763 |
+
# EVIDENCE-OF: R-19740-29710 So, for example, suppose an application
|
| 764 |
+
# runs one query against an R-Tree like this: SELECT id FROM demo_index
|
| 765 |
+
# WHERE maxY>=35.0 AND minY<=35.0; Then for each "id" value
|
| 766 |
+
# returned, suppose the application creates an UPDATE statement like the
|
| 767 |
+
# following and binds the "id" value returned against the "?1"
|
| 768 |
+
# parameter: UPDATE demo_index SET maxY=maxY+0.5 WHERE id=?1;
|
| 769 |
+
#
|
| 770 |
+
# EVIDENCE-OF: R-52919-32711 Then the UPDATE might fail with an
|
| 771 |
+
# SQLITE_LOCKED error.
|
| 772 |
+
do_execsql_test 2.0 {
|
| 773 |
+
CREATE VIRTUAL TABLE demo_index USING rtree(
|
| 774 |
+
id, -- Integer primary key
|
| 775 |
+
minX, maxX, -- Minimum and maximum X coordinate
|
| 776 |
+
minY, maxY -- Minimum and maximum Y coordinate
|
| 777 |
+
);
|
| 778 |
+
INSERT INTO demo_index VALUES
|
| 779 |
+
(28215, -80.781227, -80.604706, 35.208813, 35.297367),
|
| 780 |
+
(28216, -80.957283, -80.840599, 35.235920, 35.367825),
|
| 781 |
+
(28217, -80.960869, -80.869431, 35.133682, 35.208233),
|
| 782 |
+
(28226, -80.878983, -80.778275, 35.060287, 35.154446);
|
| 783 |
+
}
|
| 784 |
+
do_test 2.1 {
|
| 785 |
+
db eval { SELECT id FROM demo_index WHERE maxY>=35.0 AND minY<=35.0 } {
|
| 786 |
+
set rc [catch {
|
| 787 |
+
db eval { UPDATE demo_index SET maxY=maxY+0.5 WHERE id=$id }
|
| 788 |
+
} msg]
|
| 789 |
+
set errorcode [db errorcode]
|
| 790 |
+
break
|
| 791 |
+
}
|
| 792 |
+
list $errorcode $rc $msg
|
| 793 |
+
} {6 1 {database table is locked}}
|
| 794 |
+
|
| 795 |
+
# EVIDENCE-OF: R-32604-49843 Ordinary tables in SQLite are able to read
|
| 796 |
+
# and write at the same time.
|
| 797 |
+
#
|
| 798 |
+
do_execsql_test 3.0 {
|
| 799 |
+
CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c);
|
| 800 |
+
INSERT INTO x1 VALUES(1, 1, 1);
|
| 801 |
+
INSERT INTO x1 VALUES(2, 2, 2);
|
| 802 |
+
INSERT INTO x1 VALUES(3, 3, 3);
|
| 803 |
+
INSERT INTO x1 VALUES(4, 4, 4);
|
| 804 |
+
}
|
| 805 |
+
do_test 3.1 {
|
| 806 |
+
unset -nocomplain res
|
| 807 |
+
set res [list]
|
| 808 |
+
db eval { SELECT * FROM x1 } {
|
| 809 |
+
lappend res $a $b $c
|
| 810 |
+
switch -- $a {
|
| 811 |
+
1 {
|
| 812 |
+
db eval { INSERT INTO x1 VALUES(5, 5, 5) }
|
| 813 |
+
}
|
| 814 |
+
2 {
|
| 815 |
+
db eval { UPDATE x1 SET c=20 WHERE a=2 }
|
| 816 |
+
}
|
| 817 |
+
3 {
|
| 818 |
+
db eval { DELETE FROM x1 WHERE c IN (3,4) }
|
| 819 |
+
}
|
| 820 |
+
}
|
| 821 |
+
}
|
| 822 |
+
set res
|
| 823 |
+
} {1 1 1 2 2 2 3 3 3 5 5 5}
|
| 824 |
+
do_execsql_test 3.2 {
|
| 825 |
+
SELECT * FROM x1
|
| 826 |
+
} {1 1 1 2 2 20 5 5 5}
|
| 827 |
+
|
| 828 |
+
# EVIDENCE-OF: R-06177-00576 And R-Tree can appear to read and write at
|
| 829 |
+
# the same time in some circumstances, if it can figure out how to
|
| 830 |
+
# reliably run the query to completion before starting the update.
|
| 831 |
+
#
|
| 832 |
+
# In 8.2, it can, it 8.1, it cannot.
|
| 833 |
+
do_test 8.1 {
|
| 834 |
+
db eval { SELECT * FROM rt } {
|
| 835 |
+
set rc [catch { db eval { INSERT INTO rt VALUES(53,53,53) } } msg]
|
| 836 |
+
break;
|
| 837 |
+
}
|
| 838 |
+
list $rc $msg
|
| 839 |
+
} {1 {database table is locked}}
|
| 840 |
+
do_test 8.2 {
|
| 841 |
+
db eval { SELECT * FROM rt ORDER BY +id } {
|
| 842 |
+
set rc [catch { db eval { INSERT INTO rt VALUES(53,53,53) } } msg]
|
| 843 |
+
break
|
| 844 |
+
}
|
| 845 |
+
list $rc $msg
|
| 846 |
+
} {0 {}}
|
| 847 |
+
|
| 848 |
+
#-------------------------------------------------------------------------
|
| 849 |
+
#-------------------------------------------------------------------------
|
| 850 |
+
# Section 4 of documentation.
|
| 851 |
+
#-------------------------------------------------------------------------
|
| 852 |
+
#-------------------------------------------------------------------------
|
| 853 |
+
set testprefix rtreedoc-8
|
| 854 |
+
reset_db
|
| 855 |
+
|
| 856 |
+
# EVIDENCE-OF: R-21062-30088 For the example above, one might create an
|
| 857 |
+
# auxiliary table as follows: CREATE TABLE demo_data( id INTEGER PRIMARY
|
| 858 |
+
# KEY, -- primary key objname TEXT, -- name of the object objtype TEXT,
|
| 859 |
+
# -- object type boundary BLOB -- detailed boundary of object );
|
| 860 |
+
#
|
| 861 |
+
# One might.
|
| 862 |
+
#
|
| 863 |
+
do_execsql_test 1.0 {
|
| 864 |
+
CREATE TABLE demo_data(
|
| 865 |
+
id INTEGER PRIMARY KEY, -- primary key
|
| 866 |
+
objname TEXT, -- name of the object
|
| 867 |
+
objtype TEXT, -- object type
|
| 868 |
+
boundary BLOB -- detailed boundary of object
|
| 869 |
+
);
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
do_execsql_test 1.1 {
|
| 873 |
+
CREATE VIRTUAL TABLE demo_index USING rtree(
|
| 874 |
+
id, -- Integer primary key
|
| 875 |
+
minX, maxX, -- Minimum and maximum X coordinate
|
| 876 |
+
minY, maxY -- Minimum and maximum Y coordinate
|
| 877 |
+
);
|
| 878 |
+
|
| 879 |
+
INSERT INTO demo_index VALUES
|
| 880 |
+
(28215, -80.781227, -80.604706, 35.208813, 35.297367),
|
| 881 |
+
(28216, -80.957283, -80.840599, 35.235920, 35.367825),
|
| 882 |
+
(28217, -80.960869, -80.869431, 35.133682, 35.208233),
|
| 883 |
+
(28226, -80.878983, -80.778275, 35.060287, 35.154446),
|
| 884 |
+
(28227, -80.745544, -80.555382, 35.130215, 35.236916),
|
| 885 |
+
(28244, -80.844208, -80.841988, 35.223728, 35.225471),
|
| 886 |
+
(28262, -80.809074, -80.682938, 35.276207, 35.377747),
|
| 887 |
+
(28269, -80.851471, -80.735718, 35.272560, 35.407925),
|
| 888 |
+
(28270, -80.794983, -80.728966, 35.059872, 35.161823),
|
| 889 |
+
(28273, -80.994766, -80.875259, 35.074734, 35.172836),
|
| 890 |
+
(28277, -80.876793, -80.767586, 35.001709, 35.101063),
|
| 891 |
+
(28278, -81.058029, -80.956375, 35.044701, 35.223812),
|
| 892 |
+
(28280, -80.844208, -80.841972, 35.225468, 35.227203),
|
| 893 |
+
(28282, -80.846382, -80.844193, 35.223972, 35.225655);
|
| 894 |
+
|
| 895 |
+
INSERT INTO demo_index
|
| 896 |
+
SELECT NULL, minX, maxX, minY+0.2, maxY+0.2 FROM demo_index;
|
| 897 |
+
INSERT INTO demo_index
|
| 898 |
+
SELECT NULL, minX+0.2, maxX+0.2, minY, maxY FROM demo_index;
|
| 899 |
+
INSERT INTO demo_index
|
| 900 |
+
SELECT NULL, minX, maxX, minY+0.4, maxY+0.4 FROM demo_index;
|
| 901 |
+
INSERT INTO demo_index
|
| 902 |
+
SELECT NULL, minX+0.4, maxX+0.4, minY, maxY FROM demo_index;
|
| 903 |
+
INSERT INTO demo_index
|
| 904 |
+
SELECT NULL, minX, maxX, minY+0.8, maxY+0.8 FROM demo_index;
|
| 905 |
+
INSERT INTO demo_index
|
| 906 |
+
SELECT NULL, minX+0.8, maxX+0.8, minY, maxY FROM demo_index;
|
| 907 |
+
|
| 908 |
+
INSERT INTO demo_data(id) SELECT id FROM demo_index;
|
| 909 |
+
|
| 910 |
+
SELECT count(*) FROM demo_index;
|
| 911 |
+
} {896}
|
| 912 |
+
|
| 913 |
+
set ::contained_in 0
|
| 914 |
+
proc contained_in {args} {incr ::contained_in ; return 0}
|
| 915 |
+
db func contained_in contained_in
|
| 916 |
+
|
| 917 |
+
# EVIDENCE-OF: R-32671-43888 Then an efficient way to find the specific
|
| 918 |
+
# ZIP code for the main SQLite office would be to run a query like this:
|
| 919 |
+
# SELECT objname FROM demo_data, demo_index WHERE
|
| 920 |
+
# demo_data.id=demo_index.id AND contained_in(demo_data.boundary,
|
| 921 |
+
# 35.37785, -80.77470) AND minX<=-80.77470 AND maxX>=-80.77470 AND
|
| 922 |
+
# minY<=35.37785 AND maxY>=35.37785;
|
| 923 |
+
do_vmstep_test 1.2 {
|
| 924 |
+
SELECT objname FROM demo_data, demo_index
|
| 925 |
+
WHERE demo_data.id=demo_index.id
|
| 926 |
+
AND contained_in(demo_data.boundary, 35.37785, -80.77470)
|
| 927 |
+
AND minX<=-80.77470 AND maxX>=-80.77470
|
| 928 |
+
AND minY<=35.37785 AND maxY>=35.37785;
|
| 929 |
+
} {$step<100}
|
| 930 |
+
set ::contained_in1 $::contained_in
|
| 931 |
+
|
| 932 |
+
# EVIDENCE-OF: R-32761-23915 One would get the same answer without the
|
| 933 |
+
# use of the R*Tree index using the following simpler query: SELECT
|
| 934 |
+
# objname FROM demo_data WHERE contained_in(demo_data.boundary,
|
| 935 |
+
# 35.37785, -80.77470);
|
| 936 |
+
set ::contained_in 0
|
| 937 |
+
do_vmstep_test 1.3 {
|
| 938 |
+
SELECT objname FROM demo_data
|
| 939 |
+
WHERE contained_in(demo_data.boundary, 35.37785, -80.77470);
|
| 940 |
+
} {$step>3200}
|
| 941 |
+
|
| 942 |
+
# EVIDENCE-OF: R-40261-32799 The problem with this latter query is that
|
| 943 |
+
# it must apply the contained_in() function to all entries in the
|
| 944 |
+
# demo_data table.
|
| 945 |
+
#
|
| 946 |
+
# 896 of them, IIRC.
|
| 947 |
+
do_test 1.4 {
|
| 948 |
+
set ::contained_in
|
| 949 |
+
} 896
|
| 950 |
+
|
| 951 |
+
# EVIDENCE-OF: R-24212-52761 The use of the R*Tree in the penultimate
|
| 952 |
+
# query reduces the number of calls to contained_in() function to a
|
| 953 |
+
# small subset of the entire table.
|
| 954 |
+
#
|
| 955 |
+
# 2 is a small subset of 896.
|
| 956 |
+
#
|
| 957 |
+
# EVIDENCE-OF: R-39057-63901 The R*Tree index did not find the exact
|
| 958 |
+
# answer itself, it merely limited the search space.
|
| 959 |
+
#
|
| 960 |
+
# contained_in() filtered out those 2 rows.
|
| 961 |
+
do_test 1.5 {
|
| 962 |
+
set ::contained_in1
|
| 963 |
+
} {2}
|
| 964 |
+
|
| 965 |
+
|
| 966 |
+
#-------------------------------------------------------------------------
|
| 967 |
+
#-------------------------------------------------------------------------
|
| 968 |
+
# Section 4.1 of documentation.
|
| 969 |
+
#-------------------------------------------------------------------------
|
| 970 |
+
#-------------------------------------------------------------------------
|
| 971 |
+
set testprefix rtreedoc-9
|
| 972 |
+
reset_db
|
| 973 |
+
|
| 974 |
+
# EVIDENCE-OF: R-46566-43213 Beginning with SQLite version 3.24.0
|
| 975 |
+
# (2018-06-04), r-tree tables can have auxiliary columns that store
|
| 976 |
+
# arbitrary data. Auxiliary columns can be used in place of secondary
|
| 977 |
+
# tables such as "demo_data".
|
| 978 |
+
#
|
| 979 |
+
# EVIDENCE-OF: R-41287-48160 Auxiliary columns are marked with a "+"
|
| 980 |
+
# symbol before the column name.
|
| 981 |
+
#
|
| 982 |
+
# This interface cannot conveniently be used to prove anything about
|
| 983 |
+
# versions of SQLite prior to 3.24.0.
|
| 984 |
+
#
|
| 985 |
+
do_execsql_test 1.0 {
|
| 986 |
+
CREATE VIRTUAL TABLE rta USING rtree(
|
| 987 |
+
id, u1,u2, v1,v2, +aux
|
| 988 |
+
);
|
| 989 |
+
|
| 990 |
+
INSERT INTO rta(aux) VALUES(NULL);
|
| 991 |
+
INSERT INTO rta(aux) VALUES(45);
|
| 992 |
+
INSERT INTO rta(aux) VALUES(22.3);
|
| 993 |
+
INSERT INTO rta(aux) VALUES('hello');
|
| 994 |
+
INSERT INTO rta(aux) VALUES(X'ABCD');
|
| 995 |
+
|
| 996 |
+
SELECT typeof(aux), quote(aux) FROM rta;
|
| 997 |
+
} {
|
| 998 |
+
null NULL
|
| 999 |
+
integer 45
|
| 1000 |
+
real 22.3
|
| 1001 |
+
text 'hello'
|
| 1002 |
+
blob X'ABCD'
|
| 1003 |
+
}
|
| 1004 |
+
|
| 1005 |
+
# EVIDENCE-OF: R-30514-26093 Auxiliary columns must come after all of
|
| 1006 |
+
# the coordinate boundary columns.
|
| 1007 |
+
foreach {tn cols} {
|
| 1008 |
+
1 "id x1,x2, +extra, y1,y2"
|
| 1009 |
+
2 "extra, +id x1,x2, y1,y2"
|
| 1010 |
+
3 "id, x1,+x2, extra, y1,y2"
|
| 1011 |
+
} {
|
| 1012 |
+
do_catchsql_test 2.$tn "
|
| 1013 |
+
CREATE VIRTUAL TABLE rrr USING rtree($cols)
|
| 1014 |
+
" {1 {Auxiliary rtree columns must be last}}
|
| 1015 |
+
}
|
| 1016 |
+
do_catchsql_test 3.0 {
|
| 1017 |
+
CREATE VIRTUAL TABLE rrr USING rtree(+id, extra, x1, x2);
|
| 1018 |
+
} {1 {near "+": syntax error}}
|
| 1019 |
+
|
| 1020 |
+
# EVIDENCE-OF: R-01280-03635 An RTREE table can have no more than 100
|
| 1021 |
+
# columns total. In other words, the count of columns including the
|
| 1022 |
+
# integer primary key column, the coordinate boundary columns, and all
|
| 1023 |
+
# auxiliary columns must be 100 or less.
|
| 1024 |
+
do_catchsql_test 3.1 {
|
| 1025 |
+
CREATE VIRTUAL TABLE r1 USING rtree(intid, u1,u2,
|
| 1026 |
+
+c00, +c01, +c02, +c03, +c04, +c05, +c06, +c07, +c08, +c09,
|
| 1027 |
+
+c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19,
|
| 1028 |
+
+c20, +c21, +c22, +c23, +c24, +c25, +c26, +c27, +c28, +c29,
|
| 1029 |
+
+c30, +c31, +c32, +c33, +c34, +c35, +c36, +c37, +c38, +c39,
|
| 1030 |
+
+c40, +c41, +c42, +c43, +c44, +c45, +c46, +c47, +c48, +c49,
|
| 1031 |
+
+c50, +c51, +c52, +c53, +c54, +c55, +c56, +c57, +c58, +c59,
|
| 1032 |
+
+c60, +c61, +c62, +c63, +c64, +c65, +c66, +c67, +c68, +c69,
|
| 1033 |
+
+c70, +c71, +c72, +c73, +c74, +c75, +c76, +c77, +c78, +c79,
|
| 1034 |
+
+c80, +c81, +c82, +c83, +c84, +c85, +c86, +c87, +c88, +c89,
|
| 1035 |
+
+c90, +c91, +c92, +c93, +c94, +c95, +c96
|
| 1036 |
+
);
|
| 1037 |
+
} {0 {}}
|
| 1038 |
+
do_catchsql_test 3.2 {
|
| 1039 |
+
DROP TABLE r1;
|
| 1040 |
+
CREATE VIRTUAL TABLE r1 USING rtree(intid, u1,u2,
|
| 1041 |
+
+c00, +c01, +c02, +c03, +c04, +c05, +c06, +c07, +c08, +c09,
|
| 1042 |
+
+c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19,
|
| 1043 |
+
+c20, +c21, +c22, +c23, +c24, +c25, +c26, +c27, +c28, +c29,
|
| 1044 |
+
+c30, +c31, +c32, +c33, +c34, +c35, +c36, +c37, +c38, +c39,
|
| 1045 |
+
+c40, +c41, +c42, +c43, +c44, +c45, +c46, +c47, +c48, +c49,
|
| 1046 |
+
+c50, +c51, +c52, +c53, +c54, +c55, +c56, +c57, +c58, +c59,
|
| 1047 |
+
+c60, +c61, +c62, +c63, +c64, +c65, +c66, +c67, +c68, +c69,
|
| 1048 |
+
+c70, +c71, +c72, +c73, +c74, +c75, +c76, +c77, +c78, +c79,
|
| 1049 |
+
+c80, +c81, +c82, +c83, +c84, +c85, +c86, +c87, +c88, +c89,
|
| 1050 |
+
+c90, +c91, +c92, +c93, +c94, +c95, +c96, +c97
|
| 1051 |
+
);
|
| 1052 |
+
} {1 {Too many columns for an rtree table}}
|
| 1053 |
+
do_catchsql_test 3.3 {
|
| 1054 |
+
CREATE VIRTUAL TABLE r1 USING rtree(intid, u1,u2, v1,v2,
|
| 1055 |
+
+c00, +c01, +c02, +c03, +c04, +c05, +c06, +c07, +c08, +c09,
|
| 1056 |
+
+c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19,
|
| 1057 |
+
+c20, +c21, +c22, +c23, +c24, +c25, +c26, +c27, +c28, +c29,
|
| 1058 |
+
+c30, +c31, +c32, +c33, +c34, +c35, +c36, +c37, +c38, +c39,
|
| 1059 |
+
+c40, +c41, +c42, +c43, +c44, +c45, +c46, +c47, +c48, +c49,
|
| 1060 |
+
+c50, +c51, +c52, +c53, +c54, +c55, +c56, +c57, +c58, +c59,
|
| 1061 |
+
+c60, +c61, +c62, +c63, +c64, +c65, +c66, +c67, +c68, +c69,
|
| 1062 |
+
+c70, +c71, +c72, +c73, +c74, +c75, +c76, +c77, +c78, +c79,
|
| 1063 |
+
+c80, +c81, +c82, +c83, +c84, +c85, +c86, +c87, +c88, +c89,
|
| 1064 |
+
+c90, +c91, +c92, +c93, +c94,
|
| 1065 |
+
);
|
| 1066 |
+
} {0 {}}
|
| 1067 |
+
do_catchsql_test 3.4 {
|
| 1068 |
+
DROP TABLE r1;
|
| 1069 |
+
CREATE VIRTUAL TABLE r1 USING rtree(intid, u1,u2, v1,v2,
|
| 1070 |
+
+c00, +c01, +c02, +c03, +c04, +c05, +c06, +c07, +c08, +c09,
|
| 1071 |
+
+c10, +c11, +c12, +c13, +c14, +c15, +c16, +c17, +c18, +c19,
|
| 1072 |
+
+c20, +c21, +c22, +c23, +c24, +c25, +c26, +c27, +c28, +c29,
|
| 1073 |
+
+c30, +c31, +c32, +c33, +c34, +c35, +c36, +c37, +c38, +c39,
|
| 1074 |
+
+c40, +c41, +c42, +c43, +c44, +c45, +c46, +c47, +c48, +c49,
|
| 1075 |
+
+c50, +c51, +c52, +c53, +c54, +c55, +c56, +c57, +c58, +c59,
|
| 1076 |
+
+c60, +c61, +c62, +c63, +c64, +c65, +c66, +c67, +c68, +c69,
|
| 1077 |
+
+c70, +c71, +c72, +c73, +c74, +c75, +c76, +c77, +c78, +c79,
|
| 1078 |
+
+c80, +c81, +c82, +c83, +c84, +c85, +c86, +c87, +c88, +c89,
|
| 1079 |
+
+c90, +c91, +c92, +c93, +c94, +c95,
|
| 1080 |
+
);
|
| 1081 |
+
} {1 {Too many columns for an rtree table}}
|
| 1082 |
+
|
| 1083 |
+
# EVIDENCE-OF: R-05552-15084
|
| 1084 |
+
do_execsql_test 4.0 {
|
| 1085 |
+
CREATE VIRTUAL TABLE demo_index2 USING rtree(
|
| 1086 |
+
id, -- Integer primary key
|
| 1087 |
+
minX, maxX, -- Minimum and maximum X coordinate
|
| 1088 |
+
minY, maxY, -- Minimum and maximum Y coordinate
|
| 1089 |
+
+objname TEXT, -- name of the object
|
| 1090 |
+
+objtype TEXT, -- object type
|
| 1091 |
+
+boundary BLOB -- detailed boundary of object
|
| 1092 |
+
);
|
| 1093 |
+
}
|
| 1094 |
+
do_execsql_test 4.1 {
|
| 1095 |
+
CREATE VIRTUAL TABLE demo_index USING rtree(
|
| 1096 |
+
id, -- Integer primary key
|
| 1097 |
+
minX, maxX, -- Minimum and maximum X coordinate
|
| 1098 |
+
minY, maxY -- Minimum and maximum Y coordinate
|
| 1099 |
+
);
|
| 1100 |
+
CREATE TABLE demo_data(
|
| 1101 |
+
id INTEGER PRIMARY KEY, -- primary key
|
| 1102 |
+
objname TEXT, -- name of the object
|
| 1103 |
+
objtype TEXT, -- object type
|
| 1104 |
+
boundary BLOB -- detailed boundary of object
|
| 1105 |
+
);
|
| 1106 |
+
|
| 1107 |
+
INSERT INTO demo_index2(id) VALUES(1);
|
| 1108 |
+
INSERT INTO demo_index(id) VALUES(1);
|
| 1109 |
+
INSERT INTO demo_data(id) VALUES(1);
|
| 1110 |
+
}
|
| 1111 |
+
do_test 4.2 {
|
| 1112 |
+
catch { array unset R }
|
| 1113 |
+
db eval {SELECT * FROM demo_index2} R { set r1 [array names R] }
|
| 1114 |
+
catch { array unset R }
|
| 1115 |
+
db eval {SELECT * FROM demo_index NATURAL JOIN demo_data } R {
|
| 1116 |
+
set r2 [array names R]
|
| 1117 |
+
}
|
| 1118 |
+
expr {$r1==$r2}
|
| 1119 |
+
} {1}
|
| 1120 |
+
|
| 1121 |
+
# EVIDENCE-OF: R-26099-32169 SELECT objname FROM demo_index2 WHERE
|
| 1122 |
+
# contained_in(boundary, 35.37785, -80.77470) AND minX<=-80.77470 AND
|
| 1123 |
+
# maxX>=-80.77470 AND minY<=35.37785 AND maxY>=35.37785;
|
| 1124 |
+
do_execsql_test 4.3.1 {
|
| 1125 |
+
DELETE FROM demo_index2;
|
| 1126 |
+
INSERT INTO demo_index2(id,minX,maxX,minY,maxY) VALUES
|
| 1127 |
+
(28215, -80.781227, -80.604706, 35.208813, 35.297367),
|
| 1128 |
+
(28216, -80.957283, -80.840599, 35.235920, 35.367825),
|
| 1129 |
+
(28217, -80.960869, -80.869431, 35.133682, 35.208233),
|
| 1130 |
+
(28226, -80.878983, -80.778275, 35.060287, 35.154446),
|
| 1131 |
+
(28227, -80.745544, -80.555382, 35.130215, 35.236916),
|
| 1132 |
+
(28244, -80.844208, -80.841988, 35.223728, 35.225471),
|
| 1133 |
+
(28262, -80.809074, -80.682938, 35.276207, 35.377747),
|
| 1134 |
+
(28269, -80.851471, -80.735718, 35.272560, 35.407925),
|
| 1135 |
+
(28270, -80.794983, -80.728966, 35.059872, 35.161823),
|
| 1136 |
+
(28273, -80.994766, -80.875259, 35.074734, 35.172836),
|
| 1137 |
+
(28277, -80.876793, -80.767586, 35.001709, 35.101063),
|
| 1138 |
+
(28278, -81.058029, -80.956375, 35.044701, 35.223812),
|
| 1139 |
+
(28280, -80.844208, -80.841972, 35.225468, 35.227203),
|
| 1140 |
+
(28282, -80.846382, -80.844193, 35.223972, 35.225655);
|
| 1141 |
+
}
|
| 1142 |
+
set ::contained_in 0
|
| 1143 |
+
proc contained_in {args} {
|
| 1144 |
+
incr ::contained_in
|
| 1145 |
+
return 0
|
| 1146 |
+
}
|
| 1147 |
+
db func contained_in contained_in
|
| 1148 |
+
do_execsql_test 4.3.2 {
|
| 1149 |
+
SELECT objname FROM demo_index2
|
| 1150 |
+
WHERE contained_in(boundary, 35.37785, -80.77470)
|
| 1151 |
+
AND minX<=-80.77470 AND maxX>=-80.77470
|
| 1152 |
+
AND minY<=35.37785 AND maxY>=35.37785;
|
| 1153 |
+
}
|
| 1154 |
+
do_test 4.3.3 {
|
| 1155 |
+
# Function invoked only once because r-tree filtering happened first.
|
| 1156 |
+
set ::contained_in
|
| 1157 |
+
} 1
|
| 1158 |
+
set ::contained_in 0
|
| 1159 |
+
do_execsql_test 4.3.4 {
|
| 1160 |
+
SELECT objname FROM demo_index2
|
| 1161 |
+
WHERE contained_in(boundary, 35.37785, -80.77470)
|
| 1162 |
+
}
|
| 1163 |
+
do_test 4.3.3 {
|
| 1164 |
+
# Function invoked 14 times because no r-tree filtering. Inefficient.
|
| 1165 |
+
set ::contained_in
|
| 1166 |
+
} 14
|
| 1167 |
+
|
| 1168 |
+
#-------------------------------------------------------------------------
|
| 1169 |
+
#-------------------------------------------------------------------------
|
| 1170 |
+
# Section 4.1.1 of documentation.
|
| 1171 |
+
#-------------------------------------------------------------------------
|
| 1172 |
+
#-------------------------------------------------------------------------
|
| 1173 |
+
set testprefix rtreedoc-9
|
| 1174 |
+
reset_db
|
| 1175 |
+
|
| 1176 |
+
# EVIDENCE-OF: R-24021-02490 For auxiliary columns, only the name of the
|
| 1177 |
+
# column matters. The type affinity is ignored.
|
| 1178 |
+
#
|
| 1179 |
+
# EVIDENCE-OF: R-39906-44154 Constraints such as NOT NULL, UNIQUE,
|
| 1180 |
+
# REFERENCES, or CHECK are also ignored.
|
| 1181 |
+
do_execsql_test 1.0 { PRAGMA foreign_keys = on }
|
| 1182 |
+
foreach {tn auxcol nm} {
|
| 1183 |
+
1 "+extra INTEGER" extra
|
| 1184 |
+
2 "+extra TEXT" extra
|
| 1185 |
+
3 "+extra BLOB" extra
|
| 1186 |
+
4 "+extra REAL" extra
|
| 1187 |
+
|
| 1188 |
+
5 "+col NOT NULL" col
|
| 1189 |
+
6 "+col CHECK (col IS NOT NULL)" col
|
| 1190 |
+
7 "+col REFERENCES tbl(x)" col
|
| 1191 |
+
} {
|
| 1192 |
+
do_execsql_test 1.$tn.1 "
|
| 1193 |
+
CREATE VIRTUAL TABLE rt USING rtree_i32(k, a,b, $auxcol)
|
| 1194 |
+
"
|
| 1195 |
+
|
| 1196 |
+
# Check that the aux column has no affinity. Or NOT NULL constraint.
|
| 1197 |
+
# And that the aux column is the child key of an FK constraint.
|
| 1198 |
+
#
|
| 1199 |
+
do_execsql_test 1.$tn.2 "
|
| 1200 |
+
INSERT INTO rt($nm) VALUES(NULL), (45), (-123.2), ('456'), (X'ABCD');
|
| 1201 |
+
SELECT typeof($nm), quote($nm) FROM rt;
|
| 1202 |
+
" {
|
| 1203 |
+
null NULL
|
| 1204 |
+
integer 45
|
| 1205 |
+
real -123.2
|
| 1206 |
+
text '456'
|
| 1207 |
+
blob X'ABCD'
|
| 1208 |
+
}
|
| 1209 |
+
|
| 1210 |
+
# Check that there is no UNIQUE constraint either.
|
| 1211 |
+
#
|
| 1212 |
+
do_execsql_test 1.$tn.3 "
|
| 1213 |
+
INSERT INTO rt($nm) VALUES('xyz'), ('xyz'), ('xyz');
|
| 1214 |
+
"
|
| 1215 |
+
|
| 1216 |
+
do_execsql_test 1.$tn.2 {
|
| 1217 |
+
DROP TABLE rt
|
| 1218 |
+
}
|
| 1219 |
+
}
|
| 1220 |
+
|
| 1221 |
+
#-------------------------------------------------------------------------
|
| 1222 |
+
#-------------------------------------------------------------------------
|
| 1223 |
+
# Section 5 of documentation.
|
| 1224 |
+
#-------------------------------------------------------------------------
|
| 1225 |
+
#-------------------------------------------------------------------------
|
| 1226 |
+
set testprefix rtreedoc-10
|
| 1227 |
+
|
| 1228 |
+
# EVIDENCE-OF: R-21011-43790 If integer coordinates are desired, declare
|
| 1229 |
+
# the table using "rtree_i32" instead: CREATE VIRTUAL TABLE intrtree
|
| 1230 |
+
# USING rtree_i32(id,x0,x1,y0,y1,z0,z1);
|
| 1231 |
+
do_execsql_test 1.0 {
|
| 1232 |
+
CREATE VIRTUAL TABLE intrtree USING rtree_i32(id,x0,x1,y0,y1,z0,z1);
|
| 1233 |
+
INSERT INTO intrtree DEFAULT VALUES;
|
| 1234 |
+
SELECT typeof(x0) FROM intrtree;
|
| 1235 |
+
} {integer}
|
| 1236 |
+
|
| 1237 |
+
# EVIDENCE-OF: R-09193-49806 An rtree_i32 stores coordinates as 32-bit
|
| 1238 |
+
# signed integers.
|
| 1239 |
+
#
|
| 1240 |
+
# Show that coordinates are cast in a way consistent with casting to
|
| 1241 |
+
# a signed 32-bit integer.
|
| 1242 |
+
do_execsql_test 1.1 {
|
| 1243 |
+
DELETE FROM intrtree;
|
| 1244 |
+
INSERT INTO intrtree VALUES(333,
|
| 1245 |
+
1<<44, (1<<44)+1,
|
| 1246 |
+
10000000000, 10000000001,
|
| 1247 |
+
-10000000001, -10000000000
|
| 1248 |
+
);
|
| 1249 |
+
SELECT * FROM intrtree;
|
| 1250 |
+
} {
|
| 1251 |
+
333 0 1 1410065408 1410065409 -1410065409 -1410065408
|
| 1252 |
+
}
|
| 1253 |
+
|
| 1254 |
+
#-------------------------------------------------------------------------
|
| 1255 |
+
#-------------------------------------------------------------------------
|
| 1256 |
+
# Section 7.1 of documentation.
|
| 1257 |
+
#-------------------------------------------------------------------------
|
| 1258 |
+
#-------------------------------------------------------------------------
|
| 1259 |
+
set testprefix rtreedoc-11
|
| 1260 |
+
reset_db
|
| 1261 |
+
|
| 1262 |
+
# This command assumes that the argument is a node blob for a 2 dimensional
|
| 1263 |
+
# i32 r-tree table. It decodes and returns a list of cells from the node
|
| 1264 |
+
# as a list. Each cell is itself a list of the following form:
|
| 1265 |
+
#
|
| 1266 |
+
# {$rowid $minX $maxX $minY $maxY}
|
| 1267 |
+
#
|
| 1268 |
+
# For internal (non-leaf) nodes, the rowid is replaced by the child node
|
| 1269 |
+
# number.
|
| 1270 |
+
#
|
| 1271 |
+
proc rnode {aData} {
|
| 1272 |
+
set nDim 2
|
| 1273 |
+
|
| 1274 |
+
set nData [string length $aData]
|
| 1275 |
+
set nBytePerCell [expr (8 + 2*$nDim*4)]
|
| 1276 |
+
binary scan [string range $aData 2 3] S nCell
|
| 1277 |
+
|
| 1278 |
+
set res [list]
|
| 1279 |
+
for {set i 0} {$i < $nCell} {incr i} {
|
| 1280 |
+
set iOff [expr $i*$nBytePerCell+4]
|
| 1281 |
+
set cell [string range $aData $iOff [expr $iOff+$nBytePerCell-1]]
|
| 1282 |
+
binary scan $cell WIIII rowid x1 x2 y1 y2
|
| 1283 |
+
lappend res [list $rowid $x1 $x2 $y1 $y2]
|
| 1284 |
+
}
|
| 1285 |
+
|
| 1286 |
+
return $res
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
# aData must be a node blob. This command returns true if the node contains
|
| 1290 |
+
# rowid $rowid, or false otherwise.
|
| 1291 |
+
#
|
| 1292 |
+
proc rnode_contains {aData rowid} {
|
| 1293 |
+
set L [rnode $aData]
|
| 1294 |
+
foreach cell $L {
|
| 1295 |
+
set r [lindex $cell 0]
|
| 1296 |
+
if {$r==$rowid} { return 1 }
|
| 1297 |
+
}
|
| 1298 |
+
return 0
|
| 1299 |
+
}
|
| 1300 |
+
|
| 1301 |
+
proc rnode_replace_cell {aData iCell cell} {
|
| 1302 |
+
set aCell [binary format WIIII {*}$cell]
|
| 1303 |
+
set nDim 2
|
| 1304 |
+
set nBytePerCell [expr (8 + 2*$nDim*4)]
|
| 1305 |
+
set iOff [expr $iCell*$nBytePerCell+4]
|
| 1306 |
+
|
| 1307 |
+
set aNew [binary format a*a*a* \
|
| 1308 |
+
[string range $aData 0 $iOff-1] \
|
| 1309 |
+
$aCell \
|
| 1310 |
+
[string range $aData $iOff+$nBytePerCell end] \
|
| 1311 |
+
]
|
| 1312 |
+
return $aNew
|
| 1313 |
+
}
|
| 1314 |
+
|
| 1315 |
+
db function rnode rnode
|
| 1316 |
+
db function rnode_contains rnode_contains
|
| 1317 |
+
db function rnode_replace_cell rnode_replace_cell
|
| 1318 |
+
|
| 1319 |
+
foreach {tn nm} {
|
| 1320 |
+
1 x1
|
| 1321 |
+
2 asdfghjkl
|
| 1322 |
+
3 hello_world
|
| 1323 |
+
} {
|
| 1324 |
+
do_execsql_test 1.$tn.1 "
|
| 1325 |
+
CREATE VIRTUAL TABLE $nm USING rtree(a,b,c,d,e);
|
| 1326 |
+
"
|
| 1327 |
+
|
| 1328 |
+
# EVIDENCE-OF: R-33789-46762 The content of an R*Tree index is actually
|
| 1329 |
+
# stored in three ordinary SQLite tables with names derived from the
|
| 1330 |
+
# name of the R*Tree.
|
| 1331 |
+
#
|
| 1332 |
+
# EVIDENCE-OF: R-39849-06566 This is their schema: CREATE TABLE
|
| 1333 |
+
# %_node(nodeno INTEGER PRIMARY KEY, data) CREATE TABLE %_parent(nodeno
|
| 1334 |
+
# INTEGER PRIMARY KEY, parentnode) CREATE TABLE %_rowid(rowid INTEGER
|
| 1335 |
+
# PRIMARY KEY, nodeno)
|
| 1336 |
+
#
|
| 1337 |
+
# EVIDENCE-OF: R-07489-10051 The "%" in the name of each shadow table is
|
| 1338 |
+
# replaced by the name of the R*Tree virtual table. So, if the name of
|
| 1339 |
+
# the R*Tree table is "xyz" then the three shadow tables would be
|
| 1340 |
+
# "xyz_node", "xyz_parent", and "xyz_rowid".
|
| 1341 |
+
do_execsql_test 1.$tn.2 {
|
| 1342 |
+
SELECT sql FROM sqlite_schema WHERE name!=$nm ORDER BY 1
|
| 1343 |
+
} [string map [list % $nm] "
|
| 1344 |
+
{CREATE TABLE \"%_node\"(nodeno INTEGER PRIMARY KEY,data)}
|
| 1345 |
+
{CREATE TABLE \"%_parent\"(nodeno INTEGER PRIMARY KEY,parentnode)}
|
| 1346 |
+
{CREATE TABLE \"%_rowid\"(rowid INTEGER PRIMARY KEY,nodeno)}
|
| 1347 |
+
"]
|
| 1348 |
+
|
| 1349 |
+
do_execsql_test 1.$tn "DROP TABLE $nm"
|
| 1350 |
+
}
|
| 1351 |
+
|
| 1352 |
+
|
| 1353 |
+
# EVIDENCE-OF: R-51070-59303 There is one entry in the %_node table for
|
| 1354 |
+
# each R*Tree node.
|
| 1355 |
+
#
|
| 1356 |
+
# The following creates a 6 node r-tree structure.
|
| 1357 |
+
#
|
| 1358 |
+
do_execsql_test 2.0 {
|
| 1359 |
+
CREATE VIRTUAL TABLE r1 USING rtree_i32(i, x1,x2, y1,y2);
|
| 1360 |
+
WITH t(i) AS (
|
| 1361 |
+
VALUES(1) UNION SELECT i+1 FROM t WHERE i<110
|
| 1362 |
+
)
|
| 1363 |
+
INSERT INTO r1 SELECT i, (i%10), (i%10)+2, (i%6), (i%7)+6 FROM t;
|
| 1364 |
+
}
|
| 1365 |
+
do_execsql_test 2.1 {
|
| 1366 |
+
SELECT count(*) FROM r1_node;
|
| 1367 |
+
} 6
|
| 1368 |
+
|
| 1369 |
+
# EVIDENCE-OF: R-27261-09153 All nodes other than the root have an entry
|
| 1370 |
+
# in the %_parent shadow table that identifies the parent node.
|
| 1371 |
+
#
|
| 1372 |
+
# In this case nodes 2-6 are the children of node 1.
|
| 1373 |
+
#
|
| 1374 |
+
do_execsql_test 2.3 {
|
| 1375 |
+
SELECT nodeno, parentnode FROM r1_parent
|
| 1376 |
+
} {2 1 3 1 4 1 5 1 6 1}
|
| 1377 |
+
|
| 1378 |
+
# EVIDENCE-OF: R-02358-35037 The %_rowid shadow table maps entry rowids
|
| 1379 |
+
# to the node that contains that entry.
|
| 1380 |
+
#
|
| 1381 |
+
do_execsql_test 2.4 {
|
| 1382 |
+
SELECT 'failed' FROM r1_rowid WHERE 0==rnode_contains(
|
| 1383 |
+
(SELECT data FROM r1_node WHERE nodeno=r1_rowid.nodeno), rowid
|
| 1384 |
+
)
|
| 1385 |
+
}
|
| 1386 |
+
do_test 2.5 {
|
| 1387 |
+
db eval { SELECT nodeno, data FROM r1_node WHERE nodeno!=1 } {
|
| 1388 |
+
set L [rnode $data]
|
| 1389 |
+
foreach cell $L {
|
| 1390 |
+
set rowid [lindex $cell 0]
|
| 1391 |
+
set rowid_nodeno 0
|
| 1392 |
+
db eval {SELECT nodeno AS rowid_nodeno FROM r1_rowid WHERE rowid=$rowid} {
|
| 1393 |
+
break
|
| 1394 |
+
}
|
| 1395 |
+
if {$rowid_nodeno!=$nodeno} { error "data mismatch!" }
|
| 1396 |
+
}
|
| 1397 |
+
}
|
| 1398 |
+
} {}
|
| 1399 |
+
|
| 1400 |
+
# EVIDENCE-OF: R-65201-22208 Extra columns appended to the %_rowid table
|
| 1401 |
+
# hold the content of auxiliary columns.
|
| 1402 |
+
#
|
| 1403 |
+
# EVIDENCE-OF: R-44161-28345 The names of these extra %_rowid columns
|
| 1404 |
+
# are probably not the same as the actual auxiliary column names.
|
| 1405 |
+
#
|
| 1406 |
+
# In this case, the auxiliary columns are named "e1" and "e2". The
|
| 1407 |
+
# extra %_rowid columns are named "a0" and "a1".
|
| 1408 |
+
#
|
| 1409 |
+
do_execsql_test 3.0 {
|
| 1410 |
+
CREATE VIRTUAL TABLE rtaux USING rtree(id, x1,x2, y1,y2, +e1, +e2);
|
| 1411 |
+
SELECT sql FROM sqlite_schema WHERE name='rtaux_rowid';
|
| 1412 |
+
} {
|
| 1413 |
+
{CREATE TABLE "rtaux_rowid"(rowid INTEGER PRIMARY KEY,nodeno,a0,a1)}
|
| 1414 |
+
}
|
| 1415 |
+
do_execsql_test 3.1 {
|
| 1416 |
+
INSERT INTO rtaux(e1, e2) VALUES('hello', 'world'), (123, 456);
|
| 1417 |
+
}
|
| 1418 |
+
do_execsql_test 3.2 {
|
| 1419 |
+
SELECT a0, a1 FROM rtaux_rowid;
|
| 1420 |
+
} {
|
| 1421 |
+
hello world 123 456
|
| 1422 |
+
}
|
| 1423 |
+
|
| 1424 |
+
#-------------------------------------------------------------------------
|
| 1425 |
+
#-------------------------------------------------------------------------
|
| 1426 |
+
# Section 7.2 of documentation.
|
| 1427 |
+
#-------------------------------------------------------------------------
|
| 1428 |
+
#-------------------------------------------------------------------------
|
| 1429 |
+
set testprefix rtreedoc-12
|
| 1430 |
+
reset_db
|
| 1431 |
+
forcedelete test.db2
|
| 1432 |
+
|
| 1433 |
+
db function rnode rnode
|
| 1434 |
+
db function rnode_contains rnode_contains
|
| 1435 |
+
db function rnode_replace_cell rnode_replace_cell
|
| 1436 |
+
|
| 1437 |
+
# EVIDENCE-OF: R-13571-45795 The scalar SQL function rtreecheck(R) or
|
| 1438 |
+
# rtreecheck(S,R) runs an integrity check on the rtree table named R
|
| 1439 |
+
# contained within database S.
|
| 1440 |
+
#
|
| 1441 |
+
# EVIDENCE-OF: R-36011-59963 The function returns a human-language
|
| 1442 |
+
# description of any problems found, or the string 'ok' if everything is
|
| 1443 |
+
# ok.
|
| 1444 |
+
#
|
| 1445 |
+
do_execsql_test 1.0 {
|
| 1446 |
+
CREATE VIRTUAL TABLE rt1 USING rtree(id, a, b);
|
| 1447 |
+
WITH s(i) AS (
|
| 1448 |
+
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<200
|
| 1449 |
+
)
|
| 1450 |
+
INSERT INTO rt1 SELECT i, i, i FROM s;
|
| 1451 |
+
|
| 1452 |
+
ATTACH 'test.db2' AS 'aux';
|
| 1453 |
+
CREATE VIRTUAL TABLE aux.rt1 USING rtree(id, a, b);
|
| 1454 |
+
INSERT INTO aux.rt1 SELECT * FROM rt1;
|
| 1455 |
+
}
|
| 1456 |
+
|
| 1457 |
+
do_execsql_test 1.1.1 { SELECT rtreecheck('rt1'); } {ok}
|
| 1458 |
+
do_execsql_test 1.1.2 { SELECT rtreecheck('main', 'rt1'); } {ok}
|
| 1459 |
+
do_execsql_test 1.1.3 { SELECT rtreecheck('aux', 'rt1'); } {ok}
|
| 1460 |
+
do_catchsql_test 1.1.4 {
|
| 1461 |
+
SELECT rtreecheck('nosuchdb', 'rt1');
|
| 1462 |
+
} {1 {SQL logic error}}
|
| 1463 |
+
|
| 1464 |
+
# Corrupt the table in database 'main':
|
| 1465 |
+
do_execsql_test 1.2.1 { UPDATE rt1_node SET nodeno=21 WHERE nodeno=3; }
|
| 1466 |
+
do_execsql_test 1.2.1 { SELECT rtreecheck('rt1')=='ok'; } {0}
|
| 1467 |
+
do_execsql_test 1.2.2 { SELECT rtreecheck('main', 'rt1')=='ok'; } {0}
|
| 1468 |
+
do_execsql_test 1.2.3 { SELECT rtreecheck('aux', 'rt1')=='ok'; } {1}
|
| 1469 |
+
do_execsql_test 1.2.4 { UPDATE rt1_node SET nodeno=3 WHERE nodeno=21; }
|
| 1470 |
+
|
| 1471 |
+
# Corrupt the table in database 'aux':
|
| 1472 |
+
do_execsql_test 1.2.1 { UPDATE aux.rt1_node SET nodeno=21 WHERE nodeno=3; }
|
| 1473 |
+
do_execsql_test 1.2.1 { SELECT rtreecheck('rt1')=='ok'; } {1}
|
| 1474 |
+
do_execsql_test 1.2.2 { SELECT rtreecheck('main', 'rt1')=='ok'; } {1}
|
| 1475 |
+
do_execsql_test 1.2.3 { SELECT rtreecheck('aux', 'rt1')=='ok'; } {0}
|
| 1476 |
+
do_execsql_test 1.2.4 { UPDATE rt1_node SET nodeno=3 WHERE nodeno=21; }
|
| 1477 |
+
|
| 1478 |
+
# EVIDENCE-OF: R-45759-33459 Example: To verify that an R*Tree named
|
| 1479 |
+
# "demo_index" is well-formed and internally consistent, run: SELECT
|
| 1480 |
+
# rtreecheck('demo_index');
|
| 1481 |
+
do_execsql_test 2.0 {
|
| 1482 |
+
CREATE VIRTUAL TABLE demo_index USING rtree(id, x1,x2, y1,y2);
|
| 1483 |
+
INSERT INTO demo_index SELECT id, a, b, a, b FROM rt1;
|
| 1484 |
+
}
|
| 1485 |
+
do_execsql_test 2.1 { SELECT rtreecheck('demo_index') } {ok}
|
| 1486 |
+
do_execsql_test 2.2 {
|
| 1487 |
+
UPDATE demo_index_rowid SET nodeno=44 WHERE rowid=44;
|
| 1488 |
+
SELECT rtreecheck('demo_index');
|
| 1489 |
+
} {{Found (44 -> 44) in %_rowid table, expected (44 -> 4)}}
|
| 1490 |
+
|
| 1491 |
+
|
| 1492 |
+
do_execsql_test 3.0 {
|
| 1493 |
+
CREATE VIRTUAL TABLE rt2 USING rtree_i32(id, a, b, c, d);
|
| 1494 |
+
WITH s(i) AS (
|
| 1495 |
+
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<200
|
| 1496 |
+
)
|
| 1497 |
+
INSERT INTO rt2 SELECT i, i, i+2, i, i+2 FROM s;
|
| 1498 |
+
}
|
| 1499 |
+
|
| 1500 |
+
# EVIDENCE-OF: R-02555-31045 for each dimension, (coord1 <= coord2).
|
| 1501 |
+
#
|
| 1502 |
+
execsql BEGIN
|
| 1503 |
+
do_test 3.1 {
|
| 1504 |
+
set cell [
|
| 1505 |
+
lindex [execsql {SELECT rnode(data) FROM rt2_node WHERE nodeno=3}] 0 3
|
| 1506 |
+
]
|
| 1507 |
+
set cell [list [lindex $cell 0] \
|
| 1508 |
+
[lindex $cell 2] [lindex $cell 1] \
|
| 1509 |
+
[lindex $cell 3] [lindex $cell 4] \
|
| 1510 |
+
]
|
| 1511 |
+
execsql {
|
| 1512 |
+
UPDATE rt2_node SET data=rnode_replace_cell(data, 3, $cell) WHERE nodeno=3
|
| 1513 |
+
}
|
| 1514 |
+
execsql { SELECT rtreecheck('rt2') }
|
| 1515 |
+
} {{Dimension 0 of cell 3 on node 3 is corrupt}}
|
| 1516 |
+
execsql ROLLBACK
|
| 1517 |
+
|
| 1518 |
+
# EVIDENCE-OF: R-13844-15873 unless the cell is on the root node, that
|
| 1519 |
+
# the cell is bounded by the parent cell on the parent node.
|
| 1520 |
+
#
|
| 1521 |
+
execsql BEGIN
|
| 1522 |
+
do_test 3.2 {
|
| 1523 |
+
set cell [
|
| 1524 |
+
lindex [execsql {SELECT rnode(data) FROM rt2_node WHERE nodeno=3}] 0 3
|
| 1525 |
+
]
|
| 1526 |
+
lset cell 3 450
|
| 1527 |
+
lset cell 4 451
|
| 1528 |
+
execsql {
|
| 1529 |
+
UPDATE rt2_node SET data=rnode_replace_cell(data, 3, $cell) WHERE nodeno=3
|
| 1530 |
+
}
|
| 1531 |
+
execsql { SELECT rtreecheck('rt2') }
|
| 1532 |
+
} {{Dimension 1 of cell 3 on node 3 is corrupt relative to parent}}
|
| 1533 |
+
execsql ROLLBACK
|
| 1534 |
+
|
| 1535 |
+
# EVIDENCE-OF: R-02505-03621 for leaf nodes, that there is an entry in
|
| 1536 |
+
# the %_rowid table corresponding to the cell's rowid value that points
|
| 1537 |
+
# to the correct node.
|
| 1538 |
+
#
|
| 1539 |
+
execsql BEGIN
|
| 1540 |
+
do_test 3.3 {
|
| 1541 |
+
execsql {
|
| 1542 |
+
UPDATE rt2_rowid SET rowid=452 WHERE rowid=100
|
| 1543 |
+
}
|
| 1544 |
+
execsql { SELECT rtreecheck('rt2') }
|
| 1545 |
+
} {{Mapping (100 -> 6) missing from %_rowid table}}
|
| 1546 |
+
execsql ROLLBACK
|
| 1547 |
+
|
| 1548 |
+
# EVIDENCE-OF: R-50927-02218 for cells on non-leaf nodes, that there is
|
| 1549 |
+
# an entry in the %_parent table mapping from the cell's child node to
|
| 1550 |
+
# the node that it resides on.
|
| 1551 |
+
#
|
| 1552 |
+
execsql BEGIN
|
| 1553 |
+
do_test 3.4.1 {
|
| 1554 |
+
execsql {
|
| 1555 |
+
UPDATE rt2_parent SET parentnode=123 WHERE nodeno=3
|
| 1556 |
+
}
|
| 1557 |
+
execsql { SELECT rtreecheck('rt2') }
|
| 1558 |
+
} {{Found (3 -> 123) in %_parent table, expected (3 -> 1)}}
|
| 1559 |
+
execsql ROLLBACK
|
| 1560 |
+
execsql BEGIN
|
| 1561 |
+
do_test 3.4.2 {
|
| 1562 |
+
execsql {
|
| 1563 |
+
UPDATE rt2_parent SET nodeno=123 WHERE nodeno=3
|
| 1564 |
+
}
|
| 1565 |
+
execsql { SELECT rtreecheck('rt2') }
|
| 1566 |
+
} {{Mapping (3 -> 1) missing from %_parent table}}
|
| 1567 |
+
execsql ROLLBACK
|
| 1568 |
+
|
| 1569 |
+
# EVIDENCE-OF: R-23235-09153 That there are the same number of entries
|
| 1570 |
+
# in the %_rowid table as there are leaf cells in the r-tree structure,
|
| 1571 |
+
# and that there is a leaf cell that corresponds to each entry in the
|
| 1572 |
+
# %_rowid table.
|
| 1573 |
+
execsql BEGIN
|
| 1574 |
+
do_test 3.5 {
|
| 1575 |
+
execsql { INSERT INTO rt2_rowid VALUES(1000, 1000) }
|
| 1576 |
+
execsql { SELECT rtreecheck('rt2') }
|
| 1577 |
+
} {{Wrong number of entries in %_rowid table - expected 200, actual 201}}
|
| 1578 |
+
execsql ROLLBACK
|
| 1579 |
+
|
| 1580 |
+
# EVIDENCE-OF: R-62800-43436 That there are the same number of entries
|
| 1581 |
+
# in the %_parent table as there are non-leaf cells in the r-tree
|
| 1582 |
+
# structure, and that there is a non-leaf cell that corresponds to each
|
| 1583 |
+
# entry in the %_parent table.
|
| 1584 |
+
execsql BEGIN
|
| 1585 |
+
do_test 3.6 {
|
| 1586 |
+
execsql { INSERT INTO rt2_parent VALUES(1000, 1000) }
|
| 1587 |
+
execsql { SELECT rtreecheck('rt2') }
|
| 1588 |
+
} {{Wrong number of entries in %_parent table - expected 10, actual 11}}
|
| 1589 |
+
execsql ROLLBACK
|
| 1590 |
+
|
| 1591 |
+
|
| 1592 |
+
|
| 1593 |
+
finish_test
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreedoc2.test
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2021 September 13
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# The focus of this file is testing the r-tree extension.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
set testprefix rtreedoc2
|
| 21 |
+
|
| 22 |
+
ifcapable !rtree {
|
| 23 |
+
finish_test
|
| 24 |
+
return
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
#-------------------------------------------------------------------------
|
| 28 |
+
#-------------------------------------------------------------------------
|
| 29 |
+
# Section 6 of documentation.
|
| 30 |
+
#-------------------------------------------------------------------------
|
| 31 |
+
#-------------------------------------------------------------------------
|
| 32 |
+
set testprefix rtreedoc2-1
|
| 33 |
+
|
| 34 |
+
# EVIDENCE-OF: R-35254-48865 A call to one of the above APIs creates a
|
| 35 |
+
# new SQL function named by the second parameter (zQueryFunc or zGeom).
|
| 36 |
+
#
|
| 37 |
+
# [register_circle_geom db] registers new geometry callback "Qcircle"
|
| 38 |
+
# and legacy implementation "circle". Test that these do actually appear.
|
| 39 |
+
#
|
| 40 |
+
do_execsql_test 1.1.0 {
|
| 41 |
+
SELECT * FROM pragma_function_list WHERE name IN('circle', 'qcircle');
|
| 42 |
+
} {
|
| 43 |
+
}
|
| 44 |
+
do_test 1.1 {
|
| 45 |
+
register_circle_geom db
|
| 46 |
+
} {SQLITE_OK}
|
| 47 |
+
do_execsql_test 1.1.2 {
|
| 48 |
+
SELECT * FROM pragma_function_list WHERE name = 'circle' AND enc='utf8';
|
| 49 |
+
} {
|
| 50 |
+
circle 0 s utf8 -1 0
|
| 51 |
+
}
|
| 52 |
+
do_execsql_test 1.1.3 {
|
| 53 |
+
SELECT * FROM pragma_function_list WHERE name = 'qcircle' AND enc='utf8';
|
| 54 |
+
} {
|
| 55 |
+
qcircle 0 s utf8 -1 0
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
do_execsql_test 1.2.0 { SELECT circle(1, 2, 3); } {{}}
|
| 59 |
+
do_execsql_test 1.2.1 { SELECT qcircle(1, 2, 3); } {{}}
|
| 60 |
+
|
| 61 |
+
# EVIDENCE-OF: R-61427-46983
|
| 62 |
+
do_execsql_test 1.3.0 {
|
| 63 |
+
CREATE VIRTUAL TABLE demo_index USING rtree(id, x1,x2, y1,y2);
|
| 64 |
+
INSERT INTO demo_index VALUES(10, 45,45, 24,24);
|
| 65 |
+
INSERT INTO demo_index VALUES(20, 50,50, 28,28);
|
| 66 |
+
INSERT INTO demo_index VALUES(30, 43,43, 22,22);
|
| 67 |
+
}
|
| 68 |
+
do_execsql_test 1.3.1 {
|
| 69 |
+
SELECT id FROM demo_index WHERE id MATCH circle(45.3, 22.9, 5.0)
|
| 70 |
+
} {10 30}
|
| 71 |
+
|
| 72 |
+
# EVIDENCE-OF: R-16907-50223 The SQL syntax for custom queries is the
|
| 73 |
+
# same regardless of which interface, sqlite3_rtree_geometry_callback()
|
| 74 |
+
# or sqlite3_rtree_query_callback(), is used to register the SQL
|
| 75 |
+
# function.
|
| 76 |
+
do_execsql_test 1.3.2 {
|
| 77 |
+
SELECT id FROM demo_index WHERE id MATCH qcircle(45.3, 22.9, 5.0, 1)
|
| 78 |
+
} {10 30}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# EVIDENCE-OF: R-59634-51678 When that SQL function appears on the
|
| 82 |
+
# right-hand side of the MATCH operator and the left-hand side of the
|
| 83 |
+
# MATCH operator is any column in the R*Tree virtual table, then the
|
| 84 |
+
# callback defined by the third argument (xQueryFunc or xGeom) is
|
| 85 |
+
# invoked to determine if a particular object or subtree overlaps the
|
| 86 |
+
# desired region.
|
| 87 |
+
proc box_geom {args} {
|
| 88 |
+
lappend ::box_geom [concat [lindex $args 0] [lrange $args 2 end-1]]
|
| 89 |
+
return ""
|
| 90 |
+
}
|
| 91 |
+
register_box_geom db box_geom
|
| 92 |
+
set box_geom [list]
|
| 93 |
+
do_execsql_test 1.3.2 {
|
| 94 |
+
SELECT id FROM demo_index WHERE id MATCH box(43,46, 21,25);
|
| 95 |
+
} {10 30}
|
| 96 |
+
do_test 1.3.3 {
|
| 97 |
+
set ::box_geom
|
| 98 |
+
} [list {*}{
|
| 99 |
+
{box {43.0 46.0 21.0 25.0} {45.0 45.0 24.0 24.0}}
|
| 100 |
+
{box {43.0 46.0 21.0 25.0} {50.0 50.0 28.0 28.0}}
|
| 101 |
+
{box {43.0 46.0 21.0 25.0} {43.0 43.0 22.0 22.0}}
|
| 102 |
+
}]
|
| 103 |
+
|
| 104 |
+
#-------------------------------------------------------------------------
|
| 105 |
+
#-------------------------------------------------------------------------
|
| 106 |
+
# Section 6 of documentation.
|
| 107 |
+
#-------------------------------------------------------------------------
|
| 108 |
+
#-------------------------------------------------------------------------
|
| 109 |
+
set testprefix rtreedoc2-2
|
| 110 |
+
|
| 111 |
+
# EVIDENCE-OF: R-02424-24769 The second argument is the number of
|
| 112 |
+
# coordinates in each r-tree entry, and is always the same for any given
|
| 113 |
+
# R*Tree.
|
| 114 |
+
#
|
| 115 |
+
# EVIDENCE-OF: R-40260-16838 The number of coordinates is 2 for a
|
| 116 |
+
# 1-dimensional R*Tree, 4 for a 2-dimensional R*Tree, 6 for a
|
| 117 |
+
# 3-dimensional R*Tree, and so forth.
|
| 118 |
+
#
|
| 119 |
+
# The second argument refered to above is the length of the list passed
|
| 120 |
+
# as the 3rd parameter to the Tcl script.
|
| 121 |
+
#
|
| 122 |
+
do_execsql_test 1.0 {
|
| 123 |
+
CREATE VIRTUAL TABLE rt1 USING rtree(id, x1,x2);
|
| 124 |
+
CREATE VIRTUAL TABLE rt2 USING rtree(id, x1,x2, y1,y2);
|
| 125 |
+
CREATE VIRTUAL TABLE rt3 USING rtree(id, x1,x2, y1,y2, z1,z2);
|
| 126 |
+
|
| 127 |
+
INSERT INTO rt1 DEFAULT VALUES;
|
| 128 |
+
INSERT INTO rt2 DEFAULT VALUES;
|
| 129 |
+
INSERT INTO rt3 DEFAULT VALUES;
|
| 130 |
+
}
|
| 131 |
+
foreach {tn tbl nCoord} {
|
| 132 |
+
1 rt1 2
|
| 133 |
+
2 rt2 4
|
| 134 |
+
3 rt3 6
|
| 135 |
+
} {
|
| 136 |
+
set ::box_geom [list]
|
| 137 |
+
do_catchsql_test 1.$tn.1 "
|
| 138 |
+
SELECT id FROM $tbl WHERE id MATCH box();
|
| 139 |
+
" {1 {SQL logic error}}
|
| 140 |
+
|
| 141 |
+
do_test 1.$tn.2 {
|
| 142 |
+
llength [lindex $::box_geom 0 2]
|
| 143 |
+
} $nCoord
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
# EVIDENCE-OF: R-28051-48608 If xGeom returns anything other than
|
| 147 |
+
# SQLITE_OK, then the r-tree query will abort with an error.
|
| 148 |
+
proc box_geom {args} {
|
| 149 |
+
error "an error!"
|
| 150 |
+
}
|
| 151 |
+
do_catchsql_test 2.0 {
|
| 152 |
+
SELECT * FROM rt2 WHERE id MATCH box(22,23, 24,25);
|
| 153 |
+
} {1 {SQL logic error}}
|
| 154 |
+
|
| 155 |
+
do_execsql_test 3.0 {
|
| 156 |
+
INSERT INTO rt1 VALUES(10, 10, 10);
|
| 157 |
+
INSERT INTO rt1 VALUES(11, 11, 11);
|
| 158 |
+
INSERT INTO rt1 VALUES(12, 12, 12);
|
| 159 |
+
INSERT INTO rt1 VALUES(13, 13, 13);
|
| 160 |
+
INSERT INTO rt1 VALUES(14, 14, 14);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
# EVIDENCE-OF: R-53759-57366 The exact same sqlite3_rtree_geometry
|
| 164 |
+
# structure is used for every callback for same MATCH operator in the
|
| 165 |
+
# same query.
|
| 166 |
+
proc box_geom {args} {
|
| 167 |
+
lappend ::ptr_list [lindex $args 4]
|
| 168 |
+
return 0
|
| 169 |
+
}
|
| 170 |
+
set ::ptr_list [list]
|
| 171 |
+
do_execsql_test 3.1 {
|
| 172 |
+
SELECT * FROM rt1 WHERE id MATCH box(1,1);
|
| 173 |
+
}
|
| 174 |
+
do_test 3.2 {
|
| 175 |
+
set val [lindex $::ptr_list 0]
|
| 176 |
+
foreach p $::ptr_list {
|
| 177 |
+
if {$p!=$val} {error "pointer mismatch"}
|
| 178 |
+
}
|
| 179 |
+
} {}
|
| 180 |
+
|
| 181 |
+
# EVIDENCE-OF: R-60247-35692 The contents of the sqlite3_rtree_geometry
|
| 182 |
+
# structure are initialized by SQLite but are not subsequently modified.
|
| 183 |
+
proc box_geom {args} {
|
| 184 |
+
lappend ::box_geom [concat [lindex $args 0] [lrange $args 2 end-1]]
|
| 185 |
+
if {[llength $::box_geom]==3} {
|
| 186 |
+
return "zero"
|
| 187 |
+
}
|
| 188 |
+
return ""
|
| 189 |
+
}
|
| 190 |
+
set ::box_geom [list]
|
| 191 |
+
do_catchsql_test 3.2 {
|
| 192 |
+
SELECT * FROM rt1 WHERE id MATCH box(1,1);
|
| 193 |
+
} {1 {SQL logic error}}
|
| 194 |
+
do_test 3.3 {
|
| 195 |
+
set ::box_geom
|
| 196 |
+
} [list {*}{
|
| 197 |
+
{box {1.0 1.0} {0.0 0.0}}
|
| 198 |
+
{box {1.0 1.0} {10.0 10.0}}
|
| 199 |
+
{box {1.0 1.0} {11.0 11.0}}
|
| 200 |
+
{box 0.0 {12.0 12.0}}
|
| 201 |
+
}]
|
| 202 |
+
|
| 203 |
+
# EVIDENCE-OF: R-31246-29731 The pContext member of the
|
| 204 |
+
# sqlite3_rtree_geometry structure is always set to a copy of the
|
| 205 |
+
# pContext argument passed to sqlite3_rtree_geometry_callback() when the
|
| 206 |
+
# callback is registered.
|
| 207 |
+
reset_db
|
| 208 |
+
do_execsql_test 4.0 {
|
| 209 |
+
CREATE VIRTUAL TABLE r1 USING rtree(id, minX,maxX, minY,maxY);
|
| 210 |
+
WITH s(i) AS (
|
| 211 |
+
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<120
|
| 212 |
+
)
|
| 213 |
+
INSERT INTO r1 SELECT i,i,i+1, 200,201 FROM s;
|
| 214 |
+
}
|
| 215 |
+
set ctx [register_box_geom db box_geom]
|
| 216 |
+
set ::box_geom [list]
|
| 217 |
+
proc box_geom {args} {
|
| 218 |
+
lappend ::box_geom [lindex $args 1]
|
| 219 |
+
return ""
|
| 220 |
+
}
|
| 221 |
+
do_execsql_test 4.1 {
|
| 222 |
+
SELECT count(*) FROM r1 WHERE id MATCH box(0,150,199,201)
|
| 223 |
+
} 120
|
| 224 |
+
do_test 4.2 {
|
| 225 |
+
foreach g $::box_geom {
|
| 226 |
+
if {$g!=$ctx} {error "pointer mismatch"}
|
| 227 |
+
}
|
| 228 |
+
} {}
|
| 229 |
+
|
| 230 |
+
# EVIDENCE-OF: R-09904-19077 The aParam[] array (size nParam) contains
|
| 231 |
+
# the parameter values passed to the SQL function on the right-hand side
|
| 232 |
+
# of the MATCH operator.
|
| 233 |
+
proc box_geom {args} {
|
| 234 |
+
set ::box_geom [lindex $args 2]
|
| 235 |
+
}
|
| 236 |
+
foreach {tn q vals} {
|
| 237 |
+
1 "SELECT count(*) FROM r1 WHERE id MATCH box(1,2,3)" {1.0 2.0 3.0}
|
| 238 |
+
2 "SELECT count(*) FROM r1 WHERE id MATCH box(10001)" {10001.0}
|
| 239 |
+
3 "SELECT count(*) FROM r1 WHERE id MATCH box(-10001)" {-10001.0}
|
| 240 |
+
} {
|
| 241 |
+
do_catchsql_test 5.$tn.1 $q {1 {SQL logic error}}
|
| 242 |
+
do_test 5.$tn.2 { set ::box_geom } $vals
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
do_execsql_test 5.0 {
|
| 246 |
+
CREATE VIRTUAL TABLE myrtree USING rtree(id, x1,x2);
|
| 247 |
+
INSERT INTO myrtree VALUES(1, 1, 1);
|
| 248 |
+
INSERT INTO myrtree VALUES(2, 2, 2);
|
| 249 |
+
INSERT INTO myrtree VALUES(3, 3, 3);
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
# EVIDENCE-OF: R-44448-00687 The pUser and xDelUser members of the
|
| 253 |
+
# sqlite3_rtree_geometry structure are initially set to NULL.
|
| 254 |
+
set ::box_geom_calls 0
|
| 255 |
+
proc box_geom {args} {
|
| 256 |
+
incr ::box_geom_calls
|
| 257 |
+
return user_is_zero
|
| 258 |
+
}
|
| 259 |
+
do_execsql_test 5.1.1 {
|
| 260 |
+
SELECT * FROM myrtree WHERE id MATCH box(4, 5);
|
| 261 |
+
}
|
| 262 |
+
do_test 5.1.2 { set ::box_geom_calls } 3
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
# EVIDENCE-OF: R-55837-00155 The pUser variable may be set by the
|
| 266 |
+
# callback implementation to any arbitrary value that may be useful to
|
| 267 |
+
# subsequent invocations of the callback within the same query (for
|
| 268 |
+
# example, a pointer to a complicated data structure used to test for
|
| 269 |
+
# region intersection).
|
| 270 |
+
#
|
| 271 |
+
# EVIDENCE-OF: R-34745-08839 If the xDelUser variable is set to a
|
| 272 |
+
# non-NULL value, then after the query has finished running SQLite
|
| 273 |
+
# automatically invokes it with the value of the pUser variable as the
|
| 274 |
+
# only argument.
|
| 275 |
+
#
|
| 276 |
+
set ::box_geom_calls 0
|
| 277 |
+
proc box_geom {args} {
|
| 278 |
+
incr ::box_geom_calls
|
| 279 |
+
switch -- $::box_geom_calls {
|
| 280 |
+
1 {
|
| 281 |
+
return user_is_zero
|
| 282 |
+
}
|
| 283 |
+
2 {
|
| 284 |
+
return [list user box_geom_finalizer]
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
return ""
|
| 288 |
+
}
|
| 289 |
+
proc box_geom_finalizer {} {
|
| 290 |
+
set ::box_geom_finalizer "::box_geom_calls is $::box_geom_calls"
|
| 291 |
+
}
|
| 292 |
+
do_execsql_test 5.1.1 {
|
| 293 |
+
SELECT * FROM myrtree WHERE id MATCH box(4, 5);
|
| 294 |
+
}
|
| 295 |
+
do_test 5.1.2 { set ::box_geom_calls } 3
|
| 296 |
+
do_test 5.1.3 {
|
| 297 |
+
set ::box_geom_finalizer
|
| 298 |
+
} {::box_geom_calls is 3}
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
# EVIDENCE-OF: R-28176-28813 The xGeom callback always does a
|
| 302 |
+
# depth-first search of the r-tree.
|
| 303 |
+
#
|
| 304 |
+
# For a breadth first search, final test case would return "B L" only.
|
| 305 |
+
#
|
| 306 |
+
do_execsql_test 6.0 {
|
| 307 |
+
CREATE VIRTUAL TABLE xyz USING rtree(x, x1,x2, y1,y2);
|
| 308 |
+
WITH s(i) AS (
|
| 309 |
+
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<15
|
| 310 |
+
)
|
| 311 |
+
INSERT INTO xyz SELECT NULL, one.i,one.i+1, two.i,two.i+1 FROM s one, s two;
|
| 312 |
+
}
|
| 313 |
+
do_execsql_test 6.1 {
|
| 314 |
+
SELECT count(*) FROM xyz_node
|
| 315 |
+
} {10}
|
| 316 |
+
proc box_geom {args} {
|
| 317 |
+
set coords [lindex $args 3]
|
| 318 |
+
set area [expr {
|
| 319 |
+
([lindex $coords 1]-[lindex $coords 0]) *
|
| 320 |
+
([lindex $coords 3]-[lindex $coords 2])
|
| 321 |
+
}]
|
| 322 |
+
if {$area==1} {
|
| 323 |
+
lappend ::box_geom_calls L
|
| 324 |
+
} else {
|
| 325 |
+
lappend ::box_geom_calls B
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
set ::box_geom_calls [list]
|
| 329 |
+
do_execsql_test 6.2 {
|
| 330 |
+
SELECT count(*) FROM xyz WHERE x MATCH box(0,20,0,20)
|
| 331 |
+
} 225
|
| 332 |
+
do_test 6.3 {
|
| 333 |
+
set prev ""
|
| 334 |
+
set box_calls [list]
|
| 335 |
+
foreach c $::box_geom_calls {
|
| 336 |
+
if {$c!=$prev} {
|
| 337 |
+
lappend ::box_calls $c
|
| 338 |
+
set prev $c
|
| 339 |
+
}
|
| 340 |
+
}
|
| 341 |
+
set ::box_calls
|
| 342 |
+
} {B L B L B L B L B L B L B L B L B L}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
finish_test
|
| 346 |
+
|
local-test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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2021 September 13
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# The focus of this file is testing the r-tree extension.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
set testprefix rtreedoc3
|
| 21 |
+
|
| 22 |
+
ifcapable !rtree {
|
| 23 |
+
finish_test
|
| 24 |
+
return
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# This command assumes that the argument is a node blob for a 2 dimensional
|
| 29 |
+
# i32 r-tree table. It decodes and returns a list of cells from the node
|
| 30 |
+
# as a list. Each cell is itself a list of the following form:
|
| 31 |
+
#
|
| 32 |
+
# {$rowid $minX $maxX $minY $maxY}
|
| 33 |
+
#
|
| 34 |
+
# For internal (non-leaf) nodes, the rowid is replaced by the child node
|
| 35 |
+
# number.
|
| 36 |
+
#
|
| 37 |
+
proc rnode_cells {aData} {
|
| 38 |
+
set nDim 2
|
| 39 |
+
|
| 40 |
+
set nData [string length $aData]
|
| 41 |
+
set nBytePerCell [expr (8 + 2*$nDim*4)]
|
| 42 |
+
binary scan [string range $aData 2 3] S nCell
|
| 43 |
+
|
| 44 |
+
set res [list]
|
| 45 |
+
for {set i 0} {$i < $nCell} {incr i} {
|
| 46 |
+
set iOff [expr $i*$nBytePerCell+4]
|
| 47 |
+
set cell [string range $aData $iOff [expr $iOff+$nBytePerCell-1]]
|
| 48 |
+
binary scan $cell WIIII rowid x1 x2 y1 y2
|
| 49 |
+
lappend res [list $rowid $x1 $x2 $y1 $y2]
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
return $res
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
# Interpret the first two bytes of the blob passed as the only parameter
|
| 56 |
+
# as a 16-bit big-endian integer and return the value. If this blob is
|
| 57 |
+
# the root node of an r-tree, this value is the height of the tree.
|
| 58 |
+
#
|
| 59 |
+
proc rnode_height {aData} {
|
| 60 |
+
binary scan [string range $aData 0 1] S nHeight
|
| 61 |
+
return $nHeight
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
# Return a blob containing node iNode of r-tree "rt".
|
| 65 |
+
#
|
| 66 |
+
proc rt_node_get {iNode} {
|
| 67 |
+
db one { SELECT data FROM rt_node WHERE nodeno=$iNode }
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
#--------------------------------------------------------------
|
| 72 |
+
# API:
|
| 73 |
+
#
|
| 74 |
+
# pq_init
|
| 75 |
+
# Initialize a new test.
|
| 76 |
+
#
|
| 77 |
+
# pq_test_callback
|
| 78 |
+
# Invoked each time the xQueryCallback function is called. This Tcl
|
| 79 |
+
# command checks that the arguments that SQLite passed to xQueryCallback
|
| 80 |
+
# are as expected.
|
| 81 |
+
#
|
| 82 |
+
# pq_test_row
|
| 83 |
+
# Invoked each time a row is returned. Checks that the row returned
|
| 84 |
+
# was predicted by the documentation.
|
| 85 |
+
#
|
| 86 |
+
# DATA STRUCTURE:
|
| 87 |
+
# The priority queue is stored as a Tcl list. The order of elements in
|
| 88 |
+
# the list is unimportant - it is just used as a set here. Each element
|
| 89 |
+
# in the priority queue is itself a list. The first element is the
|
| 90 |
+
# priority value for the entry (a real). Following this is a list of
|
| 91 |
+
# key-value pairs that make up the entries fields.
|
| 92 |
+
#
|
| 93 |
+
proc pq_init {} {
|
| 94 |
+
global Q
|
| 95 |
+
set Q(pri_queue) [list]
|
| 96 |
+
|
| 97 |
+
set nHeight [rnode_height [rt_node_get 1]]
|
| 98 |
+
set nCell [llength [rnode_cells [rt_node_get 1]]]
|
| 99 |
+
|
| 100 |
+
# EVIDENCE-OF: R-54708-13595 An R*Tree query is initialized by making
|
| 101 |
+
# the root node the only entry in a priority queue sorted by rScore.
|
| 102 |
+
lappend Q(pri_queue) [list 0.0 [list \
|
| 103 |
+
iLevel [expr $nHeight+1] \
|
| 104 |
+
iChild 1 \
|
| 105 |
+
iCurrent 0 \
|
| 106 |
+
]]
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
proc pq_extract {} {
|
| 110 |
+
global Q
|
| 111 |
+
if {[llength $Q(pri_queue)]==0} {
|
| 112 |
+
error "priority queue is empty!"
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
# Find the priority queue entry with the lowest score.
|
| 116 |
+
#
|
| 117 |
+
# EVIDENCE-OF: R-47257-47871 Smaller scores are processed first.
|
| 118 |
+
set iBest 0
|
| 119 |
+
set rBestScore [lindex $Q(pri_queue) 0 0]
|
| 120 |
+
for {set ii 1} {$ii < [llength $Q(pri_queue)]} {incr ii} {
|
| 121 |
+
set rScore [expr [lindex $Q(pri_queue) $ii 0]]
|
| 122 |
+
if {$rScore<$rBestScore} {
|
| 123 |
+
set rBestScore $rScore
|
| 124 |
+
set iBest $ii
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
# Extract the entry with the lowest score from the queue and return it.
|
| 129 |
+
#
|
| 130 |
+
# EVIDENCE-OF: R-60002-49798 The query proceeds by extracting the entry
|
| 131 |
+
# from the priority queue that has the lowest score.
|
| 132 |
+
set ret [lindex $Q(pri_queue) $iBest]
|
| 133 |
+
set Q(pri_queue) [lreplace $Q(pri_queue) $iBest $iBest]
|
| 134 |
+
|
| 135 |
+
return $ret
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
proc pq_new_entry {rScore iLevel cell} {
|
| 139 |
+
global Q
|
| 140 |
+
|
| 141 |
+
set rowid_name "iChild"
|
| 142 |
+
if {$iLevel==0} { set rowid_name "iRowid" }
|
| 143 |
+
|
| 144 |
+
set kv [list]
|
| 145 |
+
lappend kv aCoord [lrange $cell 1 end]
|
| 146 |
+
lappend kv iLevel $iLevel
|
| 147 |
+
|
| 148 |
+
if {$iLevel==0} {
|
| 149 |
+
lappend kv iRowid [lindex $cell 0]
|
| 150 |
+
} else {
|
| 151 |
+
lappend kv iChild [lindex $cell 0]
|
| 152 |
+
lappend kv iCurrent 0
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
lappend Q(pri_queue) [list $rScore $kv]
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
proc pq_test_callback {L res} {
|
| 159 |
+
#pq_debug "pq_test_callback $L -> $res"
|
| 160 |
+
global Q
|
| 161 |
+
|
| 162 |
+
array set G $L ;# "Got" - as in stuff passed to xQuery
|
| 163 |
+
|
| 164 |
+
# EVIDENCE-OF: R-65127-42665 If the extracted priority queue entry is a
|
| 165 |
+
# node (a subtree), then the next child of that node is passed to the
|
| 166 |
+
# xQueryFunc callback.
|
| 167 |
+
#
|
| 168 |
+
# If it had been a leaf, the row should have been returned, instead of
|
| 169 |
+
# xQueryCallback being called on a child - as is happening here.
|
| 170 |
+
foreach {rParentScore parent} [pq_extract] {}
|
| 171 |
+
array set P $parent ;# "Parent" - as in parent of expected cell
|
| 172 |
+
if {$P(iLevel)==0} { error "query callback mismatch (1)" }
|
| 173 |
+
set child_node [rnode_cells [rt_node_get $P(iChild)]]
|
| 174 |
+
set expected_cell [lindex $child_node $P(iCurrent)]
|
| 175 |
+
set expected_coords [lrange $expected_cell 1 end]
|
| 176 |
+
if {[llength $expected_coords] != [llength $G(aCoord)]} {
|
| 177 |
+
puts [array get P]
|
| 178 |
+
puts "E: $expected_coords G: $G(aCoord)"
|
| 179 |
+
error "coordinate mismatch in query callback (1)"
|
| 180 |
+
}
|
| 181 |
+
foreach a [lrange $expected_cell 1 end] b $G(aCoord) {
|
| 182 |
+
if {$a!=$b} { error "coordinate mismatch in query callback (2)" }
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
# Check level is as expected
|
| 186 |
+
#
|
| 187 |
+
if {$G(iLevel) != $P(iLevel)-1} {
|
| 188 |
+
error "iLevel mismatch in query callback (1)"
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
# Unless the callback returned NOT_WITHIN, add the entry to the priority
|
| 192 |
+
# queue.
|
| 193 |
+
#
|
| 194 |
+
# EVIDENCE-OF: R-28754-35153 Those subelements for which the xQueryFunc
|
| 195 |
+
# callback sets eWithin to PARTLY_WITHIN or FULLY_WITHIN are added to
|
| 196 |
+
# the priority queue using the score supplied by the callback.
|
| 197 |
+
#
|
| 198 |
+
# EVIDENCE-OF: R-08681-45277 Subelements that return NOT_WITHIN are
|
| 199 |
+
# discarded.
|
| 200 |
+
set r [lindex $res 0]
|
| 201 |
+
set rScore [lindex $res 1]
|
| 202 |
+
if {$r!="fully" && $r!="partly" && $r!="not"} {
|
| 203 |
+
error "unknown result: $r - expected \"fully\", \"partly\" or \"not\""
|
| 204 |
+
}
|
| 205 |
+
if {$r!="not"} {
|
| 206 |
+
pq_new_entry $rScore [expr $P(iLevel)-1] $expected_cell
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
# EVIDENCE-OF: R-07194-63805 If the node has more children then it is
|
| 210 |
+
# returned to the priority queue. Otherwise it is discarded.
|
| 211 |
+
incr P(iCurrent)
|
| 212 |
+
if {$P(iCurrent)<[llength $child_node]} {
|
| 213 |
+
lappend Q(pri_queue) [list $rParentScore [array get P]]
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
proc pq_test_result {id x1 x2 y1 y2} {
|
| 218 |
+
#pq_debug "pq_test_result $id $x1 $x2 $y1 $y2"
|
| 219 |
+
foreach {rScore next} [pq_extract] {}
|
| 220 |
+
|
| 221 |
+
# The extracted entry must be a leaf (otherwise, xQueryCallback would
|
| 222 |
+
# have been called on the extracted entries children instead of just
|
| 223 |
+
# returning the data).
|
| 224 |
+
#
|
| 225 |
+
# EVIDENCE-OF: R-13214-54017 If that entry is a leaf (meaning that it is
|
| 226 |
+
# an actual R*Tree entry and not a subtree) then that entry is returned
|
| 227 |
+
# as one row of the query result.
|
| 228 |
+
array set N $next
|
| 229 |
+
if {$N(iLevel)!=0} { error "result row mismatch (1)" }
|
| 230 |
+
|
| 231 |
+
if {$x1!=[lindex $N(aCoord) 0] || $x2!=[lindex $N(aCoord) 1]
|
| 232 |
+
|| $y1!=[lindex $N(aCoord) 2] || $y2!=[lindex $N(aCoord) 3]
|
| 233 |
+
} {
|
| 234 |
+
if {$N(iLevel)!=0} { error "result row mismatch (2)" }
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
if {$id!=$N(iRowid)} { error "result row mismatch (3)" }
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
proc pq_done {} {
|
| 241 |
+
global Q
|
| 242 |
+
# EVIDENCE-OF: R-57438-45968 The query runs until the priority queue is
|
| 243 |
+
# empty.
|
| 244 |
+
if {[llength $Q(pri_queue)]>0} {
|
| 245 |
+
error "priority queue is not empty!"
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
proc pq_debug {caption} {
|
| 250 |
+
global Q
|
| 251 |
+
|
| 252 |
+
puts "**** $caption ****"
|
| 253 |
+
set i 0
|
| 254 |
+
foreach q [lsort -real -index 0 $Q(pri_queue)] {
|
| 255 |
+
puts "PQ $i: $q"
|
| 256 |
+
incr i
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
#--------------------------------------------------------------
|
| 261 |
+
|
| 262 |
+
proc box_query {a} {
|
| 263 |
+
set res [list fully [expr rand()]]
|
| 264 |
+
pq_test_callback $a $res
|
| 265 |
+
return $res
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
register_box_query db box_query
|
| 269 |
+
|
| 270 |
+
do_execsql_test 1.0 {
|
| 271 |
+
CREATE VIRTUAL TABLE rt USING rtree_i32(id, x1,x2, y1,y2);
|
| 272 |
+
WITH s(i) AS (
|
| 273 |
+
SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<64
|
| 274 |
+
)
|
| 275 |
+
INSERT INTO rt SELECT NULL, a.i, a.i+1, b.i, b.i+1 FROM s a, s b;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
proc box_query {a} {
|
| 279 |
+
set res [list fully [expr rand()]]
|
| 280 |
+
pq_test_callback $a $res
|
| 281 |
+
return $res
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
pq_init
|
| 285 |
+
db eval { SELECT id, x1,x2, y1,y2 FROM rt WHERE id MATCH qbox() } {
|
| 286 |
+
pq_test_result $id $x1 $x2 $y1 $y2
|
| 287 |
+
}
|
| 288 |
+
pq_done
|
| 289 |
+
|
| 290 |
+
finish_test
|
| 291 |
+
|
| 292 |
+
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/rtreefuzz001.test
ADDED
|
@@ -0,0 +1,1211 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2012-12-21
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# Test cases for corrupt database files.
|
| 13 |
+
|
| 14 |
+
if {![info exists testdir]} {
|
| 15 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 16 |
+
}
|
| 17 |
+
source $testdir/tester.tcl
|
| 18 |
+
|
| 19 |
+
ifcapable !deserialize||!rtree {
|
| 20 |
+
finish_test
|
| 21 |
+
return
|
| 22 |
+
}
|
| 23 |
+
database_may_be_corrupt
|
| 24 |
+
|
| 25 |
+
do_test rtreefuzz001-100 {
|
| 26 |
+
sqlite3 db {}
|
| 27 |
+
db deserialize [decode_hexdb {
|
| 28 |
+
| size 24576 pagesize 4096 filename c1b.db
|
| 29 |
+
| page 1 offset 0
|
| 30 |
+
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
| 31 |
+
| 16: 10 00 01 01 00 40 20 20 00 00 00 03 00 00 00 06 .....@ ........
|
| 32 |
+
| 32: 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 04 ................
|
| 33 |
+
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
|
| 34 |
+
| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................
|
| 35 |
+
| 96: 00 2e 30 38 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f ..08...........O
|
| 36 |
+
| 112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
| 37 |
+
| 3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17 ............^...
|
| 38 |
+
| 3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72 .....tablet1_par
|
| 39 |
+
| 3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45 entt1_parent.CRE
|
| 40 |
+
| 3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61 ATE TABLE .t1_pa
|
| 41 |
+
| 3792: 72 66 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 rfnt.(nodeno INT
|
| 42 |
+
| 3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
|
| 43 |
+
| 3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17 ,parentnode)Q...
|
| 44 |
+
| 3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65 ....tablet1_node
|
| 45 |
+
| 3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54 t1_node.CREATE T
|
| 46 |
+
| 3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e ABLE .t1_node.(n
|
| 47 |
+
| 3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52 odeno INTEGER PR
|
| 48 |
+
| 3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c IMARY KEY,data).
|
| 49 |
+
| 3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f ........tablet1_
|
| 50 |
+
| 3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52 rowidt1_rowid.CR
|
| 51 |
+
| 3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72 EATE TABLE .t1_r
|
| 52 |
+
| 3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE
|
| 53 |
+
| 3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY,
|
| 54 |
+
| 4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07 nodeno,a0,a1)Q..
|
| 55 |
+
| 4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43 ......tablet1t1C
|
| 56 |
+
| 4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA
|
| 57 |
+
| 4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 BLE t1 USING rtr
|
| 58 |
+
| 4064: 65 65 28 69 64 2c 78 30 2c 78 31 2c 79 30 2c 79 ee(id,x0,x1,y0,y
|
| 59 |
+
| 4080: 31 2c 2b 6c 61 62 65 6c 2c 2b 6f 74 68 65 72 29 1,+label,+other)
|
| 60 |
+
| page 2 offset 4096
|
| 61 |
+
| 0: 0d 0c cd 00 74 08 75 01 0f e8 0c b3 0f d0 0f b7 ....t.u.........
|
| 62 |
+
| 16: 0f 9e 0f 91 0f 81 0f 70 0f 5e 0f 4f 0f 39 0f 29 .......p.^.O.9.)
|
| 63 |
+
| 32: 0f 18 0f 06 0e f7 0c 65 0e 58 0d c2 0d 2c 0c 25 .......e.X...,.%
|
| 64 |
+
| 48: 0b 85 0a e5 0a 45 09 a5 09 05 0c 83 0c 93 0c a3 .....E..........
|
| 65 |
+
| 64: 0f f0 0c 15 0b 75 0a d5 0a 35 09 95 08 f5 0e d8 .....u...5......
|
| 66 |
+
| 80: 0e 42 0d ac 0d 16 0c 05 0b 65 0a c5 0a 25 09 85 .B.......e...%..
|
| 67 |
+
| 96: 08 e5 0e c8 0e 32 0d 9c 0d 06 0b f5 0b 55 0a b5 .....2.......U..
|
| 68 |
+
| 112: 0a 15 09 75 08 d5 0e b8 0e 22 0d 8c 0c f6 0b e5 ...u............
|
| 69 |
+
| 128: 0b 45 0a a5 0a 05 09 65 08 c5 0e a8 0e 12 0d 7c .E.....e.......|
|
| 70 |
+
| 144: 0c e6 0b d5 0b 35 0a 95 09 f5 09 55 08 b5 0e 98 .....5.....U....
|
| 71 |
+
| 160: 0e 02 0d 6c 0c d6 0b c5 0b 25 0a 85 09 e5 09 45 ...l.....%.....E
|
| 72 |
+
| 176: 08 a5 0e 88 0d f2 0d 5c 0c 55 0b b5 0b 15 0a 75 .........U.....u
|
| 73 |
+
| 192: 09 d5 09 35 08 95 0e 78 0d e2 0d 4c 0c 45 0b a5 ...5...x...L.E..
|
| 74 |
+
| 208: 0b 05 0a 65 09 c5 09 25 08 85 0e 68 0d d2 0d 3c ...e...%...h...<
|
| 75 |
+
| 224: 0c 35 0b 95 0a f5 0a 55 09 b5 09 15 08 75 0c 75 .5.....U.....u.u
|
| 76 |
+
| 2160: 00 00 00 00 00 0d 8e 75 05 00 01 1b 00 04 62 6f .......u......bo
|
| 77 |
+
| 2176: 78 2d 39 2c 39 0d 8e 11 05 00 01 1b 00 02 62 6f x-9,9.........bo
|
| 78 |
+
| 2192: 78 2d 39 2c 38 0d 8d 2d 05 00 01 1b 00 02 62 6f x-9,8..-......bo
|
| 79 |
+
| 2208: 78 2d 39 2c 37 0d 8c 49 05 00 01 1b 00 02 62 6f x-9,7..I......bo
|
| 80 |
+
| 2224: 78 2d 39 2c 36 0d 8b 65 05 00 01 1b 00 02 62 6f x-9,6..e......bo
|
| 81 |
+
| 2240: 78 2d 39 2c 35 0d 8b 01 05 00 01 1b 00 02 62 6f x-9,5.........bo
|
| 82 |
+
| 2256: 78 2d 39 2c 34 0d 8a 1d 05 00 01 1b 00 02 62 6f x-9,4.........bo
|
| 83 |
+
| 2272: 78 2d 39 2c 33 0d 89 39 05 00 01 1b 00 02 62 6f x-9,3..9......bo
|
| 84 |
+
| 2288: 78 2d 39 2c 32 0d 88 55 05 00 01 1b 00 02 62 6f x-9,2..U......bo
|
| 85 |
+
| 2304: 78 2d 39 2c 31 0d 87 71 05 00 01 1b 00 02 62 6f x-9,1..q......bo
|
| 86 |
+
| 2320: 78 2d 39 2c 30 0d 8e 74 05 00 01 1b 00 04 62 6f x-9,0..t......bo
|
| 87 |
+
| 2336: 78 2d 38 2c 39 0d 8e 10 05 00 01 1b 00 02 62 6f x-8,9.........bo
|
| 88 |
+
| 2352: 78 2d 38 2c 38 0d 8d 2c 05 00 01 1b 00 02 62 6f x-8,8..,......bo
|
| 89 |
+
| 2368: 78 2d 38 2c 37 0d 8c 48 05 00 01 1b 00 02 62 6f x-8,7..H......bo
|
| 90 |
+
| 2384: 78 2d 38 2c 36 0d 8b 64 05 00 01 1b 00 02 62 6f x-8,6..d......bo
|
| 91 |
+
| 2400: 78 2d 38 2c 35 0d 8b 00 05 00 01 1b 00 02 62 6f x-8,5.........bo
|
| 92 |
+
| 2416: 78 2d 38 2c 34 0d 8a 1c 05 00 01 1b 00 02 62 6f x-8,4.........bo
|
| 93 |
+
| 2432: 78 2d 38 2c 33 0d 89 38 05 00 01 1b 00 02 62 6f x-8,3..8......bo
|
| 94 |
+
| 2448: 78 2d 38 2c 32 0d 88 54 05 00 01 1b 00 02 62 6f x-8,2..T......bo
|
| 95 |
+
| 2464: 78 2d 38 2c 31 0d 87 70 05 00 01 1b 00 02 62 6f x-8,1..p......bo
|
| 96 |
+
| 2480: 78 2d 38 2c 30 0d 8e 73 05 00 01 1b 00 05 62 6f x-8,0..s......bo
|
| 97 |
+
| 2496: 78 2d 37 2c 39 0d 8e 0f 05 00 01 1b 00 05 62 6f x-7,9.........bo
|
| 98 |
+
| 2512: 78 2d 37 2c 38 0d 8d 2b 05 00 01 1b 00 05 62 6f x-7,8..+......bo
|
| 99 |
+
| 2528: 78 2d 37 2c 37 0d 8c 47 05 00 01 1b 00 05 62 6f x-7,7..G......bo
|
| 100 |
+
| 2544: 78 2d 37 2c 36 0d 8b 63 05 00 01 1b 00 05 62 6f x-7,6..c......bo
|
| 101 |
+
| 2560: 78 2d 37 2c 35 0d 8a 7f 05 00 01 1b 00 05 62 6f x-7,5.........bo
|
| 102 |
+
| 2576: 78 2d 37 2c 34 0d 8a 1b 05 00 01 1b 00 05 62 6f x-7,4.........bo
|
| 103 |
+
| 2592: 78 2d 37 2c 33 0d 89 37 05 00 01 1b 00 05 62 6f x-7,3..7......bo
|
| 104 |
+
| 2608: 78 2d 37 2c 32 0d 88 53 05 00 01 1b 00 05 62 6f x-7,2..S......bo
|
| 105 |
+
| 2624: 78 2d 37 2c 31 0d 87 6f 05 00 01 1b 00 05 62 6f x-7,1..o......bo
|
| 106 |
+
| 2640: 78 2d 37 2c 30 0d 8e 72 05 00 01 1b 00 04 62 6f x-7,0..r......bo
|
| 107 |
+
| 2656: 78 2d 36 2c 39 0d 8e 0e 05 00 01 1b 00 05 62 6f x-6,9.........bo
|
| 108 |
+
| 2672: 78 2d 36 2c 38 0d 8d 2a 05 00 01 1b 00 05 62 6f x-6,8..*......bo
|
| 109 |
+
| 2688: 78 2d 36 2c 37 0d 8c 46 05 00 01 1b 00 05 62 6f x-6,7..F......bo
|
| 110 |
+
| 2704: 78 2d 36 2c 36 0d 8b 62 05 00 01 1b 00 05 62 6f x-6,6..b......bo
|
| 111 |
+
| 2720: 78 2d 36 2c 35 0d 8a 7e 05 00 01 1b 00 05 62 6f x-6,5..~......bo
|
| 112 |
+
| 2736: 78 2d 36 2c 34 0d 8a 1a 05 00 01 1b 00 05 62 6f x-6,4.........bo
|
| 113 |
+
| 2752: 78 2d 36 2c 33 0d 89 36 05 00 01 1b 00 05 62 6f x-6,3..6......bo
|
| 114 |
+
| 2768: 78 2d 36 2c 32 0d 88 52 05 00 01 1b 00 05 62 6f x-6,2..R......bo
|
| 115 |
+
| 2784: 78 2d 36 2c 31 0d 87 6e 05 00 01 1b 00 05 62 6f x-6,1..n......bo
|
| 116 |
+
| 2800: 78 2d 36 2c 30 0d 8e 71 05 00 01 1b 00 04 62 6f x-6,0..q......bo
|
| 117 |
+
| 2816: 78 2d 35 2c 39 0d 8e 0d 05 00 01 1b 00 05 62 6f x-5,9.........bo
|
| 118 |
+
| 2832: 78 2d 35 2c 38 0d 8d 29 05 00 01 1b 00 05 62 6f x-5,8..)......bo
|
| 119 |
+
| 2848: 78 2d 35 2c 37 0d 8c 45 05 00 01 1b 00 05 62 6f x-5,7..E......bo
|
| 120 |
+
| 2864: 78 2d 35 2c 36 0d 8b 61 05 00 01 1b 00 05 62 6f x-5,6..a......bo
|
| 121 |
+
| 2880: 78 2d 35 2c 35 0d 8a 7d 05 00 01 1b 00 05 62 6f x-5,5.........bo
|
| 122 |
+
| 2896: 78 2d 35 2c 34 0d 8a 19 05 00 01 1b 00 05 62 6f x-5,4.........bo
|
| 123 |
+
| 2912: 78 2d 35 2c 33 0d 89 35 05 00 01 1b 00 05 62 6f x-5,3..5......bo
|
| 124 |
+
| 2928: 78 2d 35 2c 32 0d 88 51 05 00 01 1b 00 05 62 6f x-5,2..Q......bo
|
| 125 |
+
| 2944: 78 2d 35 2c 31 0d 87 6d 05 00 01 1b 00 05 62 6f x-5,1..m......bo
|
| 126 |
+
| 2960: 78 2d 35 2c 30 0d 8e 70 05 00 01 1b 00 04 62 6f x-5,0..p......bo
|
| 127 |
+
| 2976: 78 2d 34 2c 39 0d 8e 0c 05 00 01 1b 00 04 62 6f x-4,9.........bo
|
| 128 |
+
| 2992: 78 2d 34 2c 38 0d 8d 28 05 00 01 1b 00 04 62 6f x-4,8..(......bo
|
| 129 |
+
| 3008: 78 2d 34 2c 37 0d 8c 44 05 00 01 1b 00 04 62 6f x-4,7..D......bo
|
| 130 |
+
| 3024: 78 2d 34 2c 36 0d 8b 60 05 00 01 1b 00 02 62 6f x-4,6..`......bo
|
| 131 |
+
| 3040: 78 2d 34 2c 35 0d 8a 7c 05 00 01 1b 00 02 62 6f x-4,5..|......bo
|
| 132 |
+
| 3056: 78 2d 34 2c 34 0d 8a 18 05 00 01 1b 00 02 62 6f x-4,4.........bo
|
| 133 |
+
| 3072: 78 2d 34 2c 33 0d 89 34 05 00 01 1b 00 02 62 6f x-4,3..4......bo
|
| 134 |
+
| 3088: 78 2d 34 2c 32 0d 88 50 05 00 01 1b 00 02 62 6f x-4,2..P......bo
|
| 135 |
+
| 3104: 78 2d 34 2c 31 0d 87 6c 05 00 01 1b 00 02 62 6f x-4,1..l......bo
|
| 136 |
+
| 3120: 78 2d 34 2c 30 0d 8e 6f 05 00 01 1b 00 04 62 6f x-4,0..o......bo
|
| 137 |
+
| 3136: 78 2d 33 2c 39 0d 8e 0b 05 00 01 1b 00 04 62 6f x-3,9.........bo
|
| 138 |
+
| 3152: 78 2d 33 2c 38 0d 8d 27 05 00 01 1b 00 04 62 6f x-3,8..'......bo
|
| 139 |
+
| 3168: 78 2d 33 2c 37 0d 87 68 05 00 01 1b 00 03 62 6f x-3,7..h......bo
|
| 140 |
+
| 3184: 78 2d 30 2c 30 06 90 d9 80 80 81 84 4c 05 00 01 x-0,0.......L...
|
| 141 |
+
| 3200: 00 00 03 0d 88 4c 05 00 01 1b 00 02 62 6f 78 2d .....L......box-
|
| 142 |
+
| 3216: 30 2c 31 0d 88 4d 05 00 01 1b 00 02 62 6f 78 2d 0,1..M......box-
|
| 143 |
+
| 3232: 31 2c 31 0d 88 4e 05 00 01 1b 00 02 62 6f 78 2d 1,1..N......box-
|
| 144 |
+
| 3248: 32 2c 31 17 01 05 00 01 2f 00 02 6c 6f 77 65 72 2,1...../..lower
|
| 145 |
+
| 3264: 2d 6c 65 66 74 20 63 6f 72 6e 65 72 0d 0d 26 00 -left corner..&.
|
| 146 |
+
| 3280: 09 00 01 00 00 04 0d 8c 43 05 00 01 1b 00 04 62 ........C......b
|
| 147 |
+
| 3296: 6f 78 2d 33 2c 36 0d 8b 5f 05 00 01 1b 00 02 62 ox-3,6.._......b
|
| 148 |
+
| 3312: 6f 78 2d 33 2c 35 0d 8a 7b 05 00 01 1b 00 02 62 ox-3,5.........b
|
| 149 |
+
| 3328: 6f 78 2d 33 2c 34 0d 8a 17 05 00 01 1b 00 02 62 ox-3,4.........b
|
| 150 |
+
| 3344: 6f 78 2d 33 2c 33 0d 89 33 05 00 01 1b 00 02 62 ox-3,3..3......b
|
| 151 |
+
| 3360: 6f 78 2d 33 2c 32 0d bc 00 06 00 09 0d 87 6b 05 ox-3,2........k.
|
| 152 |
+
| 3376: 00 01 1b 00 03 62 6f 78 2d 33 2c 30 0d 8e 6e 05 .....box-3,0..n.
|
| 153 |
+
| 3392: 00 01 1b 00 04 62 6f 78 2d 32 2c 39 0d 8e 0a 05 .....box-2,9....
|
| 154 |
+
| 3408: 00 01 1b 00 04 62 6f 78 2d 32 2c 38 0d 8d 26 05 .....box-2,8..&.
|
| 155 |
+
| 3424: 00 01 1b 00 04 62 6f 78 2d 32 2c 37 0d 8c 42 05 .....box-2,7..B.
|
| 156 |
+
| 3440: 00 01 1b 00 04 62 6f 78 2d 32 2c 36 0d 8b 5e 05 .....box-2,6..^.
|
| 157 |
+
| 3456: 00 01 1b 00 02 62 6f 78 2d 32 2c 35 0d 8a 7a 05 .....box-2,5..z.
|
| 158 |
+
| 3472: 00 01 1b 00 02 62 6f 78 2d 32 2c 34 0d 8a 16 05 .....box-2,4....
|
| 159 |
+
| 3488: 00 01 1b 00 02 62 6f 78 2d 32 2c 33 0d 89 32 05 .....box-2,3..2.
|
| 160 |
+
| 3504: 00 01 1b 00 02 62 6f 78 2d 32 2c 32 0e 52 00 06 .....box-2,2.R..
|
| 161 |
+
| 3520: 00 09 0d 87 6a 05 00 01 1b 00 03 62 6f 78 2d 32 ....j......box-2
|
| 162 |
+
| 3536: 2c 30 0d 8e 6d 05 00 01 1b 00 04 62 6f 78 2d 31 ,0..m......box-1
|
| 163 |
+
| 3552: 2c 39 0d 8e 09 05 00 01 1b 00 04 62 6f 78 2d 31 ,9.........box-1
|
| 164 |
+
| 3568: 2c 38 0d 8d 25 05 00 01 1b 00 04 62 6f 78 2d 31 ,8..%......box-1
|
| 165 |
+
| 3584: 2c 37 0d 8c 41 05 00 01 1b 00 04 62 6f 78 2d 31 ,7..A......box-1
|
| 166 |
+
| 3600: 2c 36 0d 8b 5d 05 00 01 1b 00 02 62 6f 78 2d 31 ,6..]......box-1
|
| 167 |
+
| 3616: 2c 35 0d 8a 79 05 00 01 1b 00 02 62 6f 78 2d 31 ,5..y......box-1
|
| 168 |
+
| 3632: 2c 34 0d 8a 15 05 00 01 1b 00 02 62 6f 78 2d 31 ,4.........box-1
|
| 169 |
+
| 3648: 2c 33 0d 89 31 05 00 01 1b 00 02 62 6f 78 2d 31 ,3..1......box-1
|
| 170 |
+
| 3664: 2c 32 0e e8 00 06 00 09 0d 87 69 05 00 01 1b 00 ,2........i.....
|
| 171 |
+
| 3680: 03 62 6f 78 2d 31 2c 30 0d 8e 6c 05 00 01 1b 00 .box-1,0..l.....
|
| 172 |
+
| 3696: 04 62 6f 78 2d 30 2c 39 0d 8e 08 05 00 01 1b 00 .box-0,9........
|
| 173 |
+
| 3712: 04 62 6f 78 2d 30 2c 38 0d 8d 24 05 00 01 1b 00 .box-0,8..$.....
|
| 174 |
+
| 3728: 04 62 6f 78 2d 30 2c 37 0d 8c 40 05 00 01 1b 00 .box-0,7..@.....
|
| 175 |
+
| 3744: 04 62 6f 78 2d 30 2c 36 0d 8b 5c 05 00 01 1b 00 .box-0,6........
|
| 176 |
+
| 3760: 02 62 6f 78 2d 30 2c 35 0d 8a 78 05 00 01 1b 00 .box-0,5..x.....
|
| 177 |
+
| 3776: 02 62 6f 78 2d 30 2c 34 0d 8a 14 05 00 01 1b 00 .box-0,4........
|
| 178 |
+
| 3792: 02 62 6f 78 2d 30 2c 33 0d 89 30 05 00 01 1b 00 .box-0,3..0.....
|
| 179 |
+
| 3808: 02 62 6f 78 2d 30 2c 32 00 00 00 0f 00 09 1b 00 .box-0,2........
|
| 180 |
+
| 3824: 62 6f 78 2d 30 2c 30 0d 0e 05 00 09 1d 00 74 6f box-0,0.......to
|
| 181 |
+
| 3840: 70 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74 p half.....#.bot
|
| 182 |
+
| 3856: 74 6f 6d 20 68 61 6c 66 0f 0c 02 05 09 01 00 72 tom half.......r
|
| 183 |
+
| 3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00 ight half.......
|
| 184 |
+
| 3888: 6c 65 66 74 20 68 61 6c 66 14 0a 05 00 09 2b 00 left half.....+.
|
| 185 |
+
| 3904: 74 68 65 20 77 68 6f 6c 65 20 74 68 69 6e 67 0d the whole thing.
|
| 186 |
+
| 3920: 09 05 00 09 1d 00 74 6f 70 20 65 64 67 65 10 08 ......top edge..
|
| 187 |
+
| 3936: 05 00 09 23 00 62 6f 74 74 6f 6d 20 65 64 67 65 ...#.bottom edge
|
| 188 |
+
| 3952: 0f 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67 .....!.right edg
|
| 189 |
+
| 3968: 65 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67 e.......left edg
|
| 190 |
+
| 3984: 65 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04 e.......center..
|
| 191 |
+
| 4000: 05 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74 ...1.upper-right
|
| 192 |
+
| 4016: 20 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f corner.....1.lo
|
| 193 |
+
| 4032: 77 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72 wer-right corner
|
| 194 |
+
| 4048: 16 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66 ...../.upper-lef
|
| 195 |
+
| 4064: 74 20 63 6f 72 6e 65 72 06 00 05 00 01 00 00 03 t corner........
|
| 196 |
+
| 4080: 0d 88 4f 05 00 01 1b 00 02 62 6f 78 2d 33 2c 31 ..O......box-3,1
|
| 197 |
+
| page 3 offset 8192
|
| 198 |
+
| 0: 05 00 00 00 01 0f fb 00 00 00 00 06 0f fb 00 00 ................
|
| 199 |
+
| 384: 00 00 00 00 00 00 00 89 50 03 04 00 93 24 00 00 ........P....$..
|
| 200 |
+
| 400: 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
| 201 |
+
| 688: 00 00 00 00 42 c8 00 00 42 4c 00 00 42 00 00 00 ....B...BL..B...
|
| 202 |
+
| 720: 03 eb 40 40 00 00 40 80 00 00 00 00 00 00 3f 80 ..@@..@.......?.
|
| 203 |
+
| 736: 00 00 00 00 00 00 00 00 03 ea 40 00 00 00 40 40 ..........@...@@
|
| 204 |
+
| 752: 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 00 ......?.........
|
| 205 |
+
| 768: 03 e9 3f 80 00 00 40 00 00 00 00 00 00 00 3f 80 ..?...@.......?.
|
| 206 |
+
| 784: 00 00 00 00 00 00 00 00 03 e8 00 00 00 00 3f 80 ..............?.
|
| 207 |
+
| 800: 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 00 ......?.........
|
| 208 |
+
| 1616: 00 00 00 00 00 00 00 00 00 00 89 50 02 04 00 93 ...........P....
|
| 209 |
+
| 1632: 24 00 00 00 33 00 00 00 00 00 00 00 01 00 00 00 $...3...........
|
| 210 |
+
| 1648: 00 41 20 00 00 00 00 00 00 41 0e 00 00 00 00 00 .A ......A......
|
| 211 |
+
| 1664: 00 00 00 04 4f 40 40 00 00 40 80 00 00 3f 80 00 ....O@@..@...?..
|
| 212 |
+
| 1680: 00 40 00 00 00 00 00 00 00 00 00 04 4e 40 00 00 [email protected]@..
|
| 213 |
+
| 1696: 00 40 40 00 00 3f 80 00 00 40 00 00 00 00 00 00 .@@..?...@......
|
| 214 |
+
| 1712: 00 00 00 04 4d 3f 80 00 00 40 00 00 00 3f 80 00 ....M?...@...?..
|
| 215 |
+
| 1728: 00 40 00 00 00 00 00 00 00 00 00 04 4c 00 00 00 [email protected]...
|
| 216 |
+
| 1744: 00 3f 80 00 00 3f 80 00 00 40 00 00 00 00 00 00 .?...?...@......
|
| 217 |
+
| 1760: 00 00 00 04 b3 40 40 00 00 40 80 00 00 40 00 00 .....@@..@...@..
|
| 218 |
+
| 1776: 00 40 40 00 00 00 00 00 00 00 00 04 b2 40 00 00 .@@..........@..
|
| 219 |
+
| 1792: 00 40 40 00 00 40 00 00 00 40 40 00 00 00 00 00 .@@..@...@@.....
|
| 220 |
+
| 1808: 00 00 00 04 b1 3f 80 00 00 40 00 00 00 40 00 00 .....?...@...@..
|
| 221 |
+
| 1824: 00 40 40 00 00 00 00 00 00 00 00 04 b0 00 00 00 .@@.............
|
| 222 |
+
| 1840: 00 3f 80 00 00 40 00 00 00 40 40 00 00 00 00 00 .?...@...@@.....
|
| 223 |
+
| 1856: 00 00 00 05 17 40 40 00 00 40 80 00 00 40 40 00 .....@@..@...@@.
|
| 224 |
+
| 1872: 00 40 80 00 00 00 00 00 00 00 00 05 16 40 00 00 .@...........@..
|
| 225 |
+
| 1888: 00 40 40 00 00 40 40 00 00 40 80 00 00 00 00 00 .@@..@@..@......
|
| 226 |
+
| 1904: 00 00 00 05 15 3f 80 00 00 40 00 00 00 40 40 00 .....?...@...@@.
|
| 227 |
+
| 1920: 00 40 80 00 00 00 00 00 00 00 00 05 14 00 00 00 .@..............
|
| 228 |
+
| 1936: 00 3f 80 00 00 40 40 00 00 40 80 00 00 00 00 00 .?...@@..@......
|
| 229 |
+
| 1952: 00 00 00 05 7b 40 40 00 00 40 80 00 00 40 80 00 .....@@..@...@..
|
| 230 |
+
| 1968: 00 40 a0 00 00 00 00 00 00 00 00 05 7a 40 00 00 [email protected]@..
|
| 231 |
+
| 1984: 00 40 40 00 00 40 80 00 00 40 a0 00 00 00 00 00 .@@..@...@......
|
| 232 |
+
| 2000: 00 00 00 05 79 3f 80 00 00 40 00 00 00 40 80 00 ....y?...@...@..
|
| 233 |
+
| 2016: 00 40 a0 00 00 00 00 00 00 00 00 05 78 00 00 00 [email protected]...
|
| 234 |
+
| 2032: 00 3f 80 00 00 40 80 00 00 40 a0 00 00 00 00 00 .?...@...@......
|
| 235 |
+
| 2048: 00 00 00 05 df 40 40 00 00 40 80 00 00 40 a0 00 .....@@..@...@..
|
| 236 |
+
| 2064: 00 40 c0 00 00 00 00 00 00 00 00 05 de 40 00 00 .@...........@..
|
| 237 |
+
| 2080: 00 40 40 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .@@..@...@......
|
| 238 |
+
| 2096: 00 00 00 05 dd 3f 80 00 00 40 00 00 00 40 a0 00 .....?...@...@..
|
| 239 |
+
| 2112: 00 40 c0 00 00 00 00 00 00 00 00 05 dc 00 00 00 .@..............
|
| 240 |
+
| 2128: 00 3f 80 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .?...@...@......
|
| 241 |
+
| 2144: 00 00 00 06 43 40 40 00 00 40 80 00 00 40 c0 00 ....C@@..@...@..
|
| 242 |
+
| 2160: 00 40 e0 00 00 00 00 00 00 00 00 06 42 40 00 00 [email protected]@..
|
| 243 |
+
| 2176: 00 40 40 00 00 40 c0 00 00 40 e0 00 00 00 00 00 .@@..@...@......
|
| 244 |
+
| 2192: 00 00 00 06 41 3f 80 00 00 40 00 00 00 40 c0 00 ....A?...@...@..
|
| 245 |
+
| 2208: 00 40 e0 00 00 00 00 00 00 00 00 06 40 00 00 00 .@..........@...
|
| 246 |
+
| 2224: 00 3f 80 00 00 40 c0 00 00 40 e0 00 00 00 00 00 .?...@...@......
|
| 247 |
+
| 2240: 00 00 00 06 a7 40 40 00 00 40 80 00 00 40 e0 00 .....@@..@...@..
|
| 248 |
+
| 2256: 00 41 00 00 00 00 00 00 00 00 00 06 a6 40 00 00 .A...........@..
|
| 249 |
+
| 2272: 00 40 40 00 00 40 e0 00 00 41 00 00 00 00 00 00 .@@[email protected]......
|
| 250 |
+
| 2288: 00 00 00 06 a5 3f 80 00 00 40 00 00 00 40 e0 00 .....?...@...@..
|
| 251 |
+
| 2304: 00 41 00 00 00 00 00 00 00 00 00 06 a4 00 00 00 .A..............
|
| 252 |
+
| 2320: 00 3f 80 00 00 40 e0 00 00 41 00 00 00 00 00 00 [email protected]......
|
| 253 |
+
| 2336: 00 00 00 07 0a 40 00 00 00 40 40 00 00 41 00 00 .....@...@@..A..
|
| 254 |
+
| 2352: 00 41 10 00 00 00 00 00 00 00 00 07 09 3f 80 00 .A...........?..
|
| 255 |
+
| 2368: 00 40 00 00 00 41 00 00 00 41 10 00 00 00 00 00 [email protected]......
|
| 256 |
+
| 2384: 00 00 00 07 08 00 00 00 00 3f 80 00 00 41 00 00 .........?...A..
|
| 257 |
+
| 2400: 00 41 10 00 00 00 00 00 00 00 00 07 6e 40 00 00 .A..........n@..
|
| 258 |
+
| 2416: 00 40 40 00 00 41 10 00 00 41 20 00 00 00 00 00 .@@..A...A .....
|
| 259 |
+
| 2432: 00 00 00 07 6d 3f 80 00 00 40 00 00 00 41 10 00 [email protected]..
|
| 260 |
+
| 2448: 00 41 20 00 00 00 00 00 00 00 00 07 6c 00 00 00 .A .........l...
|
| 261 |
+
| 2464: 00 3f 80 00 00 41 10 00 00 41 20 00 00 00 00 00 .?...A...A .....
|
| 262 |
+
| 2480: 00 00 00 07 0b 40 40 00 00 40 80 00 00 41 00 00 .....@@[email protected]..
|
| 263 |
+
| 2496: 00 41 10 00 00 00 00 00 00 00 00 07 6f 40 40 00 .A..........o@@.
|
| 264 |
+
| 2512: 00 40 80 00 00 41 10 00 00 41 20 00 00 00 00 00 [email protected] .....
|
| 265 |
+
| 2528: 00 00 00 03 ec 40 80 00 00 40 a0 00 00 00 00 00 .....@...@......
|
| 266 |
+
| 2544: 00 3f 80 00 00 00 00 00 00 00 00 04 50 40 80 00 .?..........P@..
|
| 267 |
+
| 2560: 00 40 a0 00 00 3f 80 00 00 40 00 00 00 00 00 00 .@...?...@......
|
| 268 |
+
| 2576: 00 00 00 04 b4 40 80 00 00 40 a0 00 00 40 00 00 .....@...@...@..
|
| 269 |
+
| 2592: 00 40 40 00 00 00 00 00 00 00 00 05 18 40 80 00 .@@..........@..
|
| 270 |
+
| 2608: 00 40 a0 00 00 40 40 00 00 40 80 00 00 00 00 00 .@...@@..@......
|
| 271 |
+
| 2624: 00 00 00 05 7c 40 80 00 00 40 a0 00 00 40 80 00 ....|@...@...@..
|
| 272 |
+
| 2640: 00 40 a0 00 00 00 00 00 00 00 00 05 e0 40 80 00 .@...........@..
|
| 273 |
+
| 2656: 00 40 a0 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .@...@...@......
|
| 274 |
+
| 2672: 00 00 00 06 44 40 80 00 00 40 a0 00 00 40 c0 00 ....D@...@...@..
|
| 275 |
+
| 2688: 00 40 e0 00 00 00 00 00 00 00 00 06 a8 40 80 00 .@...........@..
|
| 276 |
+
| 2704: 00 40 a0 00 00 40 e0 00 00 41 00 00 00 00 00 00 .@[email protected]......
|
| 277 |
+
| 2720: 00 00 00 07 0c 40 80 00 00 40 a0 00 00 41 00 00 .....@[email protected]..
|
| 278 |
+
| 2736: 00 41 10 00 00 00 00 00 00 00 00 07 70 40 80 00 .A..........p@..
|
| 279 |
+
| 2752: 00 40 a0 00 00 41 10 00 00 41 20 00 00 00 00 00 [email protected] .....
|
| 280 |
+
| 2768: 00 00 00 03 ed 40 a0 00 00 40 c0 00 00 00 00 00 .....@...@......
|
| 281 |
+
| 2784: 00 3f 80 00 00 00 00 00 00 00 00 04 51 40 a0 00 .?..........Q@..
|
| 282 |
+
| 2800: 00 40 c0 00 00 3f 80 00 00 40 00 00 00 00 00 00 .@...?...@......
|
| 283 |
+
| 2816: 00 00 00 04 b5 40 a0 00 00 40 c0 00 00 40 00 00 .....@...@...@..
|
| 284 |
+
| 2832: 00 40 40 00 00 00 00 00 00 00 00 05 19 40 a0 00 .@@..........@..
|
| 285 |
+
| 2848: 00 40 c0 00 00 40 40 00 00 40 80 00 00 89 50 01 .@...@@[email protected].
|
| 286 |
+
| 2864: 04 00 93 24 00 01 00 02 00 00 00 00 00 00 00 03 ...$............
|
| 287 |
+
| 2880: 00 00 00 00 40 80 00 00 00 00 00 00 3f 80 00 00 ....@.......?...
|
| 288 |
+
| 2896: 00 00 00 00 00 00 00 02 00 00 00 00 41 20 00 00 ............A ..
|
| 289 |
+
| 2912: 00 00 00 00 41 20 00 00 00 00 00 00 00 00 00 00 ....A ..........
|
| 290 |
+
| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 03 ................
|
| 291 |
+
| page 4 offset 12288
|
| 292 |
+
| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................
|
| 293 |
+
| page 5 offset 16384
|
| 294 |
+
| 0: 0d 00 00 00 03 01 87 00 0b 2d 06 5a 01 87 00 00 .........-.Z....
|
| 295 |
+
| 384: 00 00 00 00 00 00 00 89 50 03 04 00 93 24 00 00 ........P....$..
|
| 296 |
+
| 400: 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
| 297 |
+
| 688: 00 00 00 00 42 c8 00 00 42 4c 00 00 42 00 00 00 ....B...BL..B...
|
| 298 |
+
| 720: 03 eb 40 40 00 00 40 80 00 00 00 00 00 00 3f 80 ..@@..@.......?.
|
| 299 |
+
| 736: 00 00 00 00 00 00 00 00 03 ea 40 00 00 00 40 40 ..........@...@@
|
| 300 |
+
| 752: 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 00 ......?.........
|
| 301 |
+
| 768: 03 e9 3f 80 00 00 40 00 00 00 00 00 00 00 3f 80 ..?...@.......?.
|
| 302 |
+
| 784: 00 00 00 00 00 00 00 00 03 e8 00 00 00 00 3f 80 ..............?.
|
| 303 |
+
| 800: 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 00 ......?.........
|
| 304 |
+
| 1616: 00 00 00 00 00 00 00 00 00 00 89 50 02 04 00 93 ...........P....
|
| 305 |
+
| 1632: 24 00 00 00 2d 00 00 00 00 00 00 04 4c 00 00 00 $...-.......L...
|
| 306 |
+
| 1648: 00 3f 80 00 00 3f 80 00 00 40 00 00 00 00 00 00 .?...?...@......
|
| 307 |
+
| 1664: 00 00 00 04 b0 00 00 00 00 3f 80 00 00 40 00 00 .........?...@..
|
| 308 |
+
| 1680: 00 40 40 00 00 00 00 00 00 00 00 05 14 00 00 00 .@@.............
|
| 309 |
+
| 1696: 00 3f 80 00 00 40 40 00 00 40 80 00 00 00 00 00 .?...@@..@......
|
| 310 |
+
| 1712: 00 00 00 05 78 00 00 00 00 3f 80 00 00 40 80 00 ....x....?...@..
|
| 311 |
+
| 1728: 00 40 a0 00 00 00 00 00 00 00 00 05 dc 00 00 00 .@..............
|
| 312 |
+
| 1744: 00 3f 80 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .?...@...@......
|
| 313 |
+
| 1760: 00 00 00 00 01 00 00 00 00 41 20 00 00 00 00 00 .........A .....
|
| 314 |
+
| 1776: 00 41 0e 00 00 00 00 00 00 00 00 04 4d 3f 80 00 .A..........M?..
|
| 315 |
+
| 1792: 00 40 00 00 00 3f 80 00 00 40 00 00 00 00 00 00 .@...?...@......
|
| 316 |
+
| 1808: 00 00 00 04 b1 3f 80 00 00 40 00 00 00 40 00 00 .....?...@...@..
|
| 317 |
+
| 1824: 00 40 40 00 00 00 00 00 00 00 00 05 15 3f 80 00 .@@..........?..
|
| 318 |
+
| 1840: 00 40 00 00 00 40 40 00 00 40 80 00 00 00 00 00 .@...@@..@......
|
| 319 |
+
| 1856: 00 00 00 05 79 3f 80 00 00 40 00 00 00 40 80 00 ....y?...@...@..
|
| 320 |
+
| 1872: 00 40 a0 00 00 00 00 00 00 00 00 05 dd 3f 80 00 .@...........?..
|
| 321 |
+
| 1888: 00 40 00 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .@...@...@......
|
| 322 |
+
| 1904: 00 00 00 04 4e 40 00 00 00 40 40 00 00 3f 80 00 ....N@...@@..?..
|
| 323 |
+
| 1920: 00 40 00 00 00 00 00 00 00 00 00 04 b2 40 00 00 .@...........@..
|
| 324 |
+
| 1936: 00 40 40 00 00 40 00 00 00 40 40 00 00 00 00 00 .@@..@...@@.....
|
| 325 |
+
| 1952: 00 00 00 05 16 40 00 00 00 40 40 00 00 40 40 00 .....@...@@..@@.
|
| 326 |
+
| 1968: 00 40 80 00 00 00 00 00 00 00 00 05 7a 40 00 00 [email protected]@..
|
| 327 |
+
| 1984: 00 40 40 00 00 40 80 00 00 40 a0 00 00 00 00 00 .@@..@...@......
|
| 328 |
+
| 2000: 00 00 00 05 de 40 00 00 00 40 40 00 00 40 a0 00 .....@...@@..@..
|
| 329 |
+
| 2016: 00 40 c0 00 00 00 00 00 00 00 00 04 4f 40 40 00 [email protected]@@.
|
| 330 |
+
| 2032: 00 40 80 00 00 3f 80 00 00 40 00 00 00 00 00 00 .@...?...@......
|
| 331 |
+
| 2048: 00 00 00 04 b3 40 40 00 00 40 80 00 00 40 00 00 .....@@..@...@..
|
| 332 |
+
| 2064: 00 40 40 00 00 00 00 00 00 00 00 05 17 40 40 00 .@@..........@@.
|
| 333 |
+
| 2080: 00 40 80 00 00 40 40 00 00 40 80 00 00 00 00 00 .@...@@..@......
|
| 334 |
+
| 2096: 00 00 00 05 7b 40 40 00 00 40 80 00 00 40 80 00 .....@@..@...@..
|
| 335 |
+
| 2112: 00 40 a0 00 00 00 00 00 00 00 00 05 df 40 40 00 .@...........@@.
|
| 336 |
+
| 2128: 00 40 80 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .@...@...@......
|
| 337 |
+
| 2144: 00 00 00 03 ec 40 80 00 00 40 a0 00 00 00 00 00 .....@...@......
|
| 338 |
+
| 2160: 00 3f 80 00 00 00 00 00 00 00 00 04 50 40 80 00 .?..........P@..
|
| 339 |
+
| 2176: 00 40 a0 00 00 3f 80 00 00 40 00 00 00 00 00 00 .@...?...@......
|
| 340 |
+
| 2192: 00 00 00 04 b4 40 80 00 00 40 a0 00 00 40 00 00 .....@...@...@..
|
| 341 |
+
| 2208: 00 40 40 00 00 00 00 00 00 00 00 05 18 40 80 00 .@@..........@..
|
| 342 |
+
| 2224: 00 40 a0 00 00 40 40 00 00 40 80 00 00 00 00 00 .@...@@..@......
|
| 343 |
+
| 2240: 00 00 00 05 7c 40 80 00 00 40 a0 00 00 40 80 00 ....|@...@...@..
|
| 344 |
+
| 2256: 00 40 a0 00 00 00 00 00 00 00 00 05 e0 40 80 00 .@...........@..
|
| 345 |
+
| 2272: 00 40 a0 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .@...@...@......
|
| 346 |
+
| 2288: 00 00 00 03 f0 41 00 00 00 41 10 00 00 00 00 00 .....A...A......
|
| 347 |
+
| 2304: 00 3f 80 00 00 00 00 00 00 00 00 04 54 41 00 00 .?..........TA..
|
| 348 |
+
| 2320: 00 41 10 00 00 3f 80 00 00 40 00 00 00 00 00 00 .A...?...@......
|
| 349 |
+
| 2336: 00 00 00 04 b8 41 00 00 00 41 10 00 00 40 00 00 .....A...A...@..
|
| 350 |
+
| 2352: 00 40 40 00 00 00 00 00 00 00 00 05 1c 41 00 00 .@@..........A..
|
| 351 |
+
| 2368: 00 41 10 00 00 40 40 00 00 40 80 00 00 00 00 00 .A...@@..@......
|
| 352 |
+
| 2384: 00 00 00 05 80 41 00 00 00 41 10 00 00 40 80 00 .....A...A...@..
|
| 353 |
+
| 2400: 00 40 a0 00 00 00 00 00 00 00 00 05 e4 41 00 00 [email protected]..
|
| 354 |
+
| 2416: 00 41 10 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .A...@...@......
|
| 355 |
+
| 2432: 00 00 00 06 48 41 00 00 00 41 10 00 00 40 c0 00 ....HA...A...@..
|
| 356 |
+
| 2448: 00 40 e0 00 00 00 00 00 00 00 00 06 ac 41 00 00 [email protected]..
|
| 357 |
+
| 2464: 00 41 10 00 00 40 e0 00 00 41 00 00 00 00 00 00 [email protected]......
|
| 358 |
+
| 2480: 00 00 00 07 10 41 00 00 00 41 10 00 00 41 00 00 .....A...A...A..
|
| 359 |
+
| 2496: 00 41 10 00 00 00 00 00 00 00 00 03 f1 41 10 00 .A...........A..
|
| 360 |
+
| 2512: 00 41 20 00 00 00 00 00 00 3f 80 00 00 00 00 00 .A ......?......
|
| 361 |
+
| 2528: 00 00 00 04 55 41 10 00 00 41 20 00 00 3f 80 00 ....UA...A ..?..
|
| 362 |
+
| 2544: 00 40 00 00 00 00 00 00 00 00 00 04 b9 41 10 00 [email protected]..
|
| 363 |
+
| 2560: 00 41 20 00 00 40 00 00 00 40 40 00 00 00 00 00 .A ..@...@@.....
|
| 364 |
+
| 2576: 00 00 00 05 1d 41 10 00 00 41 20 00 00 40 40 00 .....A...A ..@@.
|
| 365 |
+
| 2592: 00 40 80 00 00 00 00 00 00 00 00 05 81 41 10 00 [email protected]..
|
| 366 |
+
| 2608: 00 41 20 00 00 40 80 00 00 40 a0 00 00 00 00 00 .A ..@...@......
|
| 367 |
+
| 2624: 00 00 00 05 e5 41 10 00 00 41 20 00 00 40 a0 00 .....A...A ..@..
|
| 368 |
+
| 2640: 00 40 c0 00 00 00 00 00 00 00 00 06 49 41 10 00 [email protected]..
|
| 369 |
+
| 2656: 00 41 20 00 00 40 c0 00 00 40 e0 00 00 00 00 00 .A ..@...@......
|
| 370 |
+
| 2672: 00 00 00 06 ad 41 10 00 00 41 20 00 00 40 e0 00 .....A...A ..@..
|
| 371 |
+
| 2688: 00 41 00 00 00 00 00 00 00 00 00 07 11 41 10 00 .A...........A..
|
| 372 |
+
| 2704: 00 41 20 00 00 41 00 00 00 41 10 00 00 00 00 00 .A ..A...A......
|
| 373 |
+
| 2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01 ..............P.
|
| 374 |
+
| 2864: 04 00 93 24 00 01 00 04 00 00 00 00 00 00 00 03 ...$............
|
| 375 |
+
| 2880: 00 00 00 00 40 80 00 00 00 00 00 00 3f 80 00 00 ....@.......?...
|
| 376 |
+
| 2896: 00 00 00 00 00 00 00 02 00 00 00 00 41 20 00 00 ............A ..
|
| 377 |
+
| 2912: 00 00 00 00 41 10 00 00 00 00 00 00 00 00 00 04 ....A...........
|
| 378 |
+
| 2928: 00 00 00 00 41 20 00 00 40 c0 00 00 41 20 00 00 ....A [email protected] ..
|
| 379 |
+
| 2944: 00 00 00 00 00 00 00 05 40 a0 00 00 41 00 00 00 [email protected]...
|
| 380 |
+
| 2960: 00 00 00 00 41 20 00 00 00 00 00 00 00 00 00 00 ....A ..........
|
| 381 |
+
| page 6 offset 20480
|
| 382 |
+
| 0: 0d 00 00 00 02 06 5a 00 0b 2d 06 5a 00 00 00 00 ......Z..-.Z....
|
| 383 |
+
| 1616: 00 00 00 00 00 00 00 00 00 00 89 50 05 04 00 93 ...........P....
|
| 384 |
+
| 1632: 24 00 00 00 1c 00 00 00 00 00 00 03 ed 40 a0 00 $............@..
|
| 385 |
+
| 1648: 00 40 c0 00 00 00 00 00 00 3f 80 00 00 00 00 00 .@.......?......
|
| 386 |
+
| 1664: 00 00 00 04 51 40 a0 00 00 40 c0 00 00 3f 80 00 ....Q@...@...?..
|
| 387 |
+
| 1680: 00 40 00 00 00 00 00 00 00 00 00 04 b5 40 a0 00 .@...........@..
|
| 388 |
+
| 1696: 00 40 c0 00 00 40 00 00 00 40 40 00 00 00 00 00 .@...@...@@.....
|
| 389 |
+
| 1712: 00 00 00 05 19 40 a0 00 00 40 c0 00 00 40 40 00 .....@...@...@@.
|
| 390 |
+
| 1728: 00 40 80 00 00 00 00 00 00 00 00 05 7d 40 a0 00 .@...........@..
|
| 391 |
+
| 1744: 00 40 c0 00 00 40 80 00 00 40 a0 00 00 00 00 00 .@...@...@......
|
| 392 |
+
| 1760: 00 00 00 05 e1 40 a0 00 00 40 c0 00 00 40 a0 00 .....@...@...@..
|
| 393 |
+
| 1776: 00 40 c0 00 00 00 00 00 00 00 00 06 45 40 a0 00 [email protected]@..
|
| 394 |
+
| 1792: 00 40 c0 00 00 40 c0 00 00 40 e0 00 00 00 00 00 .@...@...@......
|
| 395 |
+
| 1808: 00 00 00 06 a9 40 a0 00 00 40 c0 00 00 40 e0 00 .....@...@...@..
|
| 396 |
+
| 1824: 00 41 00 00 00 00 00 00 00 00 00 07 0d 40 a0 00 .A...........@..
|
| 397 |
+
| 1840: 00 40 c0 00 00 41 00 00 00 41 10 00 00 00 00 00 [email protected]......
|
| 398 |
+
| 1856: 00 00 00 03 ee 40 c0 00 00 40 e0 00 00 00 00 00 .....@...@......
|
| 399 |
+
| 1872: 00 3f 80 00 00 00 00 00 00 00 00 04 52 40 c0 00 .?..........R@..
|
| 400 |
+
| 1888: 00 40 e0 00 00 3f 80 00 00 40 00 00 00 00 00 00 .@...?...@......
|
| 401 |
+
| 1904: 00 00 00 04 b6 40 c0 00 00 40 e0 00 00 40 00 00 .....@...@...@..
|
| 402 |
+
| 1920: 00 40 40 00 00 00 00 00 00 00 00 05 1a 40 c0 00 .@@..........@..
|
| 403 |
+
| 1936: 00 40 e0 00 00 40 40 00 00 40 80 00 00 00 00 00 .@...@@..@......
|
| 404 |
+
| 1952: 00 00 00 05 7e 40 c0 00 00 40 e0 00 00 40 80 00 ....~@...@...@..
|
| 405 |
+
| 1968: 00 40 a0 00 00 00 00 00 00 00 00 05 e2 40 c0 00 .@...........@..
|
| 406 |
+
| 1984: 00 40 e0 00 00 40 a0 00 00 40 c0 00 00 00 00 00 .@...@...@......
|
| 407 |
+
| 2000: 00 00 00 06 46 40 c0 00 00 40 e0 00 00 40 c0 00 ....F@...@...@..
|
| 408 |
+
| 2016: 00 40 e0 00 00 00 00 00 00 00 00 06 aa 40 c0 00 .@...........@..
|
| 409 |
+
| 2032: 00 40 e0 00 00 40 e0 00 00 41 00 00 00 00 00 00 .@[email protected]......
|
| 410 |
+
| 2048: 00 00 00 07 0e 40 c0 00 00 40 e0 00 00 41 00 00 .....@[email protected]..
|
| 411 |
+
| 2064: 00 41 10 00 00 00 00 00 00 00 00 03 ef 40 e0 00 .A...........@..
|
| 412 |
+
| 2080: 00 41 00 00 00 00 00 00 00 3f 80 00 00 00 00 00 .A.......?......
|
| 413 |
+
| 2096: 00 00 00 04 53 40 e0 00 00 41 00 00 00 3f 80 00 [email protected]...?..
|
| 414 |
+
| 2112: 00 40 00 00 00 00 00 00 00 00 00 04 b7 40 e0 00 .@...........@..
|
| 415 |
+
| 2128: 00 41 00 00 00 40 00 00 00 40 40 00 00 00 00 00 .A...@...@@.....
|
| 416 |
+
| 2144: 00 00 00 05 1b 40 e0 00 00 41 00 00 00 40 40 00 [email protected]...@@.
|
| 417 |
+
| 2160: 00 40 80 00 00 00 00 00 00 00 00 05 7f 40 e0 00 .@...........@..
|
| 418 |
+
| 2176: 00 41 00 00 00 40 80 00 00 40 a0 00 00 00 00 00 .A...@...@......
|
| 419 |
+
| 2192: 00 00 00 05 e3 40 e0 00 00 41 00 00 00 40 a0 00 [email protected]...@..
|
| 420 |
+
| 2208: 00 40 c0 00 00 00 00 00 00 00 00 06 47 40 e0 00 [email protected]@..
|
| 421 |
+
| 2224: 00 41 00 00 00 40 c0 00 00 40 e0 00 00 00 00 00 .A...@...@......
|
| 422 |
+
| 2240: 00 00 00 06 ab 40 e0 00 00 41 00 00 00 40 e0 00 [email protected]...@..
|
| 423 |
+
| 2256: 00 41 00 00 00 00 00 00 00 00 00 07 0f 40 e0 00 .A...........@..
|
| 424 |
+
| 2272: 00 41 00 00 00 41 00 00 00 41 10 00 00 00 00 00 .A...A...A......
|
| 425 |
+
| 2288: 00 00 00 07 73 40 e0 00 00 41 00 00 00 41 10 00 [email protected]..
|
| 426 |
+
| 2304: 00 41 20 00 00 00 00 00 00 00 00 00 00 00 00 00 .A .............
|
| 427 |
+
| 2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 04 ..............P.
|
| 428 |
+
| 2864: 04 00 93 24 00 00 00 18 00 00 00 00 00 00 06 43 ...$...........C
|
| 429 |
+
| 2880: 40 40 00 00 40 80 00 00 40 c0 00 00 40 e0 00 00 @@..@...@...@...
|
| 430 |
+
| 2896: 00 00 00 00 00 00 06 42 40 00 00 00 40 40 00 00 .......B@...@@..
|
| 431 |
+
| 2912: 40 c0 00 00 40 e0 00 00 00 00 00 00 00 00 06 41 @[email protected]
|
| 432 |
+
| 2928: 3f 80 00 00 40 00 00 00 40 c0 00 00 40 e0 00 00 ?...@...@...@...
|
| 433 |
+
| 2944: 00 00 00 00 00 00 06 40 00 00 00 00 3f 80 00 00 .......@....?...
|
| 434 |
+
| 2960: 40 c0 00 00 40 e0 00 00 00 00 00 00 00 00 06 44 @[email protected]
|
| 435 |
+
| 2976: 40 80 00 00 40 a0 00 00 40 c0 00 00 40 e0 00 00 @...@...@...@...
|
| 436 |
+
| 2992: 00 00 00 00 00 00 06 a7 40 40 00 00 40 80 00 00 ........@@..@...
|
| 437 |
+
| 3008: 40 e0 00 00 41 00 00 00 00 00 00 00 00 00 06 a6 @...A...........
|
| 438 |
+
| 3024: 40 00 00 00 40 40 00 00 40 e0 00 00 41 00 00 00 @...@@[email protected]...
|
| 439 |
+
| 3040: 00 00 00 00 00 00 06 a5 3f 80 00 00 40 00 00 00 ........?...@...
|
| 440 |
+
| 3056: 40 e0 00 00 41 00 00 00 00 00 00 00 00 00 06 a4 @...A...........
|
| 441 |
+
| 3072: 00 00 00 00 3f 80 00 00 40 e0 00 00 41 00 00 00 [email protected]...
|
| 442 |
+
| 3088: 00 00 00 00 00 00 06 a8 40 80 00 00 40 a0 00 00 ........@...@...
|
| 443 |
+
| 3104: 40 e0 00 00 41 00 00 00 00 00 00 00 00 00 07 0a @...A...........
|
| 444 |
+
| 3120: 40 00 00 00 40 40 00 00 41 00 00 00 41 10 00 00 @...@@..A...A...
|
| 445 |
+
| 3136: 00 00 00 00 00 00 07 09 3f 80 00 00 40 00 00 00 ........?...@...
|
| 446 |
+
| 3152: 41 00 00 00 41 10 00 00 00 00 00 00 00 00 07 08 A...A...........
|
| 447 |
+
| 3168: 00 00 00 00 3f 80 00 00 41 00 00 00 41 10 00 00 ....?...A...A...
|
| 448 |
+
| 3184: 00 00 00 00 00 00 07 0b 40 40 00 00 40 80 00 00 ........@@..@...
|
| 449 |
+
| 3200: 41 00 00 00 41 10 00 00 00 00 00 00 00 00 07 0c A...A...........
|
| 450 |
+
| 3216: 40 80 00 00 40 a0 00 00 41 00 00 00 41 10 00 00 @[email protected]...
|
| 451 |
+
| 3232: 00 00 00 00 00 00 07 6e 40 00 00 00 40 40 00 00 .......n@...@@..
|
| 452 |
+
| 3248: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 07 6d A...A .........m
|
| 453 |
+
| 3264: 3f 80 00 00 40 00 00 00 41 10 00 00 41 20 00 00 [email protected] ..
|
| 454 |
+
| 3280: 00 00 00 00 00 00 07 6c 00 00 00 00 3f 80 00 00 .......l....?...
|
| 455 |
+
| 3296: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 07 6f A...A .........o
|
| 456 |
+
| 3312: 40 40 00 00 40 80 00 00 41 10 00 00 41 20 00 00 @@[email protected] ..
|
| 457 |
+
| 3328: 00 00 00 00 00 00 07 70 40 80 00 00 40 a0 00 00 .......p@...@...
|
| 458 |
+
| 3344: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 07 71 A...A .........q
|
| 459 |
+
| 3360: 40 a0 00 00 40 c0 00 00 41 10 00 00 41 20 00 00 @[email protected] ..
|
| 460 |
+
| 3376: 00 00 00 00 00 00 07 72 40 c0 00 00 40 e0 00 00 .......r@...@...
|
| 461 |
+
| 3392: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 07 74 A...A .........t
|
| 462 |
+
| 3408: 41 00 00 00 41 10 00 00 41 10 00 00 41 20 00 00 A...A...A...A ..
|
| 463 |
+
| 3424: 00 00 00 00 00 00 07 75 41 10 00 00 41 20 00 00 .......uA...A ..
|
| 464 |
+
| 3440: 41 10 00 00 41 20 00 00 00 00 00 00 00 00 00 00 A...A ..........
|
| 465 |
+
| end c1b.db
|
| 466 |
+
}]
|
| 467 |
+
catchsql {
|
| 468 |
+
PRAGMA writable_schema = 1;
|
| 469 |
+
SELECT rtreecheck('t1');
|
| 470 |
+
}
|
| 471 |
+
} {1 {SQL logic error}}
|
| 472 |
+
|
| 473 |
+
do_test rtreefuzz001-200 {
|
| 474 |
+
sqlite3 db {}
|
| 475 |
+
db deserialize [decode_hexdb {
|
| 476 |
+
| size 16384 pagesize 4096 filename c3.db
|
| 477 |
+
| page 1 offset 0
|
| 478 |
+
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
| 479 |
+
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04 .....@ ........
|
| 480 |
+
| 32: 00 00 00 00 01 00 00 00 00 00 00 04 00 00 00 04 ................
|
| 481 |
+
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
|
| 482 |
+
| 96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f ...............O
|
| 483 |
+
| 112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
| 484 |
+
| 3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17 ............^...
|
| 485 |
+
| 3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72 .....tablet1_par
|
| 486 |
+
| 3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45 entt1_parent.CRE
|
| 487 |
+
| 3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61 ATE TABLE .t1_pa
|
| 488 |
+
| 3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 rent.(nodeno INT
|
| 489 |
+
| 3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
|
| 490 |
+
| 3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17 ,parentnode)Q...
|
| 491 |
+
| 3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65 ....tablet1_node
|
| 492 |
+
| 3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54 t1_node.CREATE T
|
| 493 |
+
| 3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e ABLE .t1_node.(n
|
| 494 |
+
| 3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52 odeno INTEGER PR
|
| 495 |
+
| 3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c IMARY KEY,data).
|
| 496 |
+
| 3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f ........tablet1_
|
| 497 |
+
| 3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52 rowidt1_rowid.CR
|
| 498 |
+
| 3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72 EATE TABLE .t1_r
|
| 499 |
+
| 3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE
|
| 500 |
+
| 3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY,
|
| 501 |
+
| 4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07 nodeno,a0,a1)Q..
|
| 502 |
+
| 4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43 ......tablet1t1C
|
| 503 |
+
| 4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA
|
| 504 |
+
| 4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 BLE t1 USING rtr
|
| 505 |
+
| 4064: 65 65 28 69 64 2c 78 30 2c 78 31 2c 79 30 2c 79 ee(id,x0,x1,y0,y
|
| 506 |
+
| 4080: 31 2c 2b 6c 61 62 65 6c 2c 2b 6f 74 68 65 72 29 1,+label,+other)
|
| 507 |
+
| page 2 offset 4096
|
| 508 |
+
| 0: 0d 00 00 00 0e 0e f7 00 0f e8 0f d0 0f b7 0f 9e ................
|
| 509 |
+
| 16: 0f 91 0f 81 0f 70 0f 5e 0f 4f 0f 39 0f 29 0f 18 .....p.^.O.9.)..
|
| 510 |
+
| 32: 0f 06 0e f7 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
| 511 |
+
| 3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f ..............to
|
| 512 |
+
| 3840: 70 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74 p half.....#.bot
|
| 513 |
+
| 3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72 tom half.....!.r
|
| 514 |
+
| 3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00 ight half.......
|
| 515 |
+
| 3888: 6c 65 66 74 20 68 61 6c 66 14 0a 05 00 09 2b 00 left half.....+.
|
| 516 |
+
| 3904: 74 68 65 20 77 68 6f 6c 65 20 74 68 69 6e 67 0d the whole thing.
|
| 517 |
+
| 3920: 09 05 00 09 1d 00 74 6f 70 20 65 64 67 65 10 08 ......top edge..
|
| 518 |
+
| 3936: 05 00 09 23 00 62 6f 74 74 6f 6d 20 65 64 67 65 ...#.bottom edge
|
| 519 |
+
| 3952: 0f 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67 .....!.right edg
|
| 520 |
+
| 3968: 65 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67 e.......left edg
|
| 521 |
+
| 3984: 65 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04 e.......center..
|
| 522 |
+
| 4000: 05 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74 ...1.upper-right
|
| 523 |
+
| 4016: 20 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f corner.....1.lo
|
| 524 |
+
| 4032: 77 65 72 2d 72 69 67 68 74 27 60 f6 32 6e 65 72 wer-right'`.2ner
|
| 525 |
+
| 4048: 16 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66 ...../.upper-lef
|
| 526 |
+
| 4064: 74 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 00 6c t corner...../.l
|
| 527 |
+
| 4080: 6f 77 65 72 2d 6c 65 66 74 20 63 6f 72 6e 65 72 ower-left corner
|
| 528 |
+
| page 3 offset 8192
|
| 529 |
+
| 0: 0d 00 00 00 02 0b 2d 00 0b 2d 00 00 00 00 00 00 ......-..-......
|
| 530 |
+
| 2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01 ..............P.
|
| 531 |
+
| 2864: 04 00 93 24 00 00 00 0e 00 00 00 00 00 00 00 01 ...$............
|
| 532 |
+
| 2880: 00 00 00 00 41 20 00 00 00 00 00 00 41 20 01 00 ....A ......A ..
|
| 533 |
+
| 2896: 00 00 00 00 00 00 00 02 00 00 00 00 41 00 00 04 ............A...
|
| 534 |
+
| 2912: 2b 40 00 0c 42 c8 00 00 00 00 00 00 00 00 00 03 [email protected]...........
|
| 535 |
+
| 2928: 42 b4 00 00 42 c8 00 00 00 00 00 00 41 20 00 00 B...B.......A ..
|
| 536 |
+
| 2944: 00 00 00 00 00 00 00 04 42 b4 00 00 42 c8 00 00 ........B...B...
|
| 537 |
+
| 2960: 42 b4 00 00 42 c8 00 00 00 00 00 00 00 00 00 05 B...B...........
|
| 538 |
+
| 2976: 42 20 00 00 42 70 00 00 42 20 00 00 42 70 00 00 B ..Bp..B ..Bp..
|
| 539 |
+
| 2992: 00 00 00 00 00 00 00 60 00 00 00 04 0a 00 00 00 .......`........
|
| 540 |
+
| 3008: 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 07 42 ...B...........B
|
| 541 |
+
| 3024: be 00 00 42 c8 00 00 00 00 00 00 42 c8 00 00 00 ...B.......B....
|
| 542 |
+
| 3040: 00 00 00 00 00 00 08 00 00 00 00 42 c8 00 00 00 ...........B....
|
| 543 |
+
| 3056: 00 00 00 40 a0 00 00 00 00 00 00 00 00 00 09 00 ...@............
|
| 544 |
+
| 3072: 00 00 00 42 c8 00 00 42 be 00 00 42 c8 00 00 00 ...B...B...B....
|
| 545 |
+
| 3088: 00 00 00 00 00 00 0a 00 00 00 00 42 c8 00 00 00 ...........B....
|
| 546 |
+
| 3104: 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 0b 00 ...B............
|
| 547 |
+
| 3120: 00 00 00 42 48 00 00 00 00 00 04 2c 80 00 00 00 ...BH......,....
|
| 548 |
+
| 3136: 00 00 00 00 00 00 c4 24 c0 00 04 2c 80 00 00 00 .......$...,....
|
| 549 |
+
| 3152: 00 00 04 2c 80 00 00 00 00 00 00 00 00 00 d0 00 ...,............
|
| 550 |
+
| 3168: 00 00 04 2c 80 00 00 00 00 00 04 24 80 00 00 00 ...,.......$....
|
| 551 |
+
| 3184: 00 00 00 00 00 00 e0 00 00 00 04 2c 80 00 04 24 ...........,...$
|
| 552 |
+
| 3200: c0 00 04 2c 00 00 00 00 00 00 00 00 00 00 00 00 ...,............
|
| 553 |
+
| page 4 offset 12288
|
| 554 |
+
| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................
|
| 555 |
+
| end c3.db
|
| 556 |
+
}]
|
| 557 |
+
catchsql {
|
| 558 |
+
WITH RECURSIVE
|
| 559 |
+
c1(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c1 WHERE x<99),
|
| 560 |
+
c2(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM c2 WHERE y<99)
|
| 561 |
+
INSERT INTO t1(id, x0,x1,y0,y1,label)
|
| 562 |
+
SELECT 1000+x+y*100, x, x+1, y, y+1, printf('box-%d,%d',x,y) FROM c1, c2;
|
| 563 |
+
}
|
| 564 |
+
} {1 {database disk image is malformed}}
|
| 565 |
+
do_test rtreefuzz001-210 {
|
| 566 |
+
catchsql {
|
| 567 |
+
SELECT rtreecheck('t1');
|
| 568 |
+
}
|
| 569 |
+
} {/1 .*corrupt.*/}
|
| 570 |
+
|
| 571 |
+
do_test rtreefuzz001-300 {
|
| 572 |
+
sqlite3 db {}
|
| 573 |
+
db deserialize [decode_hexdb {
|
| 574 |
+
| size 16384 pagesize 4096 filename c4.db
|
| 575 |
+
| page 1 offset 0
|
| 576 |
+
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
| 577 |
+
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04 .....@ ........
|
| 578 |
+
| 32: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 ................
|
| 579 |
+
| 96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f ...............O
|
| 580 |
+
| 112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
| 581 |
+
| 3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17 ............^...
|
| 582 |
+
| 3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72 .....tablet1_par
|
| 583 |
+
| 3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45 entt1_parent.CRE
|
| 584 |
+
| 3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61 ATE TABLE .t1_pa
|
| 585 |
+
| 3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 rent.(nodeno INT
|
| 586 |
+
| 3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
|
| 587 |
+
| 3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17 ,parentnode)Q...
|
| 588 |
+
| 3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65 ....tablet1_node
|
| 589 |
+
| 3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54 t1_node.CREATE T
|
| 590 |
+
| 3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e ABLE .t1_node.(n
|
| 591 |
+
| 3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52 odeno INTEGER PR
|
| 592 |
+
| 3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c IMARY KEY,data).
|
| 593 |
+
| 3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f ........tablet1_
|
| 594 |
+
| 3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52 rowidt1_rowid.CR
|
| 595 |
+
| 3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72 EATE TABLE .t1_r
|
| 596 |
+
| 3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE
|
| 597 |
+
| 3984: 47 45 72 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GEr PRIMARY KEY,
|
| 598 |
+
| 4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07 nodeno,a0,a1)Q..
|
| 599 |
+
| 4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43 ......tablet1t1C
|
| 600 |
+
| 4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA
|
| 601 |
+
| 4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 BLE t1 USING rtr
|
| 602 |
+
| 4064: 65 65 28 69 64 2c 78 30 2c 78 31 2c 79 30 2c 79 ee(id,x0,x1,y0,y
|
| 603 |
+
| 4080: 31 2c 2b 6c 61 62 65 6c 2c 2b 6f 74 68 65 72 29 1,+label,+other)
|
| 604 |
+
| page 2 offset 4096
|
| 605 |
+
| 0: 0d 00 00 00 0e 0e f7 00 0f e8 0f 00 fb 70 f9 e0 .............p..
|
| 606 |
+
| 16: f9 10 f8 10 f7 00 f5 e0 f4 f0 f3 90 f2 90 f1 80 ................
|
| 607 |
+
| 32: f0 60 ef 00 00 00 00 00 00 00 00 00 00 00 00 00 .`..............
|
| 608 |
+
| 3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f ..............to
|
| 609 |
+
| 3840: 70 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74 p half.....#.bot
|
| 610 |
+
| 3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72 tom half.....!.r
|
| 611 |
+
| 3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00 ight half.......
|
| 612 |
+
| 3888: 6c 65 66 74 20 68 61 6c 66 14 0a 05 00 09 2b 00 left half.....+.
|
| 613 |
+
| 3904: 00 03 98 20 49 98 2f 6c 62 05 74 68 69 6e 67 0d ... I./lb.thing.
|
| 614 |
+
| 3920: 09 05 00 09 1d 00 74 6f 70 20 65 64 67 65 10 08 ......top edge..
|
| 615 |
+
| 3936: 05 00 09 23 00 62 6f 74 74 6f 6d 20 65 64 67 65 ...#.bottom edge
|
| 616 |
+
| 3952: 0f 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67 .....!.right edg
|
| 617 |
+
| 3968: 65 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67 e.......left edg
|
| 618 |
+
| 3984: 65 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04 e.......center..
|
| 619 |
+
| 4000: 05 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74 ...1.upper-right
|
| 620 |
+
| 4016: 20 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f corner.....1.lo
|
| 621 |
+
| 4032: 77 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72 wer-right corner
|
| 622 |
+
| 4048: 16 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66 ...../.upper-lef
|
| 623 |
+
| 4064: 74 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 00 6c t corner...../.l
|
| 624 |
+
| 4080: 6f 77 65 72 2d 6c 65 66 74 20 63 6f 72 6e 65 72 ower-left corner
|
| 625 |
+
| page 3 offset 8192
|
| 626 |
+
| 0: 0d 00 00 00 01 0b 2d 00 0b 2d 00 00 00 00 00 00 ......-..-......
|
| 627 |
+
| 2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01 ..............P.
|
| 628 |
+
| 2864: 04 00 93 24 00 00 00 0e 00 00 00 00 00 00 00 01 ...$............
|
| 629 |
+
| 2880: 00 00 00 04 01 20 00 00 00 00 00 04 12 00 00 00 ..... ..........
|
| 630 |
+
| 2896: 00 00 00 00 00 00 00 23 00 00 00 00 41 20 00 00 .......#....A ..
|
| 631 |
+
| 2912: 42 b4 00 00 42 c8 00 00 00 00 00 00 00 00 00 03 B...B...........
|
| 632 |
+
| 2928: 42 b4 00 00 42 c8 00 00 00 00 00 00 41 20 00 00 B...B.......A ..
|
| 633 |
+
| 2944: 00 00 00 00 00 00 00 04 42 b4 00 00 42 c8 00 00 ........B...B...
|
| 634 |
+
| 2960: 42 b4 00 00 42 c8 00 00 00 00 00 00 00 00 00 05 B...B...........
|
| 635 |
+
| 2976: 42 20 00 00 42 70 00 00 42 20 00 00 42 70 00 00 B ..Bp..B ..Bp..
|
| 636 |
+
| 2992: 00 00 00 00 00 00 00 06 00 00 00 00 40 a0 00 00 ............@...
|
| 637 |
+
| 3008: 00 00 00 04 2c 80 00 00 00 00 00 00 00 00 00 74 ....,..........t
|
| 638 |
+
| 3024: 2b e0 00 04 2c 80 00 04 2c 80 00 00 00 00 00 00 +...,...,.......
|
| 639 |
+
| 3040: 00 00 00 80 00 00 00 04 2c 80 00 00 00 00 00 04 ........,.......
|
| 640 |
+
| 3056: 0a 00 00 00 00 00 b0 80 00 00 04 2c 80 00 04 2b ...........,...+
|
| 641 |
+
| 3072: e0 00 04 2c 80 00 00 00 00 00 00 00 00 00 a0 00 ...,............
|
| 642 |
+
| 3088: 00 00 04 2c 80 00 00 00 00 00 04 2c 80 00 00 00 ...,.......,....
|
| 643 |
+
| 3104: 00 00 00 00 00 00 b0 00 00 00 04 24 80 00 00 00 ...........$....
|
| 644 |
+
| 3120: 00 00 04 2c 80 00 00 00 00 00 00 00 50 00 91 f0 ...,........P...
|
| 645 |
+
| 3136: 06 c6 56 67 42 06 86 16 c6 61 40 a0 50 00 92 b0 [email protected]...
|
| 646 |
+
| 3152: 07 46 86 52 07 76 86 f6 c6 52 07 46 86 96 e6 70 .F.R.v...R.F...p
|
| 647 |
+
| 3168: d0 90 50 00 91 d0 07 46 f7 02 06 56 46 76 51 00 ..P....F...VFvQ.
|
| 648 |
+
| 3184: 80 50 00 92 30 06 26 f7 47 46 f6 d2 06 56 46 76 .P..0.&.GF...VFv
|
| 649 |
+
| 3200: 50 f0 70 50 00 92 10 07 26 96 76 87 42 06 56 46 P.pP....&.v.B.VF
|
| 650 |
+
| 3216: 76 50 e0 60 50 00 91 f0 06 c6 56 67 42 06 56 46 vP.`P.....VgB.VF
|
| 651 |
+
| 3232: 76 50 b0 50 50 00 91 90 06 36 56 e7 46 57 21 70 vP.PP....6V.FW!p
|
| 652 |
+
| 3248: 40 50 00 93 10 07 57 07 06 57 22 d7 26 96 76 87 @P....W..W..&.v.
|
| 653 |
+
| 3264: 42 06 36 f7 26 e6 57 21 70 30 50 00 93 10 06 c6 B.6.&.W!p0P.....
|
| 654 |
+
| 3280: f7 76 57 22 d7 26 96 76 87 42 06 36 f7 26 e6 57 .vW..&.v.B.6.&.W
|
| 655 |
+
| 3296: 21 60 20 50 00 92 f0 07 57 07 06 57 22 d6 c6 56 !` P....W..W...V
|
| 656 |
+
| 3312: 60 00 00 c4 24 c0 00 04 2c 80 00 00 00 00 00 04 `...$...,.......
|
| 657 |
+
| 3328: 2c 80 00 00 00 00 00 00 00 00 00 d0 00 00 00 04 ,...............
|
| 658 |
+
| 3344: 2c 80 00 00 00 00 00 04 24 80 00 00 00 00 00 00 ,.......$.......
|
| 659 |
+
| 3360: 00 00 00 e0 00 00 00 04 2c 80 00 04 24 c0 00 04 ........,...$...
|
| 660 |
+
| 3376: 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ,...............
|
| 661 |
+
| page 4 offset 12288
|
| 662 |
+
| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................
|
| 663 |
+
| end c4.db
|
| 664 |
+
}]
|
| 665 |
+
catchsql {
|
| 666 |
+
UPDATE t1 SET label='x';
|
| 667 |
+
}
|
| 668 |
+
} {1 {rtree constraint failed: t1.(y0<=y1)}}
|
| 669 |
+
do_test rtreefuzz001-310 {
|
| 670 |
+
catchsql {
|
| 671 |
+
SELECT rtreecheck('t1');
|
| 672 |
+
}
|
| 673 |
+
} {/1 .*corrupt.*/}
|
| 674 |
+
|
| 675 |
+
do_test rtreefuzz001-400 {
|
| 676 |
+
sqlite3 db {}
|
| 677 |
+
db deserialize [decode_hexdb {
|
| 678 |
+
| size 16384 pagesize 4096 filename c7.db
|
| 679 |
+
| page 1 offset 0
|
| 680 |
+
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
| 681 |
+
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 04 .....@ ........
|
| 682 |
+
| 32: 00 00 00 00 01 00 00 00 00 00 00 04 00 00 00 04 ................
|
| 683 |
+
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
|
| 684 |
+
| 96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f ...............O
|
| 685 |
+
| 112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
| 686 |
+
| 3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17 ............^...
|
| 687 |
+
| 3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72 .....tablet1_par
|
| 688 |
+
| 3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45 entt1_parent.CRE
|
| 689 |
+
| 3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61 ATE TABLE .t1_pa
|
| 690 |
+
| 3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 rent.(nodeno INT
|
| 691 |
+
| 3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
|
| 692 |
+
| 3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17 ,parentnode)Q...
|
| 693 |
+
| 3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65 ....tablet1_node
|
| 694 |
+
| 3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54 t1_node.CREATE T
|
| 695 |
+
| 3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e ABLE .t1_node.(n
|
| 696 |
+
| 3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52 odeno INTEGER PR
|
| 697 |
+
| 3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c IMARY KEY,data).
|
| 698 |
+
| 3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f ........tablet1_
|
| 699 |
+
| 3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52 rowidt1_rowid.CR
|
| 700 |
+
| 3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72 EATE TABLE .t1_r
|
| 701 |
+
| 3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE
|
| 702 |
+
| 3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY,
|
| 703 |
+
| 4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07 nodeno,a0,a1)Q..
|
| 704 |
+
| 4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43 ......tablet1t1C
|
| 705 |
+
| 4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA
|
| 706 |
+
| 4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 BLE t1 USING rtr
|
| 707 |
+
| 4064: 65 65 28 69 64 2c 78 30 2c 78 31 2c 79 30 2c 79 ee(id,x0,x1,y0,y
|
| 708 |
+
| 4080: 31 2c 2b 6c 61 62 65 6c 2c 2b 6f 74 68 65 72 29 1,+label,+other)
|
| 709 |
+
| page 2 offset 4096
|
| 710 |
+
| 0: 0d 00 00 00 0e 0e f7 00 0f e8 0f d0 0f b7 0f 9e ................
|
| 711 |
+
| 16: 0f 91 0f 81 0f 70 0f 5e 0f 4f 0f 39 0f 29 0f 18 .....p.^.O.9.)..
|
| 712 |
+
| 32: 0f 06 0e f7 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
| 713 |
+
| 3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f ..............to
|
| 714 |
+
| 3840: 70 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74 p half.....#.bot
|
| 715 |
+
| 3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72 tom half.....!.r
|
| 716 |
+
| 3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00 ight half.......
|
| 717 |
+
| 3888: 6c 65 66 74 20 68 61 6c 66 14 0a 05 00 09 2b 00 left half.....+.
|
| 718 |
+
| 3904: 74 68 65 20 77 68 6f 6c 65 20 74 68 69 6e 67 0d the whole thing.
|
| 719 |
+
| 3920: 09 05 00 09 1d 00 74 6f 70 20 65 64 67 65 10 08 ......top edge..
|
| 720 |
+
| 3936: 05 00 09 23 00 62 6f 74 74 6f 6d 20 65 64 67 65 ...#.bottom edge
|
| 721 |
+
| 3952: 0f 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67 .....!.right edg
|
| 722 |
+
| 3968: 65 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67 e.......left edg
|
| 723 |
+
| 3984: 65 0b 05 05 00 09 19 00 23 65 6e 74 65 72 17 04 e.......#enter..
|
| 724 |
+
| 4000: 05 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74 ...1.upper-right
|
| 725 |
+
| 4016: 20 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f corner.....1.lo
|
| 726 |
+
| 4032: 77 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72 wer-right corner
|
| 727 |
+
| 4048: 16 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66 ...../.upper-lef
|
| 728 |
+
| 4064: 74 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 00 6c t corner...../.l
|
| 729 |
+
| 4080: 6f 77 65 72 2d 6c 65 66 74 20 63 6f 72 6e 65 72 ower-left corner
|
| 730 |
+
| page 3 offset 8192
|
| 731 |
+
| 0: 0d 00 00 00 02 0b 2d 00 0b 2d 00 00 00 00 00 00 ......-..-......
|
| 732 |
+
| 2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01 ..............P.
|
| 733 |
+
| 2864: 04 00 93 24 00 00 00 00 00 00 00 00 08 00 00 00 ...$............
|
| 734 |
+
| 2880: 00 42 c8 00 00 00 00 00 00 40 a0 00 00 00 00 00 .B.......@......
|
| 735 |
+
| 2896: 00 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 07 ....B...........
|
| 736 |
+
| 2912: 42 be 00 00 42 c8 00 00 00 00 00 00 42 c8 00 00 B...B.......B...
|
| 737 |
+
| 2928: 00 00 00 00 00 00 00 08 00 00 00 00 42 c8 00 00 ............B...
|
| 738 |
+
| 2944: 00 00 00 00 40 a0 00 00 00 00 00 00 00 00 00 09 ....@...........
|
| 739 |
+
| 2960: 00 00 00 00 42 c8 00 00 42 be 00 00 42 c8 00 00 ....B...B...B...
|
| 740 |
+
| 2976: 00 00 00 00 00 00 00 0a 00 00 00 00 42 c8 00 00 ............B...
|
| 741 |
+
| 2992: 00 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 0b ....B...........
|
| 742 |
+
| 3008: 00 00 00 00 42 48 00 00 00 00 00 04 2c 80 00 00 ....BH......,...
|
| 743 |
+
| 3024: 00 00 00 00 00 00 00 c4 00 00 00 00 00 42 c8 00 .............B..
|
| 744 |
+
| 3040: 00 00 00 00 00 00 00 00 07 42 be 00 00 42 c8 00 .........B...B..
|
| 745 |
+
| 3056: 00 00 00 00 00 42 c8 00 00 00 00 00 00 00 00 00 .....B..........
|
| 746 |
+
| 3072: 08 00 00 00 00 42 c8 00 00 00 00 00 00 40 a0 00 .....B.......@..
|
| 747 |
+
| 3088: 00 00 00 00 00 00 00 00 09 00 00 00 00 42 c8 00 .............B..
|
| 748 |
+
| 3104: 00 42 be 00 00 42 c8 00 00 00 00 00 00 00 00 00 .B...B..........
|
| 749 |
+
| 3120: 0a 00 00 00 00 42 c8 00 00 00 00 00 00 42 c8 00 .....B.......B..
|
| 750 |
+
| 3136: 00 00 00 00 00 00 00 00 0b 00 00 00 00 42 48 00 .............BH.
|
| 751 |
+
| 3152: 00 00 00 00 04 2c 80 00 00 00 00 00 00 00 00 00 .....,..........
|
| 752 |
+
| 3168: c4 24 c0 00 04 2c 80 00 00 00 00 00 04 2c 80 00 .$...,.......,..
|
| 753 |
+
| 3184: 00 00 00 00 00 00 00 00 d0 00 00 00 04 2c 80 00 .............,..
|
| 754 |
+
| 3200: 00 00 00 00 04 24 80 00 00 00 00 00 00 00 00 00 .....$..........
|
| 755 |
+
| 3216: e0 00 00 00 04 2c 80 00 04 24 c0 00 04 2c 00 00 .....,...$...,..
|
| 756 |
+
| page 4 offset 12288
|
| 757 |
+
| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 0e 00 00 00 ................
|
| 758 |
+
| 16: 00 42 c8 00 00 42 4c 00 00 42 c8 00 00 00 00 00 .B...BL..B......
|
| 759 |
+
| 32: 00 00 00 0a 00 00 00 00 42 c8 00 00 00 00 00 00 ........B.......
|
| 760 |
+
| 48: 42 c8 00 00 00 00 00 00 00 00 00 0b 00 00 00 00 B...............
|
| 761 |
+
| 64: 42 48 00 00 00 00 00 04 2c 80 00 00 00 00 00 00 BH......,.......
|
| 762 |
+
| 80: 00 00 00 c4 24 c0 00 04 2c 80 00 00 00 00 00 04 ....$...,.......
|
| 763 |
+
| 96: 2c 80 00 00 00 00 00 00 00 00 00 d0 00 00 00 04 ,...............
|
| 764 |
+
| 112: 2c 80 00 00 00 00 00 04 24 80 00 00 00 00 00 00 ,.......$.......
|
| 765 |
+
| 128: 00 00 00 e0 00 00 00 04 2c 80 00 04 24 c0 00 04 ........,...$...
|
| 766 |
+
| 144: 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ,...............
|
| 767 |
+
| end c7.db
|
| 768 |
+
}]
|
| 769 |
+
catchsql {
|
| 770 |
+
WITH RECURSIVE
|
| 771 |
+
c1(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c1 WHERE x<8),
|
| 772 |
+
c2(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM c2 WHERE y<5)
|
| 773 |
+
INSERT INTO t1(id, x0,x1,y0,y1,label)
|
| 774 |
+
SELECT 1000+x+y*100, x, x+1, y, y+1, printf('box-%d,%d',x,y) FROM c1, c2;
|
| 775 |
+
}
|
| 776 |
+
} {1 {database disk image is malformed}}
|
| 777 |
+
|
| 778 |
+
do_test rtreefuzz001-500 {
|
| 779 |
+
sqlite3 db {}
|
| 780 |
+
db deserialize [decode_hexdb {
|
| 781 |
+
| size 16384 pagesize 4096 filename crash-2e81f5dce5cbd4.db
|
| 782 |
+
| page 1 offset 0
|
| 783 |
+
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
| 784 |
+
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00 .....@ ........
|
| 785 |
+
| 96: 00 00 00 00 0d 00 00 00 05 0e 6d 00 0f c8 0f 7b ..........m.....
|
| 786 |
+
| 112: 0f 20 0e cd 0e 6d 00 00 00 00 00 00 00 00 00 00 . ...m..........
|
| 787 |
+
| 3680: 00 00 00 00 00 00 00 00 00 00 00 00 00 5e 05 07 .............^..
|
| 788 |
+
| 3696: 17 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 ......tablet1_pa
|
| 789 |
+
| 3712: 72 65 6e 74 74 31 5f 70 61 72 65 6e 74 05 43 52 rentt1_parent.CR
|
| 790 |
+
| 3728: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 EATE TABLE .t1_p
|
| 791 |
+
| 3744: 61 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e arent.(nodeno IN
|
| 792 |
+
| 3760: 54 45 47 45 42 20 50 52 49 4d 41 52 59 20 4b 45 TEGEB PRIMARY KE
|
| 793 |
+
| 3776: 59 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 04 06 Y,parentnode)Q..
|
| 794 |
+
| 3792: 17 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 .....tablet1_nod
|
| 795 |
+
| 3808: 65 74 31 5f 6e 6f 64 65 04 43 52 45 41 54 45 20 et1_node.CREATE
|
| 796 |
+
| 3824: 54 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 TABLE .t1_node.(
|
| 797 |
+
| 3840: 6e 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 nodeno INTEGER P
|
| 798 |
+
| 3856: 52 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 RIMARY KEY,data)
|
| 799 |
+
| 3872: 59 03 07 17 1d 1d 01 81 05 74 61 62 6c 65 84 31 Y........table.1
|
| 800 |
+
| 3888: 5f 72 6f 77 69 64 74 31 5f 72 6f 87 69 64 03 43 _rowidt1_ro.id.C
|
| 801 |
+
| 3904: 52 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f REATE TABLE .t1_
|
| 802 |
+
| 3920: 72 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 rowid.(rowid INT
|
| 803 |
+
| 3936: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
|
| 804 |
+
| 3952: 2c 6e f8 64 65 6e 6f 2c 61 30 29 4b 02 07 17 11 ,n.deno,a0)K....
|
| 805 |
+
| 3968: 11 08 81 03 74 22 62 6c 65 74 31 74 31 43 52 45 ....t.blet1t1CRE
|
| 806 |
+
| 3984: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c ATE VIRTUAL TABL
|
| 807 |
+
| 4000: 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 65 65 E t1 USING rtree
|
| 808 |
+
| 4016: 5f 69 33 32 28 69 cc 2c 78 30 2c 78 31 2c 79 30 _i32(i.,x0,x1,y0
|
| 809 |
+
| 4032: 2c 79 31 2c 2b 65 78 29 36 01 06 17 17 17 01 4d ,y1,+ex)6......M
|
| 810 |
+
| 4048: 74 61 62 6c 65 63 6f 6f 72 64 63 6f 6f 72 64 02 tablecoordcoord.
|
| 811 |
+
| 4064: 43 52 45 41 54 45 20 54 41 42 4c 45 20 63 6f 6f CREATE TABLE coo
|
| 812 |
+
| 4080: 71 64 28 76 20 49 4e 54 2c 20 77 20 49 4e 54 29 qd(v INT, w INT)
|
| 813 |
+
| page 2 offset 4096
|
| 814 |
+
| 4016: 00 00 00 00 00 00 00 00 00 00 00 05 0a 03 01 01 ................
|
| 815 |
+
| 4032: 0a 02 05 09 03 01 01 09 02 05 08 03 01 01 08 02 ................
|
| 816 |
+
| 4048: 05 07 03 01 01 07 02 05 06 03 11 01 06 02 05 05 ................
|
| 817 |
+
| 4064: 03 01 01 05 02 05 04 03 01 01 04 02 05 03 03 01 ................
|
| 818 |
+
| 4080: 01 03 02 05 02 03 01 01 02 02 04 01 03 09 01 02 ................
|
| 819 |
+
| page 3 offset 8192
|
| 820 |
+
| 0: 0d 0e 4f 00 64 0b 5a 12 0d bb 0d 84 0f eb 0d c6 ..O.d.Z.........
|
| 821 |
+
| 16: 0f d7 0e cc 0f c1 0f b6 0f ab 0f 9f 0f 94 0d 8f ................
|
| 822 |
+
| 32: 0f 86 0d d1 0f 62 0f 67 0f 5c 0f 51 1f 46 0f 3a .....b.g...Q.F.:
|
| 823 |
+
| 48: 0f 30 0d 9a 0f 21 0d dc 0f 00 00 00 00 00 00 00 .0...!..........
|
| 824 |
+
| 2896: 00 00 00 00 00 00 00 00 00 00 0a ce 1a 04 00 01 ................
|
| 825 |
+
| 2912: 17 03 31 30 78 31 30 0a 4e 19 03 ff f1 15 03 31 ..10x10.N......1
|
| 826 |
+
| 2928: 30 78 39 09 ce 18 04 00 01 15 03 31 30 78 38 09 0x9........10x8.
|
| 827 |
+
| 2944: ce 17 04 00 01 15 03 31 30 78 37 09 ce 16 04 00 .......10x7.....
|
| 828 |
+
| 2960: 12 15 03 31 30 78 36 09 ce 15 04 00 01 15 03 31 ...10x6........1
|
| 829 |
+
| 2976: 30 78 35 09 ce 14 04 00 01 15 0d a1 30 78 34 09 0x5.........0x4.
|
| 830 |
+
| 2992: ce 13 04 00 01 15 03 31 30 78 33 09 ce 12 04 00 .......10x3.....
|
| 831 |
+
| 3008: 01 15 03 31 40 78 32 09 ce 11 04 00 01 15 03 31 [email protected]
|
| 832 |
+
| 3024: 30 78 31 09 c6 32 04 00 01 15 03 39 78 31 30 08 0x1..2.....9x10.
|
| 833 |
+
| 3040: c6 31 04 00 01 13 03 39 78 39 08 c6 30 04 00 01 .1.....9x9..0...
|
| 834 |
+
| 3056: 13 03 39 78 38 08 c6 2f 04 00 01 14 03 39 78 37 ..9x8../.....9x7
|
| 835 |
+
| 3072: 08 c6 2e 04 00 01 13 03 39 78 36 08 c6 2d 04 00 ........9x6..-..
|
| 836 |
+
| 3088: 01 13 03 39 78 34 f8 c6 2c 04 00 01 13 03 39 78 ...9x4..,.....9x
|
| 837 |
+
| 3104: 34 08 c6 2b 04 00 60 13 03 39 79 13 08 c6 2a 04 4..+..`..9y...*.
|
| 838 |
+
| 3120: 00 11 13 03 39 78 32 08 c6 29 04 00 01 13 03 39 ....9x2..).....9
|
| 839 |
+
| 3136: 78 31 09 be 4a 04 00 01 15 03 38 78 31 30 08 be x1..J.....8x10..
|
| 840 |
+
| 3152: 49 04 00 01 13 03 38 78 39 08 be 48 04 00 01 13 I.....8x9..H....
|
| 841 |
+
| 3168: 03 38 77 98 08 be 47 04 00 01 14 23 38 78 37 08 .8w...G....#8x7.
|
| 842 |
+
| 3184: be 46 04 00 01 13 03 38 78 36 08 be 45 04 00 01 .F.....8x6..E...
|
| 843 |
+
| 3200: 13 03 38 78 35 08 be 44 04 00 01 13 03 38 78 34 ..8x5..D.....8x4
|
| 844 |
+
| 3216: 08 be 43 04 00 01 13 03 38 78 33 08 be 42 04 00 ..C.....8x3..B..
|
| 845 |
+
| 3232: 01 13 03 38 78 32 08 be 41 04 00 01 13 03 38 78 ...8x2..A.....8x
|
| 846 |
+
| 3248: 31 09 b6 62 04 00 01 15 03 37 68 31 30 08 b6 61 1..b.....7h10..a
|
| 847 |
+
| 3264: 04 00 01 13 03 37 79 39 08 b6 60 04 00 01 12 f3 .....7y9..`.....
|
| 848 |
+
| 3280: 37 78 38 08 b6 5e 04 00 01 13 03 37 78 37 08 b6 7x8..^.....7x7..
|
| 849 |
+
| 3296: 5e 04 00 01 13 03 37 78 36 08 b6 5d 04 00 01 13 ^.....7x6..]....
|
| 850 |
+
| 3312: 03 37 78 35 08 b6 5c 04 00 00 13 03 37 78 34 08 .7x5........7x4.
|
| 851 |
+
| 3328: b6 5b 04 00 01 13 03 37 78 33 08 b6 5a 04 00 01 .[.....7x3..Z...
|
| 852 |
+
| 3344: 13 03 37 78 32 08 b6 59 04 00 01 13 03 37 78 31 ..7x2..Y.....7x1
|
| 853 |
+
| 3360: 09 ae 7a 04 00 01 15 03 36 78 31 30 08 ae 79 04 ..z.....6x10..y.
|
| 854 |
+
| 3376: 00 01 e2 03 36 78 39 08 ae 78 04 00 01 13 03 36 ....6x9..x.....6
|
| 855 |
+
| 3392: 78 38 08 ae 77 04 00 01 13 03 36 78 37 08 ae 76 x8..w.....6x7..v
|
| 856 |
+
| 3408: 04 00 01 13 03 36 78 36 08 ae 85 04 00 01 13 03 .....6x6........
|
| 857 |
+
| 3424: 36 78 35 08 ae 73 f4 00 01 13 03 36 78 34 08 ae 6x5..s.....6x4..
|
| 858 |
+
| 3440: 73 04 00 01 13 03 36 78 33 08 ae 72 04 00 01 13 s.....6x3..r....
|
| 859 |
+
| 3456: 03 36 78 32 08 87 6a 04 00 01 13 02 3d e8 32 08 .6x2..j.....=.2.
|
| 860 |
+
| 3472: 8f 52 04 00 01 13 02 32 78 32 08 97 3b 04 00 01 .R.....2x2..;...
|
| 861 |
+
| 3488: 13 02 33 78 32 08 9f 22 04 00 01 13 02 34 78 32 ..3x2........4x2
|
| 862 |
+
| 3504: 08 a7 0a 04 00 01 13 02 35 78 32 08 87 69 04 00 ........5x2..i..
|
| 863 |
+
| 3520: 01 13 02 31 78 31 08 87 6c 04 00 01 13 02 31 78 ...1x1..l.....1x
|
| 864 |
+
| 3536: 34 08 8f 54 04 00 01 13 02 32 78 34 08 97 3c 04 4..T.....2x4..<.
|
| 865 |
+
| 3552: 00 01 12 f2 33 78 34 08 9f 24 04 00 01 13 02 34 ....3x4..$.....4
|
| 866 |
+
| 3568: 78 34 08 a7 0c 04 00 01 13 02 35 78 34 0e 6c 00 x4........5x4.l.
|
| 867 |
+
| 3584: 08 ae 71 04 00 01 13 03 36 78 31 09 a7 12 04 00 ..q.....6x1.....
|
| 868 |
+
| 3600: 01 15 02 35 78 31 30 08 a7 11 04 00 01 13 02 35 ...5x10........5
|
| 869 |
+
| 3616: 78 39 08 a7 10 04 00 01 13 02 35 78 38 08 a7 0f x9........5x8...
|
| 870 |
+
| 3632: 04 00 01 14 02 35 78 37 08 a7 0e 04 00 01 13 02 .....5x7........
|
| 871 |
+
| 3648: 35 78 36 08 a7 0d 04 00 01 13 02 35 78 35 0e 0e 5x6........5x5..
|
| 872 |
+
| 3664: b3 00 08 00 01 00 03 08 a7 0b 04 00 01 13 02 35 ...............5
|
| 873 |
+
| 3680: 78 33 0e d1 00 08 a7 09 04 00 01 13 02 35 78 31 x3...........5x1
|
| 874 |
+
| 3696: 09 9f 2a 04 00 01 15 02 34 78 31 30 03 cf 29 04 ..*.....4x10..).
|
| 875 |
+
| 3712: 00 01 13 02 34 78 39 08 9f 28 04 00 01 13 02 34 ....4x9..(.....4
|
| 876 |
+
| 3728: 78 38 09 9f 27 04 00 01 13 02 34 78 37 08 9f 26 x8..'.....4x7..&
|
| 877 |
+
| 3744: 04 00 01 13 0e a4 78 36 08 9f 25 04 00 01 13 02 ......x6..%.....
|
| 878 |
+
| 3760: 34 78 35 0f 18 00 09 00 09 13 34 78 08 9f 23 04 4x5.......4x..#.
|
| 879 |
+
| 3776: 00 01 13 02 34 78 33 0f 36 00 08 9f 21 04 00 01 ....4x3.6...!...
|
| 880 |
+
| 3792: 13 02 34 78 31 09 97 42 04 00 01 15 02 33 78 31 ..4x1..B.....3x1
|
| 881 |
+
| 3808: 30 08 97 41 04 00 01 13 02 33 78 39 08 97 40 04 0..A.....3x9..@.
|
| 882 |
+
| 3824: 00 01 13 02 33 78 38 18 97 3f 04 00 01 13 02 33 ....3x8..?.....3
|
| 883 |
+
| 3840: 78 37 08 97 3e 04 00 01 13 02 33 78 36 08 97 3d x7..>.....3x6..=
|
| 884 |
+
| 3856: 04 00 01 13 02 33 78 35 1f 7d 00 09 00 09 13 33 .....3x5.......3
|
| 885 |
+
| 3872: 78 07 97 3b 04 00 01 13 02 33 78 33 0f 9b 00 08 x..;.....3x3....
|
| 886 |
+
| 3888: 97 39 04 00 01 13 02 33 78 31 09 8f 5a 04 00 01 .9.....3x1..Z...
|
| 887 |
+
| 3904: 15 02 32 79 31 30 08 8f 59 04 00 01 13 fa 32 78 ..2y10..Y.....2x
|
| 888 |
+
| 3920: 39 08 8f 58 04 00 01 13 02 32 78 38 08 8f 57 04 9..X.....2x8..W.
|
| 889 |
+
| 3936: 00 01 13 02 32 78 37 08 8f 56 04 00 01 13 02 32 ....2x7..V.....2
|
| 890 |
+
| 3952: 78 36 08 8f 55 04 00 01 13 02 32 78 35 0f e2 00 x6..U.....2x5...
|
| 891 |
+
| 3968: 09 00 09 13 32 78 08 8f 53 04 00 01 13 02 32 78 ....2x..S.....2x
|
| 892 |
+
| 3984: 33 00 00 00 08 8f 51 04 00 01 13 02 aa 78 31 09 3.....Q......x1.
|
| 893 |
+
| 4000: 87 72 04 00 01 15 02 31 78 31 30 08 87 71 04 00 .r.....1x10..q..
|
| 894 |
+
| 4016: 01 13 03 31 78 39 08 87 70 04 00 01 13 02 31 78 ...1x9..p.....1x
|
| 895 |
+
| 4032: 38 08 87 6f 04 00 01 13 02 31 78 37 08 87 6e 04 8..o.....1x7..n.
|
| 896 |
+
| 4048: 00 01 13 02 31 78 36 08 87 6d 04 00 01 13 02 31 ....1x6..m.....1
|
| 897 |
+
| 4064: 7d 25 0f f9 00 08 ff f9 13 31 78 08 87 6b 04 00 .%.......1x..k..
|
| 898 |
+
| 4080: 01 13 02 31 78 33 00 00 00 00 00 08 00 01 00 03 ...1x3..........
|
| 899 |
+
| page 4 offset 12288
|
| 900 |
+
| 0: 0d 00 00 00 03 01 87 00 0b 2d 06 5a 01 87 00 00 .........-.Z....
|
| 901 |
+
| 384: 00 00 00 00 00 00 00 89 50 01 54 00 93 24 00 00 ........P.T..$..
|
| 902 |
+
| 400: 00 32 00 00 00 00 00 00 23 2f 00 00 00 09 00 00 .2......#/......
|
| 903 |
+
| 416: 00 0b 00 00 00 07 00 00 00 09 00 00 00 00 00 00 ................
|
| 904 |
+
| 432: 23 2e 00 00 10 09 00 00 00 0b 00 00 00 06 00 00 #...............
|
| 905 |
+
| 448: 00 08 00 00 00 00 00 00 23 2d 00 00 00 09 00 00 ........#-......
|
| 906 |
+
| 464: 00 0b 00 00 00 05 00 00 00 07 00 00 00 00 00 00 ................
|
| 907 |
+
| 480: 23 2c 00 00 00 09 00 00 00 0b 00 00 00 04 00 00 #,..............
|
| 908 |
+
| 496: 00 06 00 00 00 00 00 00 23 2b 00 00 00 09 00 00 ........#+......
|
| 909 |
+
| 512: 00 0b 00 00 00 03 00 00 00 05 00 00 00 00 00 00 ................
|
| 910 |
+
| 528: 23 2a 00 00 00 09 00 00 00 0b 00 00 00 02 00 00 #*..............
|
| 911 |
+
| 544: 00 04 00 00 00 00 00 00 23 29 00 00 00 09 00 00 ........#)......
|
| 912 |
+
| 560: 00 0b 00 00 00 01 00 00 00 03 00 00 00 00 00 00 ................
|
| 913 |
+
| 576: 1f 4a 00 00 00 08 00 00 00 0a 00 00 00 0a 00 00 .J..............
|
| 914 |
+
| 592: 00 0c 00 00 00 00 00 00 0f 49 00 00 00 08 00 00 .........I......
|
| 915 |
+
| 608: 00 0a 00 00 00 09 00 00 00 0b 00 00 00 00 00 00 ................
|
| 916 |
+
| 624: 1f 48 00 00 00 08 00 00 00 0a 00 00 00 08 00 06 .H..............
|
| 917 |
+
| 640: 00 0a 00 00 00 00 00 00 1f 47 00 00 00 08 00 00 .........G......
|
| 918 |
+
| 656: 00 0a 00 00 00 07 00 00 00 09 00 00 00 00 00 00 ................
|
| 919 |
+
| 672: 15 d6 00 00 00 08 00 00 00 0a 00 00 00 06 00 00 ................
|
| 920 |
+
| 688: 00 08 00 00 00 00 00 00 1f 45 00 00 00 08 00 00 .........E......
|
| 921 |
+
| 704: 00 0a 00 00 00 05 00 00 00 07 00 00 00 00 00 00 ................
|
| 922 |
+
| 720: 1f 44 00 00 00 08 00 00 00 0a 00 00 00 04 00 00 .D..............
|
| 923 |
+
| 736: 00 06 00 00 00 00 00 00 1f 43 00 00 00 07 ff ff .........C......
|
| 924 |
+
| 752: f0 0a 00 00 00 03 00 00 00 05 00 00 00 00 00 00 ................
|
| 925 |
+
| 768: 1f 42 00 00 00 08 00 00 00 0a 00 00 00 01 ff f0 .B..............
|
| 926 |
+
| 784: 00 03 ff ff ff ff ff ff 1f 41 00 00 00 08 00 00 .........A......
|
| 927 |
+
| 800: 00 0a 00 00 00 01 00 00 00 03 00 00 00 00 00 00 ................
|
| 928 |
+
| 816: 1b 62 00 00 00 07 00 00 00 09 00 00 00 0a 00 00 .b..............
|
| 929 |
+
| 832: 00 0c 05 00 00 00 00 00 1b 64 10 00 00 07 00 00 .........d......
|
| 930 |
+
| 848: 00 09 00 00 00 09 00 00 00 0b 00 00 00 00 00 00 ................
|
| 931 |
+
| 864: 1b 60 00 00 00 07 00 00 00 09 00 00 00 08 00 00 .`..............
|
| 932 |
+
| 880: 00 0a 00 00 00 00 00 00 1b 5f 00 00 00 07 00 00 ........._......
|
| 933 |
+
| 896: 00 09 00 00 00 07 00 00 00 09 00 00 00 00 00 00 ................
|
| 934 |
+
| 912: 1b 5e 00 00 00 07 00 00 00 09 00 00 00 06 00 00 .^..............
|
| 935 |
+
| 928: 00 08 00 00 00 00 00 00 1b 5d 00 00 00 08 00 00 .........]......
|
| 936 |
+
| 944: 00 09 00 00 00 05 00 00 00 07 00 00 00 00 00 00 ................
|
| 937 |
+
| 960: 1b 5c 00 00 00 07 00 00 00 09 00 00 00 04 00 00 ................
|
| 938 |
+
| 976: 06 46 00 00 00 00 00 00 1b 5b 00 00 00 07 00 00 .F.......[......
|
| 939 |
+
| 992: 00 09 00 00 00 03 00 00 00 04 ff f0 00 00 00 00 ................
|
| 940 |
+
| 1008: 1b 5a 00 00 00 07 00 00 00 19 00 00 00 02 00 00 .Z..............
|
| 941 |
+
| 1024: 00 04 00 00 00 00 00 00 1b 59 00 00 00 07 00 00 .........Y......
|
| 942 |
+
| 1040: 00 09 00 00 00 01 00 00 00 03 00 00 00 00 ff f0 ................
|
| 943 |
+
| 1056: 17 7a 00 00 00 06 00 00 00 08 00 00 00 0a 00 00 .z..............
|
| 944 |
+
| 1072: 00 0c 00 00 00 00 00 00 17 79 00 00 00 06 00 00 .........y......
|
| 945 |
+
| 1088: 00 08 00 00 00 09 00 00 00 0b 00 00 00 00 00 00 ................
|
| 946 |
+
| 1104: 17 78 00 00 00 06 00 00 00 08 00 00 00 08 00 00 .x..............
|
| 947 |
+
| 1120: 00 0a 00 00 00 00 00 00 17 77 00 00 00 06 10 00 .........w......
|
| 948 |
+
| 1136: 00 08 00 00 00 07 00 09 c0 09 00 00 00 00 00 00 ................
|
| 949 |
+
| 1152: 17 76 00 00 00 06 00 00 00 08 00 00 00 06 00 00 .v..............
|
| 950 |
+
| 1168: 00 08 00 00 00 00 00 00 17 75 00 00 00 06 00 00 .........u......
|
| 951 |
+
| 1184: 00 08 00 00 00 05 00 00 00 07 00 00 00 00 00 00 ................
|
| 952 |
+
| 1200: 17 74 00 00 00 06 00 00 00 08 00 00 00 03 ff ff .t..............
|
| 953 |
+
| 1216: f0 06 00 00 00 83 00 00 17 73 00 00 00 06 00 00 .........s......
|
| 954 |
+
| 1232: 00 08 00 00 00 03 00 00 00 05 00 00 00 00 00 00 ................
|
| 955 |
+
| 1248: 17 71 ff 00 00 06 00 00 10 08 00 00 00 02 00 00 .q..............
|
| 956 |
+
| 1264: 00 04 00 00 c0 00 00 00 17 0d 00 00 00 06 00 00 ................
|
| 957 |
+
| 1280: 00 08 00 00 e7 01 00 00 00 03 00 00 09 e0 00 00 ................
|
| 958 |
+
| 1296: 23 30 00 00 00 09 00 00 00 0a 00 00 00 08 00 00 #0..............
|
| 959 |
+
| 1312: 00 0a 00 00 00 00 bb 00 23 31 00 00 00 09 00 00 ........#1......
|
| 960 |
+
| 1328: 00 0b 00 00 00 09 00 00 00 0b 00 00 00 00 00 00 ................
|
| 961 |
+
| 1344: 23 32 00 00 00 09 00 00 00 0b 00 00 00 0a 00 00 #2..............
|
| 962 |
+
| 1360: 00 0c 00 00 00 00 00 00 27 11 00 00 00 0a 00 00 ........'.......
|
| 963 |
+
| 1376: 00 0c 00 00 00 01 00 08 c0 03 00 00 00 00 00 00 ................
|
| 964 |
+
| 1392: 27 12 00 00 00 0a 00 00 00 0c 51 00 00 02 00 00 '.........Q.....
|
| 965 |
+
| 1408: 00 04 6f 00 00 00 00 00 27 13 00 00 00 09 ff ff ..o.....'.......
|
| 966 |
+
| 1424: 00 0c 00 00 00 03 00 00 00 05 00 00 00 00 00 00 ................
|
| 967 |
+
| 1440: 27 14 00 00 00 0a 00 00 00 00 00 00 00 00 00 00 '...............
|
| 968 |
+
| 1616: 00 00 00 00 00 00 00 00 00 00 89 50 02 04 00 93 ...........P....
|
| 969 |
+
| 1632: 24 00 00 00 32 00 00 00 00 00 00 23 8c 00 00 00 $...2......#....
|
| 970 |
+
| 1648: 05 00 00 00 07 00 00 00 04 00 00 00 06 00 00 00 ................
|
| 971 |
+
| 1664: 00 00 00 0f a4 00 00 00 04 00 00 00 06 00 00 00 ................
|
| 972 |
+
| 1680: 04 00 00 00 06 00 00 00 00 00 00 0b bc 00 00 00 ................
|
| 973 |
+
| 1696: 03 00 00 00 05 00 00 00 04 00 00 00 06 00 00 00 ................
|
| 974 |
+
| 1712: 00 00 00 07 d4 00 00 00 02 00 00 00 04 00 00 00 ................
|
| 975 |
+
| 1728: 04 00 00 00 06 00 00 00 10 00 00 03 ec 00 00 00 ................
|
| 976 |
+
| 1744: 01 00 00 00 03 00 00 00 04 00 00 00 06 00 00 00 ................
|
| 977 |
+
| 1760: 00 00 00 13 8d 00 00 00 05 00 00 00 07 00 00 00 ................
|
| 978 |
+
| 1776: 05 00 00 00 07 00 00 00 00 00 00 0f a5 00 00 00 ................
|
| 979 |
+
| 1792: 04 00 00 00 06 00 00 00 05 00 00 00 07 00 00 00 ................
|
| 980 |
+
| 1808: 00 00 00 0b bd 00 00 00 03 00 00 00 05 00 00 00 ................
|
| 981 |
+
| 1824: 05 00 00 00 07 00 00 00 00 00 00 07 d5 00 00 00 ................
|
| 982 |
+
| 1840: 02 00 00 00 05 00 00 00 05 00 00 00 07 00 00 00 ................
|
| 983 |
+
| 1856: 00 00 00 03 ed 00 00 00 01 00 00 00 03 00 00 00 ................
|
| 984 |
+
| 1872: 05 00 00 00 07 00 00 00 00 00 00 13 8e 00 00 00 ................
|
| 985 |
+
| 1888: 05 00 00 00 07 00 00 00 06 00 00 00 08 00 00 00 ................
|
| 986 |
+
| 1904: 00 00 00 0f a6 00 00 00 04 00 00 00 06 00 00 00 ................
|
| 987 |
+
| 1920: 06 00 00 00 07 ff ff 00 00 00 00 0b be 00 00 00 ................
|
| 988 |
+
| 1936: 0b 40 00 00 05 00 00 00 06 00 00 00 08 00 00 00 .@..............
|
| 989 |
+
| 1952: 00 00 00 07 d6 00 00 00 02 00 00 00 04 00 00 00 ................
|
| 990 |
+
| 1968: 05 00 00 00 08 00 00 00 00 00 00 03 ee 00 00 00 ................
|
| 991 |
+
| 1984: 01 00 00 00 02 ff ff 00 06 00 00 00 08 00 00 00 ................
|
| 992 |
+
| 2000: 00 00 00 13 8f 00 00 00 05 00 00 00 07 00 00 00 ................
|
| 993 |
+
| 2016: 07 00 00 00 09 00 00 00 00 00 00 0f a7 00 00 00 ................
|
| 994 |
+
| 2032: 04 00 00 00 06 00 00 00 07 00 00 00 09 00 00 08 ................
|
| 995 |
+
| 2048: 30 00 00 0b bf 00 00 00 03 00 00 00 05 00 00 00 0...............
|
| 996 |
+
| 2064: 07 00 00 00 09 00 00 00 00 00 00 07 d7 00 00 00 ................
|
| 997 |
+
| 2080: 02 00 00 00 04 00 00 00 07 00 00 00 09 00 00 00 ................
|
| 998 |
+
| 2096: 00 00 00 03 ef 00 00 00 01 00 00 00 03 00 00 00 ................
|
| 999 |
+
| 2112: 07 00 00 00 09 00 00 00 00 00 00 13 90 00 00 00 ................
|
| 1000 |
+
| 2128: 05 00 01 00 07 00 00 00 08 00 00 00 0a 00 00 00 ................
|
| 1001 |
+
| 2144: 00 00 00 0f a8 00 00 00 04 00 00 00 06 00 00 00 ................
|
| 1002 |
+
| 2160: 08 00 00 00 0a 00 00 00 00 00 00 0b f2 00 00 00 ................
|
| 1003 |
+
| 2176: 03 00 00 00 05 00 00 00 08 00 00 00 0a 00 00 01 ................
|
| 1004 |
+
| 2192: 00 00 00 07 d8 00 00 00 02 00 00 00 04 00 00 00 ................
|
| 1005 |
+
| 2208: 08 00 00 00 0a 00 00 00 00 00 00 03 f0 00 00 00 ................
|
| 1006 |
+
| 2224: 01 00 00 00 03 00 00 00 08 00 00 00 09 ff 00 00 ................
|
| 1007 |
+
| 2240: 00 00 00 13 91 00 00 00 05 00 00 00 07 00 00 00 ................
|
| 1008 |
+
| 2256: 09 00 00 00 0b 00 00 00 00 00 00 0f a9 00 00 00 ................
|
| 1009 |
+
| 2272: 04 00 00 00 06 00 00 00 09 00 00 00 0b 00 00 00 ................
|
| 1010 |
+
| 2288: 00 00 00 0b c1 00 00 00 03 00 00 00 05 00 00 00 ................
|
| 1011 |
+
| 2304: 09 00 00 00 0b 00 00 00 00 00 00 07 d9 00 00 00 ................
|
| 1012 |
+
| 2320: 02 00 00 00 04 00 00 00 09 00 00 00 0b 00 00 01 ................
|
| 1013 |
+
| 2336: 00 00 00 03 f0 ff ff 00 01 00 00 00 03 00 00 00 ................
|
| 1014 |
+
| 2352: 09 00 00 00 0b 00 00 00 00 00 00 13 92 00 00 00 ................
|
| 1015 |
+
| 2368: 05 00 00 00 07 00 00 00 0a 00 00 00 0c 00 00 00 ................
|
| 1016 |
+
| 2384: 00 00 00 0f aa 00 00 00 04 00 00 00 06 00 00 00 ................
|
| 1017 |
+
| 2400: 0a 00 00 00 0c 00 00 00 00 00 00 0b c2 00 00 00 ................
|
| 1018 |
+
| 2416: 03 00 00 00 05 00 00 00 0a 00 00 00 0c 00 00 00 ................
|
| 1019 |
+
| 2432: 00 00 00 07 da 00 00 00 02 00 00 00 04 00 00 00 ................
|
| 1020 |
+
| 2448: 0a 00 00 00 0c 00 00 00 00 00 00 03 f2 00 00 00 ................
|
| 1021 |
+
| 2464: 01 00 00 10 03 00 00 00 0a 00 00 00 0c 00 00 00 ................
|
| 1022 |
+
| 2480: 00 00 00 03 eb 00 00 00 01 00 00 00 03 00 00 00 ................
|
| 1023 |
+
| 2496: 03 00 00 00 05 00 00 00 00 00 00 07 d3 00 00 00 ................
|
| 1024 |
+
| 2512: 02 00 00 00 04 00 00 00 03 00 00 00 05 00 00 00 ................
|
| 1025 |
+
| 2528: 00 00 00 0b bb 00 00 00 03 00 00 00 05 00 00 00 ................
|
| 1026 |
+
| 2544: 03 00 00 00 05 00 00 00 00 00 00 0f a3 00 00 00 ................
|
| 1027 |
+
| 2560: 04 00 00 00 06 00 00 00 03 00 00 00 05 00 00 00 ................
|
| 1028 |
+
| 2576: 00 00 00 13 8b 00 00 00 05 00 00 00 07 00 00 00 ................
|
| 1029 |
+
| 2592: 03 00 00 00 05 00 00 00 00 00 00 03 ea 00 00 00 ................
|
| 1030 |
+
| 2608: 01 00 00 00 03 00 00 00 02 00 00 00 04 00 00 00 ................
|
| 1031 |
+
| 2624: 00 00 00 07 d2 00 00 00 02 00 00 00 04 00 00 00 ................
|
| 1032 |
+
| 2640: 02 00 00 00 04 00 00 00 00 00 00 0b ba 00 00 00 ................
|
| 1033 |
+
| 2656: 03 00 00 00 05 00 00 00 02 00 00 00 04 00 00 00 ................
|
| 1034 |
+
| 2672: 00 00 00 0f a1 ff ff ff 04 00 00 00 06 00 00 00 ................
|
| 1035 |
+
| 2688: 02 00 00 00 04 00 00 00 00 00 00 13 8a 00 00 00 ................
|
| 1036 |
+
| 2704: 05 00 00 00 06 ff ff ff f2 00 00 00 04 00 00 00 ................
|
| 1037 |
+
| 2720: 00 00 00 03 e9 00 00 00 01 00 00 00 03 00 00 00 ................
|
| 1038 |
+
| 2736: 01 00 00 00 03 00 00 00 00 00 00 07 d1 00 00 00 ................
|
| 1039 |
+
| 2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 01 ..............P.
|
| 1040 |
+
| 2864: 04 00 93 24 00 01 00 02 00 00 00 00 00 00 00 02 ...$............
|
| 1041 |
+
| 2880: ff ff ff 06 00 00 00 0c 00 00 00 01 00 00 00 0b ................
|
| 1042 |
+
| 2896: 00 00 00 00 00 00 00 02 40 00 00 00 00 00 00 00 ........@.......
|
| 1043 |
+
| end crash-2e81f5dce5cbd4.db}]
|
| 1044 |
+
execsql { PRAGMA writable_schema = 1;}
|
| 1045 |
+
catchsql {UPDATE t1 SET ex= ex ISNULL}
|
| 1046 |
+
} {0 {}}
|
| 1047 |
+
|
| 1048 |
+
do_test rtreefuzz001-600 {
|
| 1049 |
+
sqlite3 db {}
|
| 1050 |
+
db deserialize [decode_hexdb {
|
| 1051 |
+
| size 20480 pagesize 4096 filename crash-7b37d80f000235.db
|
| 1052 |
+
| page 1 offset 0
|
| 1053 |
+
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
| 1054 |
+
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05 .....@ ........
|
| 1055 |
+
| 32: 00 00 00 00 00 00 00 00 00 00 10 06 00 00 00 04 ................
|
| 1056 |
+
| 96: 00 00 00 00 0d 00 00 00 05 0e 49 00 0f 99 0f 40 ..........I....@
|
| 1057 |
+
| 112: 0e da 0e 8f 0e 49 00 00 00 00 00 00 00 00 00 00 .....I..........
|
| 1058 |
+
| 3648: 00 00 00 00 00 00 00 00 00 44 05 06 17 15 15 08 .........D......
|
| 1059 |
+
| 3664: 6f 74 61 62 6c 65 67 65 6f 31 67 65 6f 31 43 52 otablegeo1geo1CR
|
| 1060 |
+
| 3680: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
|
| 1061 |
+
| 3696: 4c 45 20 67 65 6f 31 20 55 53 49 4e 47 20 67 65 LE geo1 USING ge
|
| 1062 |
+
| 3712: 6f 70 6f 6c 79 28 74 79 70 65 2c 63 6c 72 29 49 opoly(type,clr)I
|
| 1063 |
+
| 3728: 04 06 17 1f 1f 01 63 74 61 62 6c 65 71 75 65 72 ......ctablequer
|
| 1064 |
+
| 3744: 79 70 6f 6c 79 71 75 65 72 79 70 6f 6c 79 05 43 ypolyquerypoly.C
|
| 1065 |
+
| 3760: 52 45 41 54 45 20 54 41 42 4c 45 20 71 75 65 72 REATE TABLE quer
|
| 1066 |
+
| 3776: 79 70 6f 6c 79 28 70 6f 6c 79 20 4a 53 4f 4e 2c ypoly(poly JSON,
|
| 1067 |
+
| 3792: 20 63 6c 72 20 54 45 58 54 29 64 03 07 17 23 23 clr TEXT)d...##
|
| 1068 |
+
| 3808: 01 81 0f 74 61 62 6c 65 67 65 6f 31 5f 70 61 72 ...tablegeo1_par
|
| 1069 |
+
| 3824: 65 6e 74 67 65 6f 31 5f 70 61 72 65 6e 74 04 43 entgeo1_parent.C
|
| 1070 |
+
| 3840: 52 45 41 54 45 20 54 41 42 4c 45 20 22 67 65 6f REATE TABLE .geo
|
| 1071 |
+
| 3856: 31 5f 70 61 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 1_parent.(nodeno
|
| 1072 |
+
| 3872: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
|
| 1073 |
+
| 3888: 20 4b 45 59 2c 70 61 72 65 6e 74 6e 6f 64 85 29 KEY,parentnod.)
|
| 1074 |
+
| 3904: 57 02 06 17 1f 1f 01 7f 74 61 62 6c 65 67 65 6f W.......tablegeo
|
| 1075 |
+
| 3920: 31 5f 6e 6f 64 65 67 65 6f 31 5f 6e 6f 64 65 03 1_nodegeo1_node.
|
| 1076 |
+
| 3936: 43 52 45 41 54 45 20 54 41 42 4c 45 20 22 67 65 CREATE TABLE .ge
|
| 1077 |
+
| 3952: 6f 31 5f 6e 6f 64 65 22 28 6e 6f 64 65 6e 6f 20 o1_node.(nodeno
|
| 1078 |
+
| 3968: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY
|
| 1079 |
+
| 3984: 4b 45 59 2c 64 61 74 61 29 65 01 07 17 21 21 01 KEY,data)e...!!.
|
| 1080 |
+
| 4000: 81 15 74 61 62 6c 65 67 65 6f 31 5f 72 6f 77 69 ..tablegeo1_rowi
|
| 1081 |
+
| 4016: 64 67 65 6f 31 5f 72 6f 77 69 64 02 43 52 45 41 dgeo1_rowid.CREA
|
| 1082 |
+
| 4032: 54 45 20 54 41 42 4c 45 20 22 67 65 6f 31 5f 72 TE TABLE .geo1_r
|
| 1083 |
+
| 4048: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE
|
| 1084 |
+
| 4064: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY,
|
| 1085 |
+
| 4080: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 2c 61 32 29 nodeno,a0,a1,a2)
|
| 1086 |
+
| page 2 offset 4096
|
| 1087 |
+
| 0: 0d 00 00 00 0a 0d ab 00 0f c9 0f 88 0f 48 0f 00 .............H..
|
| 1088 |
+
| 3488: 00 00 00 00 00 00 00 00 00 00 00 45 82 0a 06 00 ...........E....
|
| 1089 |
+
| 3504: 09 74 1d 13 01 00 00 06 00 80 b5 43 00 80 ac 43 .t.........C...C
|
| 1090 |
+
| 3520: 00 00 bd 43 8f 82 9f 43 71 fd c9 43 8f 02 a7 43 ...C...Cq..C...C
|
| 1091 |
+
| 3536: 71 fd c8 43 e4 bd a8 43 64 bb bd 43 f4 3d a2 43 q..C...Cd..C.=.C
|
| 1092 |
+
| 3552: 64 3b b7 43 00 80 ad 43 61 6e 67 6c 65 2d 33 30 d;.C...Cangle-30
|
| 1093 |
+
| 3568: 72 65 64 32 81 4e 06 00 09 44 23 17 01 00 00 03 red2.N...D#.....
|
| 1094 |
+
| 3584: 00 40 3f 44 00 c0 20 44 00 c0 46 44 00 c0 20 44 .@?D.. D..FD.. D
|
| 1095 |
+
| 3600: 00 00 43 44 00 40 28 44 74 72 69 61 6e 67 6c 65 ..CD.@(Dtriangle
|
| 1096 |
+
| 3616: 2d 33 30 62 6c 61 63 6b 35 82 3e 06 00 09 54 1d -30black5.>...T.
|
| 1097 |
+
| 3632: 13 01 00 00 04 00 40 54 44 00 80 1d 44 9a c9 5c [email protected]...
|
| 1098 |
+
| 3648: 44 66 36 1b 44 33 13 5f 44 00 c0 23 44 9a 89 5b Df6.D3._D..#D..[
|
| 1099 |
+
| 3664: 44 a4 60 1d 44 61 72 72 6f 77 2d 35 30 72 65 64 D.`.Darrow-50red
|
| 1100 |
+
| 3680: 36 74 06 00 09 54 1b 17 01 00 00 04 00 80 0d 44 6t...T.........D
|
| 1101 |
+
| 3696: 00 00 f2 42 0a d7 04 44 00 00 ca 42 0a 77 05 44 ...B...D...B.w.D
|
| 1102 |
+
| 3712: 0a 57 c1 42 00 20 0e 44 0a 57 e9 42 6c 69 6e 65 .W.B. .D.W.Bline
|
| 1103 |
+
| 3728: 2d 34 30 67 72 65 65 6e 36 72 06 00 09 54 1b 17 -40green6r...T..
|
| 1104 |
+
| 3744: 01 00 00 04 00 00 7b 43 00 00 ea 42 29 5c 58 43 .......C...B).XC
|
| 1105 |
+
| 3760: 00 00 c2 42 29 dc 5a 43 0a 57 b9 42 00 80 7d 43 ...B).ZC.W.B...C
|
| 1106 |
+
| 3776: 0a 57 e1 42 6c 69 6e 65 2d 34 30 67 72 65 65 6e .W.Bline-40green
|
| 1107 |
+
| 3792: 36 54 06 00 09 54 1b 17 01 00 00 04 00 00 a2 43 6T...T.........C
|
| 1108 |
+
| 3808: 00 00 24 44 00 00 b6 43 00 00 24 44 00 00 b6 43 ..$D...C..$D...C
|
| 1109 |
+
| 3824: 00 40 25 44 00 00 a2 43 00 40 25 44 6c 69 6e 65 .@%D...C.@%Dline
|
| 1110 |
+
| 3840: 2d 34 30 62 6c 61 63 6b 3e 37 06 00 09 64 1d 15 -40black>7...d..
|
| 1111 |
+
| 3856: 01 00 00 05 00 80 f0 43 00 00 54 43 66 16 01 44 .......C..TCf..D
|
| 1112 |
+
| 3872: 66 a6 30 43 cd ec 09 44 00 00 54 43 8f 0a 09 44 f.0C...D..TC...D
|
| 1113 |
+
| 3888: a4 d0 73 43 66 16 01 44 9a 59 77 43 68 6f 75 73 ..sCf..D.YwChous
|
| 1114 |
+
| 3904: 65 2d 37 30 62 6c 75 65 3e 35 06 00 09 64 1d 15 e-70blue>5...d..
|
| 1115 |
+
| 3920: 01 00 00 05 00 00 a2 43 00 00 5a 43 cd ac b3 43 .......C..ZC...C
|
| 1116 |
+
| 3936: 66 a6 36 43 9a 59 c5 43 00 00 5a 43 1f 95 c3 43 f.6C.Y.C..ZC...C
|
| 1117 |
+
| 3952: a4 d0 79 43 cd ac b3 43 9a 59 7d 43 68 6f 75 73 ..yC...C.Y.Chous
|
| 1118 |
+
| 3968: 65 2d 37 30 62 6c 75 65 3f 2c 06 00 09 64 1d 17 e-70blue?,...d..
|
| 1119 |
+
| 3984: 01 00 00 05 00 00 f5 43 00 00 2f 43 00 00 07 44 .......C../C...D
|
| 1120 |
+
| 4000: 00 00 2f 43 00 00 07 44 00 00 61 43 00 c0 00 44 ../C...D..aC...D
|
| 1121 |
+
| 4016: 00 00 75 43 00 00 f5 43 00 00 61 43 68 6f 75 73 ..uC...C..aChous
|
| 1122 |
+
| 4032: 65 2d 37 30 62 6c 61 63 6b 35 1f 06 10 09 54 19 e-70black5....T.
|
| 1123 |
+
| 4048: 17 01 00 00 04 00 00 9b 43 00 00 67 43 0a 57 92 ........C..gC.W.
|
| 1124 |
+
| 4064: 43 00 00 5d 43 0a 57 97 43 14 ae 4b 42 ff ff a0 C..]C.W.C..KB...
|
| 1125 |
+
| 4080: 43 14 ae 55 43 62 6f 78 2d 32 30 67 72 65 65 6e C..UCbox-20green
|
| 1126 |
+
| page 3 offset 8192
|
| 1127 |
+
| 0: 0d 00 00 00 01 0b 2d 00 0b 2e 00 00 00 00 00 00 ......-.........
|
| 1128 |
+
| 2848: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 50 ...............P
|
| 1129 |
+
| 2864: 01 04 00 93 24 00 00 00 0a 00 00 00 00 00 00 01 ....$...........
|
| 1130 |
+
| 2880: 0a 43 b5 80 00 43 c9 fd 71 43 9f 82 8f 43 ad 80 .C...C..qC...C..
|
| 1131 |
+
| 2896: 00 00 00 00 00 00 00 00 72 43 58 5c 29 43 7d 80 ........rCX.)C..
|
| 1132 |
+
| 2912: 00 42 b9 57 0a 42 ea 00 00 00 00 00 00 00 00 00 .B.W.B..........
|
| 1133 |
+
| 2928: 35 43 a2 00 00 43 c5 59 9a 43 36 a6 66 43 7d 59 5C...C.Y.C6.fC.Y
|
| 1134 |
+
| 2944: 9a 00 00 00 00 00 00 00 1f 43 92 57 0a 43 a0 00 .........C.W.C..
|
| 1135 |
+
| 2960: 00 43 4b ae 14 43 67 00 00 00 00 00 00 00 00 00 .CK..Cg.........
|
| 1136 |
+
| 2976: 37 43 f0 80 00 44 09 ec cd 43 30 a6 66 43 77 59 7C...D...C0.fCwY
|
| 1137 |
+
| 2992: 9a 00 00 00 00 00 00 00 2c 43 f5 00 00 44 07 00 ........,C...D..
|
| 1138 |
+
| 3008: 00 43 2f 00 00 43 75 00 00 00 00 00 00 00 00 00 .C/..Cu.........
|
| 1139 |
+
| 3024: 74 44 04 d7 0a 44 0e 20 00 42 c1 57 0a 42 f2 00 tD...D. .B.W.B..
|
| 1140 |
+
| 3040: 00 00 00 00 00 00 00 00 ce 44 3f 40 00 44 46 c0 [email protected].
|
| 1141 |
+
| 3056: 00 44 20 c0 00 44 28 40 00 00 00 00 00 00 00 00 .D ..D(@........
|
| 1142 |
+
| 3072: be 44 54 40 00 44 5f 13 33 44 1b 36 66 44 23 c0 [email protected]_.3D.6fD#.
|
| 1143 |
+
| 3088: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
| 1144 |
+
| 3104: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
| 1145 |
+
| 3120: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
| 1146 |
+
| 3136: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
| 1147 |
+
| 3152: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
| 1148 |
+
| 3168: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
| 1149 |
+
| 3184: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
| 1150 |
+
| 3200: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
| 1151 |
+
| 3216: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
| 1152 |
+
| 3232: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
| 1153 |
+
| 3248: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
| 1154 |
+
| 3264: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
| 1155 |
+
| 3280: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
| 1156 |
+
| 3296: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 00 .D$..D%@........
|
| 1157 |
+
| 3312: 54 43 a2 00 00 43 b6 00 00 44 24 00 00 44 25 40 TC...C...D$..D%@
|
| 1158 |
+
| 3328: 00 00 00 00 00 00 00 00 54 43 a2 00 00 43 b6 00 ........TC...C..
|
| 1159 |
+
| 3344: 00 44 24 00 00 44 25 40 00 00 00 00 00 00 00 01 .D$..D%@........
|
| 1160 |
+
| 3360: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
| 1161 |
+
| 3376: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
| 1162 |
+
| 3392: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
| 1163 |
+
| 3408: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
| 1164 |
+
| 3424: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
| 1165 |
+
| 3440: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
| 1166 |
+
| 3456: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
| 1167 |
+
| 3472: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
| 1168 |
+
| 3488: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
| 1169 |
+
| 3504: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
| 1170 |
+
| 3520: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
| 1171 |
+
| 3536: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
| 1172 |
+
| 3552: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
| 1173 |
+
| 3568: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
| 1174 |
+
| 3584: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
| 1175 |
+
| 3600: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
| 1176 |
+
| 3616: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
| 1177 |
+
| 3632: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
| 1178 |
+
| 3648: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
| 1179 |
+
| 3664: 00 00 00 00 00 00 00 01 36 44 53 e0 00 44 56 bb ........6DS..DV.
|
| 1180 |
+
| 3680: 64 43 71 34 bc 43 7d 00 00 00 00 00 00 00 00 01 dCq4.C..........
|
| 1181 |
+
| 3696: 36 44 53 e0 00 44 56 bb 64 43 71 34 bc 43 7d 00 6DS..DV.dCq4.C..
|
| 1182 |
+
| page 4 offset 12288
|
| 1183 |
+
| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................
|
| 1184 |
+
| page 5 offset 16384
|
| 1185 |
+
| 0: 0d 00 00 00 01 0f 8f 00 00 00 00 00 00 00 00 00 ................
|
| 1186 |
+
| 3968: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 6f ...............o
|
| 1187 |
+
| 3984: 01 04 81 57 19 5b 5b 33 30 30 2c 33 30 30 5d 2c ...W.[[300,300],
|
| 1188 |
+
| 4000: 5b 34 30 30 2c 33 35 30 5d 2c 5b 35 30 30 2c 32 [400,350],[500,2
|
| 1189 |
+
| 4016: 35 30 5d 2c 5b 34 38 30 2c 35 30 30 5d 2c 5b 34 50],[480,500],[4
|
| 1190 |
+
| 4032: 30 30 2c 34 38 30 5d 2c 5c 33 30 30 2c 35 35 30 00,480],.300,550
|
| 1191 |
+
| 4048: 5d 2c 5b 32 38 30 2c 34 35 30 5d 2c 5b 33 32 30 ],[280,450],[320
|
| 1192 |
+
| 4064: 2c 34 30 30 5d 2c 5b 32 38 30 2c 33 35 30 5d 2c ,400],[280,350],
|
| 1193 |
+
| 4080: 5b 33 30 30 2c 33 30 00 00 00 00 00 00 00 00 00 [300,30.........
|
| 1194 |
+
| end crash-7b37d80f000235.db
|
| 1195 |
+
}]} {}
|
| 1196 |
+
|
| 1197 |
+
ifcapable geopoly {
|
| 1198 |
+
|
| 1199 |
+
do_catchsql_test rtreefuzz001-601 {
|
| 1200 |
+
SAVEPOINT one;
|
| 1201 |
+
UPDATE geo1 SET clr=CASE WHEN rowid IN ( SELECT geo1.rowid FROM geo1, querypoly ) THEN 'e' ELSE 'blue' END;
|
| 1202 |
+
} {1 {database disk image is malformed}}
|
| 1203 |
+
|
| 1204 |
+
do_catchsql_test rtreefuzz001-602 {
|
| 1205 |
+
SELECT geopoly_svg(_shape, printf('j',geo1.clr))
|
| 1206 |
+
FROM geo1, querypoly WHERE geopoly_overlap(_shape, poly);
|
| 1207 |
+
} {1 {database disk image is malformed}}
|
| 1208 |
+
|
| 1209 |
+
} ;# ifcapable geopoly
|
| 1210 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** 2010 August 28
|
| 3 |
+
**
|
| 4 |
+
** The author disclaims copyright to this source code. In place of
|
| 5 |
+
** a legal notice, here is a blessing:
|
| 6 |
+
**
|
| 7 |
+
** May you do good and not evil.
|
| 8 |
+
** May you find forgiveness for yourself and forgive others.
|
| 9 |
+
** May you share freely, never taking more than you give.
|
| 10 |
+
**
|
| 11 |
+
*************************************************************************
|
| 12 |
+
** Code for testing all sorts of SQLite interfaces. This code
|
| 13 |
+
** is not included in the SQLite library.
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include "sqlite3.h"
|
| 17 |
+
#include "tclsqlite.h"
|
| 18 |
+
|
| 19 |
+
/* Solely for the UNUSED_PARAMETER() macro. */
|
| 20 |
+
#include "sqliteInt.h"
|
| 21 |
+
|
| 22 |
+
#ifdef SQLITE_ENABLE_RTREE
|
| 23 |
+
|
| 24 |
+
typedef struct BoxGeomCtx BoxGeomCtx;
|
| 25 |
+
struct BoxGeomCtx {
|
| 26 |
+
Tcl_Interp *interp;
|
| 27 |
+
Tcl_Obj *pScript;
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
typedef struct BoxQueryCtx BoxQueryCtx;
|
| 31 |
+
struct BoxQueryCtx {
|
| 32 |
+
Tcl_Interp *interp;
|
| 33 |
+
Tcl_Obj *pScript;
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
static void testDelUser(void *pCtx){
|
| 37 |
+
BoxGeomCtx *p = (BoxGeomCtx*)pCtx;
|
| 38 |
+
Tcl_EvalObjEx(p->interp, p->pScript, 0);
|
| 39 |
+
Tcl_DecrRefCount(p->pScript);
|
| 40 |
+
sqlite3_free(p);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
static int invokeTclGeomCb(
|
| 44 |
+
const char *zName,
|
| 45 |
+
sqlite3_rtree_geometry *p,
|
| 46 |
+
int nCoord,
|
| 47 |
+
sqlite3_rtree_dbl *aCoord
|
| 48 |
+
){
|
| 49 |
+
int rc = SQLITE_OK;
|
| 50 |
+
if( p->pContext ){
|
| 51 |
+
char aPtr[64];
|
| 52 |
+
BoxGeomCtx *pCtx = (BoxGeomCtx*)p->pContext;
|
| 53 |
+
Tcl_Interp *interp = pCtx->interp;
|
| 54 |
+
Tcl_Obj *pScript = 0;
|
| 55 |
+
Tcl_Obj *pParam = 0;
|
| 56 |
+
Tcl_Obj *pCoord = 0;
|
| 57 |
+
int ii;
|
| 58 |
+
Tcl_Obj *pRes;
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
pScript = Tcl_DuplicateObj(pCtx->pScript);
|
| 62 |
+
Tcl_IncrRefCount(pScript);
|
| 63 |
+
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj(zName,-1));
|
| 64 |
+
|
| 65 |
+
sqlite3_snprintf(sizeof(aPtr)-1, aPtr, "%p", (void*)p->pContext);
|
| 66 |
+
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj(aPtr,-1));
|
| 67 |
+
|
| 68 |
+
pParam = Tcl_NewObj();
|
| 69 |
+
for(ii=0; ii<p->nParam; ii++){
|
| 70 |
+
Tcl_ListObjAppendElement(
|
| 71 |
+
interp, pParam, Tcl_NewDoubleObj(p->aParam[ii])
|
| 72 |
+
);
|
| 73 |
+
}
|
| 74 |
+
Tcl_ListObjAppendElement(interp, pScript, pParam);
|
| 75 |
+
|
| 76 |
+
pCoord = Tcl_NewObj();
|
| 77 |
+
for(ii=0; ii<nCoord; ii++){
|
| 78 |
+
Tcl_ListObjAppendElement(interp, pCoord, Tcl_NewDoubleObj(aCoord[ii]));
|
| 79 |
+
}
|
| 80 |
+
Tcl_ListObjAppendElement(interp, pScript, pCoord);
|
| 81 |
+
|
| 82 |
+
sqlite3_snprintf(sizeof(aPtr)-1, aPtr, "%p", (void*)p);
|
| 83 |
+
Tcl_ListObjAppendElement(interp, pScript, Tcl_NewStringObj(aPtr,-1));
|
| 84 |
+
|
| 85 |
+
rc = Tcl_EvalObjEx(interp, pScript, 0);
|
| 86 |
+
if( rc!=TCL_OK ){
|
| 87 |
+
rc = SQLITE_ERROR;
|
| 88 |
+
}else{
|
| 89 |
+
Tcl_Size nObj = 0;
|
| 90 |
+
Tcl_Obj **aObj = 0;
|
| 91 |
+
|
| 92 |
+
pRes = Tcl_GetObjResult(interp);
|
| 93 |
+
if( Tcl_ListObjGetElements(interp, pRes, &nObj, &aObj) ) return TCL_ERROR;
|
| 94 |
+
if( nObj>0 ){
|
| 95 |
+
const char *zCmd = Tcl_GetString(aObj[0]);
|
| 96 |
+
if( 0==sqlite3_stricmp(zCmd, "zero") ){
|
| 97 |
+
p->aParam[0] = 0.0;
|
| 98 |
+
p->nParam = 1;
|
| 99 |
+
}
|
| 100 |
+
else if( 0==sqlite3_stricmp(zCmd, "user") ){
|
| 101 |
+
if( p->pUser || p->xDelUser ){
|
| 102 |
+
rc = SQLITE_ERROR;
|
| 103 |
+
}else{
|
| 104 |
+
BoxGeomCtx *pBGCtx = sqlite3_malloc(sizeof(BoxGeomCtx));
|
| 105 |
+
if( pBGCtx==0 ){
|
| 106 |
+
rc = SQLITE_NOMEM;
|
| 107 |
+
}else{
|
| 108 |
+
pBGCtx->interp = interp;
|
| 109 |
+
pBGCtx->pScript = Tcl_DuplicateObj(pRes);
|
| 110 |
+
Tcl_IncrRefCount(pBGCtx->pScript);
|
| 111 |
+
Tcl_ListObjReplace(interp, pBGCtx->pScript, 0, 1, 0, 0);
|
| 112 |
+
p->pUser = (void*)pBGCtx;
|
| 113 |
+
p->xDelUser = testDelUser;
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
else if( 0==sqlite3_stricmp(zCmd, "user_is_zero") ){
|
| 118 |
+
if( p->pUser || p->xDelUser ) rc = SQLITE_ERROR;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
return rc;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/*
|
| 127 |
+
# EVIDENCE-OF: R-00693-36727 The legacy xGeom callback is invoked with
|
| 128 |
+
# four arguments.
|
| 129 |
+
|
| 130 |
+
# EVIDENCE-OF: R-50437-53270 The first argument is a pointer to an
|
| 131 |
+
# sqlite3_rtree_geometry structure which provides information about how
|
| 132 |
+
# the SQL function was invoked.
|
| 133 |
+
|
| 134 |
+
# EVIDENCE-OF: R-00090-24248 The third argument, aCoord[], is an array
|
| 135 |
+
# of nCoord coordinates that defines a bounding box to be tested.
|
| 136 |
+
|
| 137 |
+
# EVIDENCE-OF: R-28207-40885 The last argument is a pointer into which
|
| 138 |
+
# the callback result should be written.
|
| 139 |
+
|
| 140 |
+
*/
|
| 141 |
+
static int box_geom(
|
| 142 |
+
sqlite3_rtree_geometry *p, /* R-50437-53270 */
|
| 143 |
+
int nCoord, /* R-02424-24769 */
|
| 144 |
+
sqlite3_rtree_dbl *aCoord, /* R-00090-24248 */
|
| 145 |
+
int *pRes /* R-28207-40885 */
|
| 146 |
+
){
|
| 147 |
+
int ii;
|
| 148 |
+
|
| 149 |
+
if( p->nParam!=nCoord ){
|
| 150 |
+
invokeTclGeomCb("box", p, nCoord, aCoord);
|
| 151 |
+
return SQLITE_ERROR;
|
| 152 |
+
}
|
| 153 |
+
if( invokeTclGeomCb("box", p, nCoord, aCoord) ) return SQLITE_ERROR;
|
| 154 |
+
|
| 155 |
+
for(ii=0; ii<nCoord; ii+=2){
|
| 156 |
+
if( aCoord[ii]>p->aParam[ii+1] || aCoord[ii+1]<p->aParam[ii] ){
|
| 157 |
+
/* R-28207-40885 */
|
| 158 |
+
*pRes = 0;
|
| 159 |
+
return SQLITE_OK;
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/* R-28207-40885 */
|
| 164 |
+
*pRes = 1;
|
| 165 |
+
|
| 166 |
+
return SQLITE_OK;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
static int SQLITE_TCLAPI register_box_geom(
|
| 170 |
+
void * clientData,
|
| 171 |
+
Tcl_Interp *interp,
|
| 172 |
+
int objc,
|
| 173 |
+
Tcl_Obj *CONST objv[]
|
| 174 |
+
){
|
| 175 |
+
extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
|
| 176 |
+
extern const char *sqlite3ErrName(int);
|
| 177 |
+
sqlite3 *db;
|
| 178 |
+
BoxGeomCtx *pCtx;
|
| 179 |
+
char aPtr[64];
|
| 180 |
+
|
| 181 |
+
if( objc!=3 ){
|
| 182 |
+
Tcl_WrongNumArgs(interp, 1, objv, "DB SCRIPT");
|
| 183 |
+
return TCL_ERROR;
|
| 184 |
+
}
|
| 185 |
+
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
| 186 |
+
|
| 187 |
+
pCtx = (BoxGeomCtx*)ckalloc(sizeof(BoxGeomCtx*));
|
| 188 |
+
pCtx->interp = interp;
|
| 189 |
+
pCtx->pScript = Tcl_DuplicateObj(objv[2]);
|
| 190 |
+
Tcl_IncrRefCount(pCtx->pScript);
|
| 191 |
+
|
| 192 |
+
sqlite3_rtree_geometry_callback(db, "box", box_geom, (void*)pCtx);
|
| 193 |
+
|
| 194 |
+
sqlite3_snprintf(64, aPtr, "%p", (void*)pCtx);
|
| 195 |
+
Tcl_SetObjResult(interp, Tcl_NewStringObj(aPtr, -1));
|
| 196 |
+
return TCL_OK;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
static int box_query(sqlite3_rtree_query_info *pInfo){
|
| 200 |
+
const char *azParentWithin[] = {"not", "partly", "fully", 0};
|
| 201 |
+
BoxQueryCtx *pCtx = (BoxQueryCtx*)pInfo->pContext;
|
| 202 |
+
Tcl_Interp *interp = pCtx->interp;
|
| 203 |
+
Tcl_Obj *pEval;
|
| 204 |
+
Tcl_Obj *pArg;
|
| 205 |
+
Tcl_Obj *pTmp = 0;
|
| 206 |
+
int rc;
|
| 207 |
+
int ii;
|
| 208 |
+
|
| 209 |
+
pEval = Tcl_DuplicateObj(pCtx->pScript);
|
| 210 |
+
Tcl_IncrRefCount(pEval);
|
| 211 |
+
pArg = Tcl_NewObj();
|
| 212 |
+
Tcl_IncrRefCount(pArg);
|
| 213 |
+
|
| 214 |
+
/* aParam[] */
|
| 215 |
+
pTmp = Tcl_NewObj();
|
| 216 |
+
Tcl_IncrRefCount(pTmp);
|
| 217 |
+
for(ii=0; ii<pInfo->nParam; ii++){
|
| 218 |
+
Tcl_Obj *p = Tcl_NewDoubleObj(pInfo->aParam[ii]);
|
| 219 |
+
Tcl_ListObjAppendElement(interp, pTmp, p);
|
| 220 |
+
}
|
| 221 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("aParam", -1));
|
| 222 |
+
Tcl_ListObjAppendElement(interp, pArg, pTmp);
|
| 223 |
+
Tcl_DecrRefCount(pTmp);
|
| 224 |
+
|
| 225 |
+
/* aCoord[] */
|
| 226 |
+
pTmp = Tcl_NewObj();
|
| 227 |
+
Tcl_IncrRefCount(pTmp);
|
| 228 |
+
for(ii=0; ii<pInfo->nCoord; ii++){
|
| 229 |
+
Tcl_Obj *p = Tcl_NewDoubleObj(pInfo->aCoord[ii]);
|
| 230 |
+
Tcl_ListObjAppendElement(interp, pTmp, p);
|
| 231 |
+
}
|
| 232 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("aCoord", -1));
|
| 233 |
+
Tcl_ListObjAppendElement(interp, pArg, pTmp);
|
| 234 |
+
Tcl_DecrRefCount(pTmp);
|
| 235 |
+
|
| 236 |
+
/* anQueue[] */
|
| 237 |
+
pTmp = Tcl_NewObj();
|
| 238 |
+
Tcl_IncrRefCount(pTmp);
|
| 239 |
+
for(ii=0; ii<=pInfo->mxLevel; ii++){
|
| 240 |
+
Tcl_Obj *p = Tcl_NewIntObj((int)pInfo->anQueue[ii]);
|
| 241 |
+
Tcl_ListObjAppendElement(interp, pTmp, p);
|
| 242 |
+
}
|
| 243 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("anQueue", -1));
|
| 244 |
+
Tcl_ListObjAppendElement(interp, pArg, pTmp);
|
| 245 |
+
Tcl_DecrRefCount(pTmp);
|
| 246 |
+
|
| 247 |
+
/* iLevel */
|
| 248 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("iLevel", -1));
|
| 249 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewIntObj(pInfo->iLevel));
|
| 250 |
+
|
| 251 |
+
/* mxLevel */
|
| 252 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("mxLevel", -1));
|
| 253 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewIntObj(pInfo->mxLevel));
|
| 254 |
+
|
| 255 |
+
/* iRowid */
|
| 256 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("iRowid", -1));
|
| 257 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewWideIntObj(pInfo->iRowid));
|
| 258 |
+
|
| 259 |
+
/* rParentScore */
|
| 260 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("rParentScore", -1));
|
| 261 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewDoubleObj(pInfo->rParentScore));
|
| 262 |
+
|
| 263 |
+
/* eParentWithin */
|
| 264 |
+
assert( pInfo->eParentWithin==0
|
| 265 |
+
|| pInfo->eParentWithin==1
|
| 266 |
+
|| pInfo->eParentWithin==2
|
| 267 |
+
);
|
| 268 |
+
Tcl_ListObjAppendElement(interp, pArg, Tcl_NewStringObj("eParentWithin", -1));
|
| 269 |
+
Tcl_ListObjAppendElement(interp, pArg,
|
| 270 |
+
Tcl_NewStringObj(azParentWithin[pInfo->eParentWithin], -1)
|
| 271 |
+
);
|
| 272 |
+
|
| 273 |
+
Tcl_ListObjAppendElement(interp, pEval, pArg);
|
| 274 |
+
rc = Tcl_EvalObjEx(interp, pEval, 0) ? SQLITE_ERROR : SQLITE_OK;
|
| 275 |
+
|
| 276 |
+
if( rc==SQLITE_OK ){
|
| 277 |
+
double rScore = 0.0;
|
| 278 |
+
Tcl_Size nObj = 0;
|
| 279 |
+
int eP = 0;
|
| 280 |
+
Tcl_Obj **aObj = 0;
|
| 281 |
+
Tcl_Obj *pRes = Tcl_GetObjResult(interp);
|
| 282 |
+
|
| 283 |
+
if( Tcl_ListObjGetElements(interp, pRes, &nObj, &aObj)
|
| 284 |
+
|| nObj!=2
|
| 285 |
+
|| Tcl_GetDoubleFromObj(interp, aObj[1], &rScore)
|
| 286 |
+
|| Tcl_GetIndexFromObj(interp, aObj[0], azParentWithin, "value", 0, &eP)
|
| 287 |
+
){
|
| 288 |
+
rc = SQLITE_ERROR;
|
| 289 |
+
}else{
|
| 290 |
+
pInfo->rScore = rScore;
|
| 291 |
+
pInfo->eParentWithin = eP;
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
Tcl_DecrRefCount(pArg);
|
| 296 |
+
Tcl_DecrRefCount(pEval);
|
| 297 |
+
return rc;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
static void box_query_destroy(void *p){
|
| 301 |
+
BoxQueryCtx *pCtx = (BoxQueryCtx*)p;
|
| 302 |
+
Tcl_DecrRefCount(pCtx->pScript);
|
| 303 |
+
ckfree((char*)pCtx);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
static int SQLITE_TCLAPI register_box_query(
|
| 307 |
+
void * clientData,
|
| 308 |
+
Tcl_Interp *interp,
|
| 309 |
+
int objc,
|
| 310 |
+
Tcl_Obj *CONST objv[]
|
| 311 |
+
){
|
| 312 |
+
extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
|
| 313 |
+
extern const char *sqlite3ErrName(int);
|
| 314 |
+
sqlite3 *db;
|
| 315 |
+
BoxQueryCtx *pCtx;
|
| 316 |
+
|
| 317 |
+
if( objc!=3 ){
|
| 318 |
+
Tcl_WrongNumArgs(interp, 1, objv, "DB SCRIPT");
|
| 319 |
+
return TCL_ERROR;
|
| 320 |
+
}
|
| 321 |
+
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
| 322 |
+
|
| 323 |
+
pCtx = (BoxQueryCtx*)ckalloc(sizeof(BoxQueryCtx));
|
| 324 |
+
pCtx->interp = interp;
|
| 325 |
+
pCtx->pScript = Tcl_DuplicateObj(objv[2]);
|
| 326 |
+
Tcl_IncrRefCount(pCtx->pScript);
|
| 327 |
+
|
| 328 |
+
sqlite3_rtree_query_callback(
|
| 329 |
+
db, "qbox", box_query, (void*)pCtx, box_query_destroy
|
| 330 |
+
);
|
| 331 |
+
|
| 332 |
+
Tcl_ResetResult(interp);
|
| 333 |
+
return TCL_OK;
|
| 334 |
+
}
|
| 335 |
+
#endif /* SQLITE_ENABLE_RTREE */
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
int Sqlitetestrtreedoc_Init(Tcl_Interp *interp){
|
| 339 |
+
#ifdef SQLITE_ENABLE_RTREE
|
| 340 |
+
Tcl_CreateObjCommand(interp, "register_box_geom", register_box_geom, 0, 0);
|
| 341 |
+
Tcl_CreateObjCommand(interp, "register_box_query", register_box_query, 0, 0);
|
| 342 |
+
#endif /* SQLITE_ENABLE_RTREE */
|
| 343 |
+
return TCL_OK;
|
| 344 |
+
}
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/tkt3363.test
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 2008 Sep 08
|
| 2 |
+
#
|
| 3 |
+
# The author disclaims copyright to this source code. In place of
|
| 4 |
+
# a legal notice, here is a blessing:
|
| 5 |
+
#
|
| 6 |
+
# May you do good and not evil.
|
| 7 |
+
# May you find forgiveness for yourself and forgive others.
|
| 8 |
+
# May you share freely, never taking more than you give.
|
| 9 |
+
#
|
| 10 |
+
#***********************************************************************
|
| 11 |
+
#
|
| 12 |
+
# The focus of this file is testing that ticket #3363 is fixed.
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
if {![info exists testdir]} {
|
| 16 |
+
set testdir [file join [file dirname [info script]] .. .. test]
|
| 17 |
+
}
|
| 18 |
+
source [file join [file dirname [info script]] rtree_util.tcl]
|
| 19 |
+
source $testdir/tester.tcl
|
| 20 |
+
|
| 21 |
+
ifcapable !rtree {
|
| 22 |
+
finish_test
|
| 23 |
+
return
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
do_test tkt3363.1.1 {
|
| 27 |
+
execsql { CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2) }
|
| 28 |
+
} {}
|
| 29 |
+
|
| 30 |
+
do_test tkt3363.1.2 {
|
| 31 |
+
for {set ii 1} {$ii < 50} {incr ii} {
|
| 32 |
+
set x 1000000
|
| 33 |
+
set y [expr 4000000 + $ii*10]
|
| 34 |
+
execsql { INSERT INTO t1 VALUES($ii, $x, $x, $y, $y) }
|
| 35 |
+
}
|
| 36 |
+
} {}
|
| 37 |
+
|
| 38 |
+
do_test tkt3363.1.3 {
|
| 39 |
+
execsql {
|
| 40 |
+
SELECT count(*) FROM t1 WHERE +y2>4000425.0;
|
| 41 |
+
}
|
| 42 |
+
} {7}
|
| 43 |
+
|
| 44 |
+
do_test tkt3363.1.4 {
|
| 45 |
+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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
load ./libsqlite3.dylib
|
| 3 |
+
#package require sqlite3
|
| 4 |
+
source [file join [file dirname $argv0] rtree_util.tcl]
|
| 5 |
+
|
| 6 |
+
wm title . "SQLite r-tree viewer"
|
| 7 |
+
|
| 8 |
+
if {[llength $argv]!=1} {
|
| 9 |
+
puts stderr "Usage: $argv0 <database-file>"
|
| 10 |
+
puts stderr ""
|
| 11 |
+
exit
|
| 12 |
+
}
|
| 13 |
+
sqlite3 db [lindex $argv 0]
|
| 14 |
+
|
| 15 |
+
canvas .c -background white -width 400 -height 300 -highlightthickness 0
|
| 16 |
+
|
| 17 |
+
button .b -text "Parent Node" -command {
|
| 18 |
+
set sql "SELECT parentnode FROM $::O(zTab)_parent WHERE nodeno = $::O(iNode)"
|
| 19 |
+
set ::O(iNode) [db one $sql]
|
| 20 |
+
if {$::O(iNode) eq ""} {set ::O(iNode) 1}
|
| 21 |
+
view_node
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
set O(iNode) 1
|
| 25 |
+
set O(zTab) ""
|
| 26 |
+
set O(listbox_captions) [list]
|
| 27 |
+
set O(listbox_itemmap) [list]
|
| 28 |
+
set O(listbox_highlight) -1
|
| 29 |
+
|
| 30 |
+
listbox .l -listvariable ::O(listbox_captions) -yscrollcommand {.ls set}
|
| 31 |
+
scrollbar .ls -command {.l yview}
|
| 32 |
+
label .status -font courier -anchor w
|
| 33 |
+
label .title -anchor w -text "Node 1:" -background white -borderwidth 0
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
set rtree_tables [list]
|
| 37 |
+
db eval {
|
| 38 |
+
SELECT name
|
| 39 |
+
FROM sqlite_master
|
| 40 |
+
WHERE type='table' AND sql LIKE '%virtual%table%using%rtree%'
|
| 41 |
+
} {
|
| 42 |
+
set nCol [expr [llength [db eval "pragma table_info($name)"]]/6]
|
| 43 |
+
if {$nCol != 5} {
|
| 44 |
+
puts stderr "Not viewing $name - is not 2-dimensional"
|
| 45 |
+
} else {
|
| 46 |
+
lappend rtree_tables [list Table $name]
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
if {$rtree_tables eq ""} {
|
| 50 |
+
puts stderr "Cannot find an r-tree table in database [lindex $argv 0]"
|
| 51 |
+
puts stderr ""
|
| 52 |
+
exit
|
| 53 |
+
}
|
| 54 |
+
eval tk_optionMenu .select option_var $rtree_tables
|
| 55 |
+
trace add variable option_var write set_option_var
|
| 56 |
+
proc set_option_var {args} {
|
| 57 |
+
set ::O(zTab) [lindex $::option_var 1]
|
| 58 |
+
set ::O(iNode) 1
|
| 59 |
+
view_node
|
| 60 |
+
}
|
| 61 |
+
set ::O(zTab) [lindex $::rtree_tables 0 1]
|
| 62 |
+
|
| 63 |
+
bind .l <1> {listbox_click [.l nearest %y]}
|
| 64 |
+
bind .l <Motion> {listbox_mouseover [.l nearest %y]}
|
| 65 |
+
bind .l <Leave> {listbox_mouseover -1}
|
| 66 |
+
|
| 67 |
+
proc listbox_click {sel} {
|
| 68 |
+
if {$sel ne ""} {
|
| 69 |
+
set ::O(iNode) [lindex $::O(listbox_captions) $sel 1]
|
| 70 |
+
view_node
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
proc listbox_mouseover {i} {
|
| 74 |
+
set oldid [lindex $::O(listbox_itemmap) $::O(listbox_highlight)]
|
| 75 |
+
.c itemconfigure $oldid -fill ""
|
| 76 |
+
|
| 77 |
+
.l selection clear 0 end
|
| 78 |
+
.status configure -text ""
|
| 79 |
+
if {$i>=0} {
|
| 80 |
+
set id [lindex $::O(listbox_itemmap) $i]
|
| 81 |
+
.c itemconfigure $id -fill grey
|
| 82 |
+
.c lower $id
|
| 83 |
+
set ::O(listbox_highlight) $i
|
| 84 |
+
.l selection set $i
|
| 85 |
+
.status configure -text [cell_report db $::O(zTab) $::O(iNode) $i]
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
grid configure .select -row 0 -column 0 -columnspan 2 -sticky nsew
|
| 90 |
+
grid configure .b -row 1 -column 0 -columnspan 2 -sticky nsew
|
| 91 |
+
grid configure .l -row 2 -column 0 -sticky nsew
|
| 92 |
+
grid configure .status -row 3 -column 0 -columnspan 3 -sticky nsew
|
| 93 |
+
|
| 94 |
+
grid configure .title -row 0 -column 2 -sticky nsew
|
| 95 |
+
grid configure .c -row 1 -column 2 -rowspan 2 -sticky nsew
|
| 96 |
+
grid configure .ls -row 2 -column 1 -sticky nsew
|
| 97 |
+
|
| 98 |
+
grid columnconfigure . 2 -weight 1
|
| 99 |
+
grid rowconfigure . 2 -weight 1
|
| 100 |
+
|
| 101 |
+
proc node_bbox {data} {
|
| 102 |
+
set xmin 0
|
| 103 |
+
set xmax 0
|
| 104 |
+
set ymin 0
|
| 105 |
+
set ymax 0
|
| 106 |
+
foreach {rowid xmin xmax ymin ymax} [lindex $data 0] break
|
| 107 |
+
foreach cell [lrange $data 1 end] {
|
| 108 |
+
foreach {rowid x1 x2 y1 y2} $cell break
|
| 109 |
+
if {$x1 < $xmin} {set xmin $x1}
|
| 110 |
+
if {$x2 > $xmax} {set xmax $x2}
|
| 111 |
+
if {$y1 < $ymin} {set ymin $y1}
|
| 112 |
+
if {$y2 > $ymax} {set ymax $y2}
|
| 113 |
+
}
|
| 114 |
+
list $xmin $xmax $ymin $ymax
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
proc view_node {} {
|
| 118 |
+
set iNode $::O(iNode)
|
| 119 |
+
set zTab $::O(zTab)
|
| 120 |
+
|
| 121 |
+
set data [rtree_node db $zTab $iNode 12]
|
| 122 |
+
set depth [rtree_nodedepth db $zTab $iNode]
|
| 123 |
+
|
| 124 |
+
.c delete all
|
| 125 |
+
set ::O(listbox_captions) [list]
|
| 126 |
+
set ::O(listbox_itemmap) [list]
|
| 127 |
+
set $::O(listbox_highlight) -1
|
| 128 |
+
|
| 129 |
+
.b configure -state normal
|
| 130 |
+
if {$iNode == 1} {.b configure -state disabled}
|
| 131 |
+
.title configure -text "Node $iNode: [cell_report db $zTab $iNode -1]"
|
| 132 |
+
|
| 133 |
+
foreach {xmin xmax ymin ymax} [node_bbox $data] break
|
| 134 |
+
set total_area 0.0
|
| 135 |
+
|
| 136 |
+
set xscale [expr {double([winfo width .c]-20)/($xmax-$xmin)}]
|
| 137 |
+
set yscale [expr {double([winfo height .c]-20)/($ymax-$ymin)}]
|
| 138 |
+
|
| 139 |
+
set xoff [expr {10.0 - $xmin*$xscale}]
|
| 140 |
+
set yoff [expr {10.0 - $ymin*$yscale}]
|
| 141 |
+
|
| 142 |
+
foreach cell $data {
|
| 143 |
+
foreach {rowid x1 x2 y1 y2} $cell break
|
| 144 |
+
set total_area [expr {$total_area + ($x2-$x1)*($y2-$y1)}]
|
| 145 |
+
set x1 [expr {$x1*$xscale + $xoff}]
|
| 146 |
+
set x2 [expr {$x2*$xscale + $xoff}]
|
| 147 |
+
set y1 [expr {$y1*$yscale + $yoff}]
|
| 148 |
+
set y2 [expr {$y2*$yscale + $yoff}]
|
| 149 |
+
|
| 150 |
+
set id [.c create rectangle $x1 $y1 $x2 $y2]
|
| 151 |
+
if {$depth>0} {
|
| 152 |
+
lappend ::O(listbox_captions) "Node $rowid"
|
| 153 |
+
lappend ::O(listbox_itemmap) $id
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
proc cell_report {db zTab iParent iCell} {
|
| 159 |
+
set data [rtree_node db $zTab $iParent 12]
|
| 160 |
+
set cell [lindex $data $iCell]
|
| 161 |
+
|
| 162 |
+
foreach {xmin xmax ymin ymax} [node_bbox $data] break
|
| 163 |
+
set total_area [expr ($xmax-$xmin)*($ymax-$ymin)]
|
| 164 |
+
|
| 165 |
+
if {$cell eq ""} {
|
| 166 |
+
set cell_area 0.0
|
| 167 |
+
foreach cell $data {
|
| 168 |
+
foreach {rowid x1 x2 y1 y2} $cell break
|
| 169 |
+
set cell_area [expr $cell_area+($x2-$x1)*($y2-$y1)]
|
| 170 |
+
}
|
| 171 |
+
set cell_area [expr $cell_area/[llength $data]]
|
| 172 |
+
set zReport [format "Size = %.1f x %.1f Average child area = %.1f%%" \
|
| 173 |
+
[expr $xmax-$xmin] [expr $ymax-$ymin] [expr 100.0*$cell_area/$total_area]\
|
| 174 |
+
]
|
| 175 |
+
append zReport " Sub-tree height: [rtree_nodedepth db $zTab $iParent]"
|
| 176 |
+
} else {
|
| 177 |
+
foreach {rowid x1 x2 y1 y2} $cell break
|
| 178 |
+
set cell_area [expr ($x2-$x1)*($y2-$y1)]
|
| 179 |
+
set zReport [format "Size = %.1f x %.1f Area = %.1f%%" \
|
| 180 |
+
[expr $x2-$x1] [expr $y2-$y1] [expr 100.0*$cell_area/$total_area]
|
| 181 |
+
]
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
return $zReport
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
view_node
|
| 188 |
+
bind .c <Configure> view_node
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/rtree/visual01.txt
ADDED
|
@@ -0,0 +1,602 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!sqlite3
|
| 2 |
+
#
|
| 3 |
+
# This is a visual test case for the geopoly virtual table.
|
| 4 |
+
#
|
| 5 |
+
# Run this script in the sqlite3 CLI, and redirect output into an
|
| 6 |
+
# HTML file. This display the HTML in a webbrowser.
|
| 7 |
+
#
|
| 8 |
+
|
| 9 |
+
/* Test data.
|
| 10 |
+
** Lots of shapes to be displayed over a 1000x800 canvas.
|
| 11 |
+
*/
|
| 12 |
+
CREATE TEMP TABLE basis(name TEXT, jshape TEXT);
|
| 13 |
+
INSERT INTO basis(name,jshape) VALUES
|
| 14 |
+
('box-20','[[0,0],[20,0],[20,20],[0,20],[0,0]]'),
|
| 15 |
+
('house-70','[[0,0],[50,0],[50,50],[25,70],[0,50],[0,0]]'),
|
| 16 |
+
('line-40','[[0,0],[40,0],[40,5],[0,5],[0,0]]'),
|
| 17 |
+
('line-80','[[0,0],[80,0],[80,7],[0,7],[0,0]]'),
|
| 18 |
+
('arrow-50','[[0,0],[25,25],[0,50],[15,25],[0,0]]'),
|
| 19 |
+
('triangle-30','[[0,0],[30,0],[15,30],[0,0]]'),
|
| 20 |
+
('angle-30','[[0,0],[30,0],[30,30],[26,30],[26,4],[0,4],[0,0]]'),
|
| 21 |
+
('star-10','[[1,0],[5,2],[9,0],[7,4],[10,8],[7,7],[5,10],[3,7],[0,8],[3,4],[1,0]]');
|
| 22 |
+
CREATE TEMP TABLE xform(A,B,C,D,clr);
|
| 23 |
+
INSERT INTO xform(A,B,clr) VALUES
|
| 24 |
+
(1,0,'black'),
|
| 25 |
+
(0.707,0.707,'blue'),
|
| 26 |
+
(0.5,0.866,'red'),
|
| 27 |
+
(-0.866,0.5,'green');
|
| 28 |
+
CREATE TEMP TABLE xyoff(id1,id2,xoff,yoff,PRIMARY KEY(id1,id2,xoff,yoff))
|
| 29 |
+
WITHOUT ROWID;
|
| 30 |
+
INSERT INTO xyoff VALUES(1,1,811,659);
|
| 31 |
+
INSERT INTO xyoff VALUES(1,1,235,550);
|
| 32 |
+
INSERT INTO xyoff VALUES(1,1,481,620);
|
| 33 |
+
INSERT INTO xyoff VALUES(1,1,106,494);
|
| 34 |
+
INSERT INTO xyoff VALUES(1,1,487,106);
|
| 35 |
+
INSERT INTO xyoff VALUES(1,1,817,595);
|
| 36 |
+
INSERT INTO xyoff VALUES(1,1,240,504);
|
| 37 |
+
INSERT INTO xyoff VALUES(1,1,806,457);
|
| 38 |
+
INSERT INTO xyoff VALUES(1,1,608,107);
|
| 39 |
+
INSERT INTO xyoff VALUES(1,1,768,662);
|
| 40 |
+
INSERT INTO xyoff VALUES(1,2,808,528);
|
| 41 |
+
INSERT INTO xyoff VALUES(1,2,768,528);
|
| 42 |
+
INSERT INTO xyoff VALUES(1,2,771,171);
|
| 43 |
+
INSERT INTO xyoff VALUES(1,2,275,671);
|
| 44 |
+
INSERT INTO xyoff VALUES(1,2,326,336);
|
| 45 |
+
INSERT INTO xyoff VALUES(1,2,690,688);
|
| 46 |
+
INSERT INTO xyoff VALUES(1,2,597,239);
|
| 47 |
+
INSERT INTO xyoff VALUES(1,2,317,528);
|
| 48 |
+
INSERT INTO xyoff VALUES(1,2,366,223);
|
| 49 |
+
INSERT INTO xyoff VALUES(1,2,621,154);
|
| 50 |
+
INSERT INTO xyoff VALUES(1,3,829,469);
|
| 51 |
+
INSERT INTO xyoff VALUES(1,3,794,322);
|
| 52 |
+
INSERT INTO xyoff VALUES(1,3,358,387);
|
| 53 |
+
INSERT INTO xyoff VALUES(1,3,184,444);
|
| 54 |
+
INSERT INTO xyoff VALUES(1,3,729,500);
|
| 55 |
+
INSERT INTO xyoff VALUES(1,3,333,523);
|
| 56 |
+
INSERT INTO xyoff VALUES(1,3,117,595);
|
| 57 |
+
INSERT INTO xyoff VALUES(1,3,496,201);
|
| 58 |
+
INSERT INTO xyoff VALUES(1,3,818,601);
|
| 59 |
+
INSERT INTO xyoff VALUES(1,3,541,343);
|
| 60 |
+
INSERT INTO xyoff VALUES(1,4,603,248);
|
| 61 |
+
INSERT INTO xyoff VALUES(1,4,761,649);
|
| 62 |
+
INSERT INTO xyoff VALUES(1,4,611,181);
|
| 63 |
+
INSERT INTO xyoff VALUES(1,4,607,233);
|
| 64 |
+
INSERT INTO xyoff VALUES(1,4,860,206);
|
| 65 |
+
INSERT INTO xyoff VALUES(1,4,310,231);
|
| 66 |
+
INSERT INTO xyoff VALUES(1,4,727,539);
|
| 67 |
+
INSERT INTO xyoff VALUES(1,4,660,661);
|
| 68 |
+
INSERT INTO xyoff VALUES(1,4,403,133);
|
| 69 |
+
INSERT INTO xyoff VALUES(1,4,619,331);
|
| 70 |
+
INSERT INTO xyoff VALUES(2,1,712,578);
|
| 71 |
+
INSERT INTO xyoff VALUES(2,1,567,313);
|
| 72 |
+
INSERT INTO xyoff VALUES(2,1,231,423);
|
| 73 |
+
INSERT INTO xyoff VALUES(2,1,490,175);
|
| 74 |
+
INSERT INTO xyoff VALUES(2,1,898,353);
|
| 75 |
+
INSERT INTO xyoff VALUES(2,1,589,483);
|
| 76 |
+
INSERT INTO xyoff VALUES(2,1,188,462);
|
| 77 |
+
INSERT INTO xyoff VALUES(2,1,720,106);
|
| 78 |
+
INSERT INTO xyoff VALUES(2,1,793,380);
|
| 79 |
+
INSERT INTO xyoff VALUES(2,1,154,396);
|
| 80 |
+
INSERT INTO xyoff VALUES(2,2,324,218);
|
| 81 |
+
INSERT INTO xyoff VALUES(2,2,120,327);
|
| 82 |
+
INSERT INTO xyoff VALUES(2,2,655,133);
|
| 83 |
+
INSERT INTO xyoff VALUES(2,2,516,603);
|
| 84 |
+
INSERT INTO xyoff VALUES(2,2,529,572);
|
| 85 |
+
INSERT INTO xyoff VALUES(2,2,481,212);
|
| 86 |
+
INSERT INTO xyoff VALUES(2,2,802,107);
|
| 87 |
+
INSERT INTO xyoff VALUES(2,2,234,509);
|
| 88 |
+
INSERT INTO xyoff VALUES(2,2,501,269);
|
| 89 |
+
INSERT INTO xyoff VALUES(2,2,349,553);
|
| 90 |
+
INSERT INTO xyoff VALUES(2,3,495,685);
|
| 91 |
+
INSERT INTO xyoff VALUES(2,3,897,372);
|
| 92 |
+
INSERT INTO xyoff VALUES(2,3,350,681);
|
| 93 |
+
INSERT INTO xyoff VALUES(2,3,832,257);
|
| 94 |
+
INSERT INTO xyoff VALUES(2,3,778,149);
|
| 95 |
+
INSERT INTO xyoff VALUES(2,3,683,426);
|
| 96 |
+
INSERT INTO xyoff VALUES(2,3,693,217);
|
| 97 |
+
INSERT INTO xyoff VALUES(2,3,746,317);
|
| 98 |
+
INSERT INTO xyoff VALUES(2,3,805,369);
|
| 99 |
+
INSERT INTO xyoff VALUES(2,3,336,585);
|
| 100 |
+
INSERT INTO xyoff VALUES(2,4,890,255);
|
| 101 |
+
INSERT INTO xyoff VALUES(2,4,556,565);
|
| 102 |
+
INSERT INTO xyoff VALUES(2,4,865,555);
|
| 103 |
+
INSERT INTO xyoff VALUES(2,4,230,293);
|
| 104 |
+
INSERT INTO xyoff VALUES(2,4,247,251);
|
| 105 |
+
INSERT INTO xyoff VALUES(2,4,730,563);
|
| 106 |
+
INSERT INTO xyoff VALUES(2,4,318,282);
|
| 107 |
+
INSERT INTO xyoff VALUES(2,4,220,431);
|
| 108 |
+
INSERT INTO xyoff VALUES(2,4,828,336);
|
| 109 |
+
INSERT INTO xyoff VALUES(2,4,278,525);
|
| 110 |
+
INSERT INTO xyoff VALUES(3,1,324,656);
|
| 111 |
+
INSERT INTO xyoff VALUES(3,1,625,362);
|
| 112 |
+
INSERT INTO xyoff VALUES(3,1,155,570);
|
| 113 |
+
INSERT INTO xyoff VALUES(3,1,267,433);
|
| 114 |
+
INSERT INTO xyoff VALUES(3,1,599,121);
|
| 115 |
+
INSERT INTO xyoff VALUES(3,1,873,498);
|
| 116 |
+
INSERT INTO xyoff VALUES(3,1,789,520);
|
| 117 |
+
INSERT INTO xyoff VALUES(3,1,656,378);
|
| 118 |
+
INSERT INTO xyoff VALUES(3,1,831,601);
|
| 119 |
+
INSERT INTO xyoff VALUES(3,1,256,471);
|
| 120 |
+
INSERT INTO xyoff VALUES(3,2,332,258);
|
| 121 |
+
INSERT INTO xyoff VALUES(3,2,305,463);
|
| 122 |
+
INSERT INTO xyoff VALUES(3,2,796,341);
|
| 123 |
+
INSERT INTO xyoff VALUES(3,2,830,229);
|
| 124 |
+
INSERT INTO xyoff VALUES(3,2,413,271);
|
| 125 |
+
INSERT INTO xyoff VALUES(3,2,269,140);
|
| 126 |
+
INSERT INTO xyoff VALUES(3,2,628,441);
|
| 127 |
+
INSERT INTO xyoff VALUES(3,2,747,643);
|
| 128 |
+
INSERT INTO xyoff VALUES(3,2,584,435);
|
| 129 |
+
INSERT INTO xyoff VALUES(3,2,784,314);
|
| 130 |
+
INSERT INTO xyoff VALUES(3,3,722,233);
|
| 131 |
+
INSERT INTO xyoff VALUES(3,3,815,421);
|
| 132 |
+
INSERT INTO xyoff VALUES(3,3,401,267);
|
| 133 |
+
INSERT INTO xyoff VALUES(3,3,451,650);
|
| 134 |
+
INSERT INTO xyoff VALUES(3,3,329,485);
|
| 135 |
+
INSERT INTO xyoff VALUES(3,3,878,370);
|
| 136 |
+
INSERT INTO xyoff VALUES(3,3,162,616);
|
| 137 |
+
INSERT INTO xyoff VALUES(3,3,844,183);
|
| 138 |
+
INSERT INTO xyoff VALUES(3,3,161,216);
|
| 139 |
+
INSERT INTO xyoff VALUES(3,3,176,676);
|
| 140 |
+
INSERT INTO xyoff VALUES(3,4,780,128);
|
| 141 |
+
INSERT INTO xyoff VALUES(3,4,566,121);
|
| 142 |
+
INSERT INTO xyoff VALUES(3,4,646,120);
|
| 143 |
+
INSERT INTO xyoff VALUES(3,4,223,557);
|
| 144 |
+
INSERT INTO xyoff VALUES(3,4,251,117);
|
| 145 |
+
INSERT INTO xyoff VALUES(3,4,139,209);
|
| 146 |
+
INSERT INTO xyoff VALUES(3,4,813,597);
|
| 147 |
+
INSERT INTO xyoff VALUES(3,4,454,538);
|
| 148 |
+
INSERT INTO xyoff VALUES(3,4,616,198);
|
| 149 |
+
INSERT INTO xyoff VALUES(3,4,210,159);
|
| 150 |
+
INSERT INTO xyoff VALUES(4,1,208,415);
|
| 151 |
+
INSERT INTO xyoff VALUES(4,1,326,665);
|
| 152 |
+
INSERT INTO xyoff VALUES(4,1,612,133);
|
| 153 |
+
INSERT INTO xyoff VALUES(4,1,537,513);
|
| 154 |
+
INSERT INTO xyoff VALUES(4,1,638,438);
|
| 155 |
+
INSERT INTO xyoff VALUES(4,1,808,269);
|
| 156 |
+
INSERT INTO xyoff VALUES(4,1,552,121);
|
| 157 |
+
INSERT INTO xyoff VALUES(4,1,100,189);
|
| 158 |
+
INSERT INTO xyoff VALUES(4,1,643,664);
|
| 159 |
+
INSERT INTO xyoff VALUES(4,1,726,378);
|
| 160 |
+
INSERT INTO xyoff VALUES(4,2,478,409);
|
| 161 |
+
INSERT INTO xyoff VALUES(4,2,497,507);
|
| 162 |
+
INSERT INTO xyoff VALUES(4,2,233,148);
|
| 163 |
+
INSERT INTO xyoff VALUES(4,2,587,237);
|
| 164 |
+
INSERT INTO xyoff VALUES(4,2,604,166);
|
| 165 |
+
INSERT INTO xyoff VALUES(4,2,165,455);
|
| 166 |
+
INSERT INTO xyoff VALUES(4,2,320,258);
|
| 167 |
+
INSERT INTO xyoff VALUES(4,2,353,496);
|
| 168 |
+
INSERT INTO xyoff VALUES(4,2,347,495);
|
| 169 |
+
INSERT INTO xyoff VALUES(4,2,166,622);
|
| 170 |
+
INSERT INTO xyoff VALUES(4,3,461,332);
|
| 171 |
+
INSERT INTO xyoff VALUES(4,3,685,278);
|
| 172 |
+
INSERT INTO xyoff VALUES(4,3,427,594);
|
| 173 |
+
INSERT INTO xyoff VALUES(4,3,467,346);
|
| 174 |
+
INSERT INTO xyoff VALUES(4,3,125,548);
|
| 175 |
+
INSERT INTO xyoff VALUES(4,3,597,680);
|
| 176 |
+
INSERT INTO xyoff VALUES(4,3,820,445);
|
| 177 |
+
INSERT INTO xyoff VALUES(4,3,144,330);
|
| 178 |
+
INSERT INTO xyoff VALUES(4,3,557,434);
|
| 179 |
+
INSERT INTO xyoff VALUES(4,3,254,315);
|
| 180 |
+
INSERT INTO xyoff VALUES(4,4,157,339);
|
| 181 |
+
INSERT INTO xyoff VALUES(4,4,249,220);
|
| 182 |
+
INSERT INTO xyoff VALUES(4,4,391,323);
|
| 183 |
+
INSERT INTO xyoff VALUES(4,4,589,429);
|
| 184 |
+
INSERT INTO xyoff VALUES(4,4,859,592);
|
| 185 |
+
INSERT INTO xyoff VALUES(4,4,337,680);
|
| 186 |
+
INSERT INTO xyoff VALUES(4,4,410,288);
|
| 187 |
+
INSERT INTO xyoff VALUES(4,4,636,596);
|
| 188 |
+
INSERT INTO xyoff VALUES(4,4,734,433);
|
| 189 |
+
INSERT INTO xyoff VALUES(4,4,559,549);
|
| 190 |
+
INSERT INTO xyoff VALUES(5,1,549,607);
|
| 191 |
+
INSERT INTO xyoff VALUES(5,1,584,498);
|
| 192 |
+
INSERT INTO xyoff VALUES(5,1,699,116);
|
| 193 |
+
INSERT INTO xyoff VALUES(5,1,525,524);
|
| 194 |
+
INSERT INTO xyoff VALUES(5,1,304,667);
|
| 195 |
+
INSERT INTO xyoff VALUES(5,1,302,232);
|
| 196 |
+
INSERT INTO xyoff VALUES(5,1,403,149);
|
| 197 |
+
INSERT INTO xyoff VALUES(5,1,824,403);
|
| 198 |
+
INSERT INTO xyoff VALUES(5,1,697,203);
|
| 199 |
+
INSERT INTO xyoff VALUES(5,1,293,689);
|
| 200 |
+
INSERT INTO xyoff VALUES(5,2,199,275);
|
| 201 |
+
INSERT INTO xyoff VALUES(5,2,395,393);
|
| 202 |
+
INSERT INTO xyoff VALUES(5,2,657,642);
|
| 203 |
+
INSERT INTO xyoff VALUES(5,2,200,655);
|
| 204 |
+
INSERT INTO xyoff VALUES(5,2,882,234);
|
| 205 |
+
INSERT INTO xyoff VALUES(5,2,483,565);
|
| 206 |
+
INSERT INTO xyoff VALUES(5,2,755,640);
|
| 207 |
+
INSERT INTO xyoff VALUES(5,2,810,305);
|
| 208 |
+
INSERT INTO xyoff VALUES(5,2,731,655);
|
| 209 |
+
INSERT INTO xyoff VALUES(5,2,466,690);
|
| 210 |
+
INSERT INTO xyoff VALUES(5,3,563,584);
|
| 211 |
+
INSERT INTO xyoff VALUES(5,3,491,117);
|
| 212 |
+
INSERT INTO xyoff VALUES(5,3,779,292);
|
| 213 |
+
INSERT INTO xyoff VALUES(5,3,375,637);
|
| 214 |
+
INSERT INTO xyoff VALUES(5,3,253,553);
|
| 215 |
+
INSERT INTO xyoff VALUES(5,3,797,514);
|
| 216 |
+
INSERT INTO xyoff VALUES(5,3,229,480);
|
| 217 |
+
INSERT INTO xyoff VALUES(5,3,257,194);
|
| 218 |
+
INSERT INTO xyoff VALUES(5,3,449,555);
|
| 219 |
+
INSERT INTO xyoff VALUES(5,3,849,630);
|
| 220 |
+
INSERT INTO xyoff VALUES(5,4,329,286);
|
| 221 |
+
INSERT INTO xyoff VALUES(5,4,640,197);
|
| 222 |
+
INSERT INTO xyoff VALUES(5,4,104,150);
|
| 223 |
+
INSERT INTO xyoff VALUES(5,4,438,272);
|
| 224 |
+
INSERT INTO xyoff VALUES(5,4,773,226);
|
| 225 |
+
INSERT INTO xyoff VALUES(5,4,441,650);
|
| 226 |
+
INSERT INTO xyoff VALUES(5,4,242,340);
|
| 227 |
+
INSERT INTO xyoff VALUES(5,4,301,435);
|
| 228 |
+
INSERT INTO xyoff VALUES(5,4,171,397);
|
| 229 |
+
INSERT INTO xyoff VALUES(5,4,541,619);
|
| 230 |
+
INSERT INTO xyoff VALUES(6,1,651,301);
|
| 231 |
+
INSERT INTO xyoff VALUES(6,1,637,137);
|
| 232 |
+
INSERT INTO xyoff VALUES(6,1,765,643);
|
| 233 |
+
INSERT INTO xyoff VALUES(6,1,173,296);
|
| 234 |
+
INSERT INTO xyoff VALUES(6,1,263,192);
|
| 235 |
+
INSERT INTO xyoff VALUES(6,1,791,302);
|
| 236 |
+
INSERT INTO xyoff VALUES(6,1,860,601);
|
| 237 |
+
INSERT INTO xyoff VALUES(6,1,780,445);
|
| 238 |
+
INSERT INTO xyoff VALUES(6,1,462,214);
|
| 239 |
+
INSERT INTO xyoff VALUES(6,1,802,207);
|
| 240 |
+
INSERT INTO xyoff VALUES(6,2,811,685);
|
| 241 |
+
INSERT INTO xyoff VALUES(6,2,533,531);
|
| 242 |
+
INSERT INTO xyoff VALUES(6,2,390,614);
|
| 243 |
+
INSERT INTO xyoff VALUES(6,2,260,580);
|
| 244 |
+
INSERT INTO xyoff VALUES(6,2,116,377);
|
| 245 |
+
INSERT INTO xyoff VALUES(6,2,860,458);
|
| 246 |
+
INSERT INTO xyoff VALUES(6,2,438,590);
|
| 247 |
+
INSERT INTO xyoff VALUES(6,2,604,562);
|
| 248 |
+
INSERT INTO xyoff VALUES(6,2,241,242);
|
| 249 |
+
INSERT INTO xyoff VALUES(6,2,667,298);
|
| 250 |
+
INSERT INTO xyoff VALUES(6,3,787,698);
|
| 251 |
+
INSERT INTO xyoff VALUES(6,3,868,521);
|
| 252 |
+
INSERT INTO xyoff VALUES(6,3,412,587);
|
| 253 |
+
INSERT INTO xyoff VALUES(6,3,640,131);
|
| 254 |
+
INSERT INTO xyoff VALUES(6,3,748,410);
|
| 255 |
+
INSERT INTO xyoff VALUES(6,3,257,244);
|
| 256 |
+
INSERT INTO xyoff VALUES(6,3,411,195);
|
| 257 |
+
INSERT INTO xyoff VALUES(6,3,464,356);
|
| 258 |
+
INSERT INTO xyoff VALUES(6,3,157,339);
|
| 259 |
+
INSERT INTO xyoff VALUES(6,3,434,505);
|
| 260 |
+
INSERT INTO xyoff VALUES(6,4,480,671);
|
| 261 |
+
INSERT INTO xyoff VALUES(6,4,519,228);
|
| 262 |
+
INSERT INTO xyoff VALUES(6,4,404,513);
|
| 263 |
+
INSERT INTO xyoff VALUES(6,4,120,538);
|
| 264 |
+
INSERT INTO xyoff VALUES(6,4,403,663);
|
| 265 |
+
INSERT INTO xyoff VALUES(6,4,477,677);
|
| 266 |
+
INSERT INTO xyoff VALUES(6,4,690,154);
|
| 267 |
+
INSERT INTO xyoff VALUES(6,4,606,498);
|
| 268 |
+
INSERT INTO xyoff VALUES(6,4,430,665);
|
| 269 |
+
INSERT INTO xyoff VALUES(6,4,499,273);
|
| 270 |
+
INSERT INTO xyoff VALUES(7,1,118,526);
|
| 271 |
+
INSERT INTO xyoff VALUES(7,1,817,522);
|
| 272 |
+
INSERT INTO xyoff VALUES(7,1,388,638);
|
| 273 |
+
INSERT INTO xyoff VALUES(7,1,181,265);
|
| 274 |
+
INSERT INTO xyoff VALUES(7,1,442,332);
|
| 275 |
+
INSERT INTO xyoff VALUES(7,1,475,282);
|
| 276 |
+
INSERT INTO xyoff VALUES(7,1,722,633);
|
| 277 |
+
INSERT INTO xyoff VALUES(7,1,104,394);
|
| 278 |
+
INSERT INTO xyoff VALUES(7,1,631,262);
|
| 279 |
+
INSERT INTO xyoff VALUES(7,1,372,392);
|
| 280 |
+
INSERT INTO xyoff VALUES(7,2,600,413);
|
| 281 |
+
INSERT INTO xyoff VALUES(7,2,386,223);
|
| 282 |
+
INSERT INTO xyoff VALUES(7,2,839,174);
|
| 283 |
+
INSERT INTO xyoff VALUES(7,2,293,410);
|
| 284 |
+
INSERT INTO xyoff VALUES(7,2,281,391);
|
| 285 |
+
INSERT INTO xyoff VALUES(7,2,859,387);
|
| 286 |
+
INSERT INTO xyoff VALUES(7,2,478,347);
|
| 287 |
+
INSERT INTO xyoff VALUES(7,2,646,690);
|
| 288 |
+
INSERT INTO xyoff VALUES(7,2,713,234);
|
| 289 |
+
INSERT INTO xyoff VALUES(7,2,199,588);
|
| 290 |
+
INSERT INTO xyoff VALUES(7,3,389,256);
|
| 291 |
+
INSERT INTO xyoff VALUES(7,3,349,542);
|
| 292 |
+
INSERT INTO xyoff VALUES(7,3,363,345);
|
| 293 |
+
INSERT INTO xyoff VALUES(7,3,751,302);
|
| 294 |
+
INSERT INTO xyoff VALUES(7,3,423,386);
|
| 295 |
+
INSERT INTO xyoff VALUES(7,3,267,444);
|
| 296 |
+
INSERT INTO xyoff VALUES(7,3,243,182);
|
| 297 |
+
INSERT INTO xyoff VALUES(7,3,453,658);
|
| 298 |
+
INSERT INTO xyoff VALUES(7,3,126,345);
|
| 299 |
+
INSERT INTO xyoff VALUES(7,3,120,472);
|
| 300 |
+
INSERT INTO xyoff VALUES(7,4,359,654);
|
| 301 |
+
INSERT INTO xyoff VALUES(7,4,339,516);
|
| 302 |
+
INSERT INTO xyoff VALUES(7,4,710,452);
|
| 303 |
+
INSERT INTO xyoff VALUES(7,4,810,560);
|
| 304 |
+
INSERT INTO xyoff VALUES(7,4,644,692);
|
| 305 |
+
INSERT INTO xyoff VALUES(7,4,826,327);
|
| 306 |
+
INSERT INTO xyoff VALUES(7,4,465,462);
|
| 307 |
+
INSERT INTO xyoff VALUES(7,4,310,456);
|
| 308 |
+
INSERT INTO xyoff VALUES(7,4,577,613);
|
| 309 |
+
INSERT INTO xyoff VALUES(7,4,502,555);
|
| 310 |
+
INSERT INTO xyoff VALUES(8,1,601,620);
|
| 311 |
+
INSERT INTO xyoff VALUES(8,1,372,683);
|
| 312 |
+
INSERT INTO xyoff VALUES(8,1,758,399);
|
| 313 |
+
INSERT INTO xyoff VALUES(8,1,485,552);
|
| 314 |
+
INSERT INTO xyoff VALUES(8,1,159,563);
|
| 315 |
+
INSERT INTO xyoff VALUES(8,1,536,303);
|
| 316 |
+
INSERT INTO xyoff VALUES(8,1,122,263);
|
| 317 |
+
INSERT INTO xyoff VALUES(8,1,836,435);
|
| 318 |
+
INSERT INTO xyoff VALUES(8,1,544,146);
|
| 319 |
+
INSERT INTO xyoff VALUES(8,1,270,277);
|
| 320 |
+
INSERT INTO xyoff VALUES(8,2,849,281);
|
| 321 |
+
INSERT INTO xyoff VALUES(8,2,563,242);
|
| 322 |
+
INSERT INTO xyoff VALUES(8,2,704,463);
|
| 323 |
+
INSERT INTO xyoff VALUES(8,2,102,165);
|
| 324 |
+
INSERT INTO xyoff VALUES(8,2,797,524);
|
| 325 |
+
INSERT INTO xyoff VALUES(8,2,612,426);
|
| 326 |
+
INSERT INTO xyoff VALUES(8,2,345,372);
|
| 327 |
+
INSERT INTO xyoff VALUES(8,2,820,376);
|
| 328 |
+
INSERT INTO xyoff VALUES(8,2,789,156);
|
| 329 |
+
INSERT INTO xyoff VALUES(8,2,321,466);
|
| 330 |
+
INSERT INTO xyoff VALUES(8,3,150,332);
|
| 331 |
+
INSERT INTO xyoff VALUES(8,3,136,152);
|
| 332 |
+
INSERT INTO xyoff VALUES(8,3,468,528);
|
| 333 |
+
INSERT INTO xyoff VALUES(8,3,409,192);
|
| 334 |
+
INSERT INTO xyoff VALUES(8,3,820,216);
|
| 335 |
+
INSERT INTO xyoff VALUES(8,3,847,249);
|
| 336 |
+
INSERT INTO xyoff VALUES(8,3,801,267);
|
| 337 |
+
INSERT INTO xyoff VALUES(8,3,181,670);
|
| 338 |
+
INSERT INTO xyoff VALUES(8,3,398,563);
|
| 339 |
+
INSERT INTO xyoff VALUES(8,3,439,576);
|
| 340 |
+
INSERT INTO xyoff VALUES(8,4,123,309);
|
| 341 |
+
INSERT INTO xyoff VALUES(8,4,190,496);
|
| 342 |
+
INSERT INTO xyoff VALUES(8,4,571,531);
|
| 343 |
+
INSERT INTO xyoff VALUES(8,4,290,255);
|
| 344 |
+
INSERT INTO xyoff VALUES(8,4,244,412);
|
| 345 |
+
INSERT INTO xyoff VALUES(8,4,264,596);
|
| 346 |
+
INSERT INTO xyoff VALUES(8,4,253,420);
|
| 347 |
+
INSERT INTO xyoff VALUES(8,4,847,536);
|
| 348 |
+
INSERT INTO xyoff VALUES(8,4,120,288);
|
| 349 |
+
INSERT INTO xyoff VALUES(8,4,331,639);
|
| 350 |
+
|
| 351 |
+
/* Create the geopoly object from test data above */
|
| 352 |
+
CREATE VIRTUAL TABLE geo1 USING geopoly(type,clr);
|
| 353 |
+
INSERT INTO geo1(_shape,type,clr)
|
| 354 |
+
SELECT geopoly_xform(jshape,A,B,-B,A,xoff,yoff), basis.name, xform.clr
|
| 355 |
+
FROM basis, xform, xyoff
|
| 356 |
+
WHERE xyoff.id1=basis.rowid AND xyoff.id2=xform.rowid;
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
/* Query polygon */
|
| 360 |
+
CREATE TEMP TABLE querypoly(poly JSON, clr TEXT);
|
| 361 |
+
INSERT INTO querypoly(clr, poly) VALUES
|
| 362 |
+
('orange', '[[300,300],[400,350],[500,250],[480,500],[400,480],[300,550],[280,450],[320,400],[280,350],[300,300]]');
|
| 363 |
+
|
| 364 |
+
/* Generate the HTML */
|
| 365 |
+
.print '<html>'
|
| 366 |
+
.print '<h1>Everything</h1>'
|
| 367 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 368 |
+
SELECT geopoly_svg(_shape,
|
| 369 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',clr)
|
| 370 |
+
)
|
| 371 |
+
FROM geo1;
|
| 372 |
+
SELECT geopoly_svg(poly,
|
| 373 |
+
printf('style="fill:%s;fill-opacity:0.5;"',clr)
|
| 374 |
+
)
|
| 375 |
+
FROM querypoly;
|
| 376 |
+
.print '</svg>'
|
| 377 |
+
|
| 378 |
+
.print '<h1>Overlap Query</h1>'
|
| 379 |
+
.print '<pre>'
|
| 380 |
+
.print 'SELECT *'
|
| 381 |
+
.print ' FROM geo1, querypoly'
|
| 382 |
+
.print ' WHERE geopoly_overlap(_shape, poly);'
|
| 383 |
+
.print
|
| 384 |
+
EXPLAIN QUERY PLAN
|
| 385 |
+
SELECT geopoly_svg(_shape,
|
| 386 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 387 |
+
)
|
| 388 |
+
FROM geo1, querypoly
|
| 389 |
+
WHERE geopoly_overlap(_shape, poly);
|
| 390 |
+
.print '</pre>'
|
| 391 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 392 |
+
SELECT geopoly_svg(_shape,
|
| 393 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 394 |
+
)
|
| 395 |
+
FROM geo1, querypoly
|
| 396 |
+
WHERE geopoly_overlap(_shape, poly);
|
| 397 |
+
SELECT geopoly_svg(poly,
|
| 398 |
+
printf('style="fill:%s;fill-opacity:0.5;"',clr)
|
| 399 |
+
)
|
| 400 |
+
FROM querypoly;
|
| 401 |
+
.print '</svg>'
|
| 402 |
+
|
| 403 |
+
.print '<h1>Overlap Query And Result Bounding Box</h1>'
|
| 404 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 405 |
+
SELECT geopoly_svg(_shape,
|
| 406 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 407 |
+
)
|
| 408 |
+
FROM geo1, querypoly
|
| 409 |
+
WHERE geopoly_overlap(_shape, poly);
|
| 410 |
+
SELECT geopoly_svg(geopoly_bbox(poly),
|
| 411 |
+
'style="fill:none;stroke:black;stroke-width:3"'
|
| 412 |
+
)
|
| 413 |
+
FROM querypoly;
|
| 414 |
+
SELECT geopoly_svg(poly,
|
| 415 |
+
printf('style="fill:%s;fill-opacity:0.5;"',clr)
|
| 416 |
+
)
|
| 417 |
+
FROM querypoly;
|
| 418 |
+
SELECT geopoly_svg(geopoly_group_bbox(_shape),
|
| 419 |
+
'style="fill:none;stroke:red;stroke-width:3"'
|
| 420 |
+
)
|
| 421 |
+
FROM geo1, querypoly
|
| 422 |
+
WHERE geopoly_overlap(_shape, poly);
|
| 423 |
+
.print '</svg>'
|
| 424 |
+
|
| 425 |
+
.print '<h1>Bounding-Box Overlap Query</h1>'
|
| 426 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 427 |
+
SELECT geopoly_svg(_shape,
|
| 428 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 429 |
+
),
|
| 430 |
+
geopoly_svg(geopoly_bbox(_shape),
|
| 431 |
+
'style="fill:none;stroke:black;stroke-width:1"'
|
| 432 |
+
)
|
| 433 |
+
FROM geo1, querypoly
|
| 434 |
+
WHERE geopoly_overlap(geopoly_bbox(_shape), geopoly_bbox(poly));
|
| 435 |
+
SELECT geopoly_svg(poly,
|
| 436 |
+
printf('style="fill:%s;fill-opacity:0.5;"',clr)
|
| 437 |
+
)
|
| 438 |
+
FROM querypoly;
|
| 439 |
+
SELECT geopoly_svg(geopoly_bbox(poly),
|
| 440 |
+
'style="fill:none;stroke:black;stroke-width:3"'
|
| 441 |
+
)
|
| 442 |
+
FROM querypoly;
|
| 443 |
+
.print '</svg>'
|
| 444 |
+
|
| 445 |
+
.print '<h1>Within Query</h1>'
|
| 446 |
+
.print '<pre>'
|
| 447 |
+
.print 'SELECT *'
|
| 448 |
+
.print ' FROM geo1, querypoly'
|
| 449 |
+
.print ' WHERE geopoly_within(_shape, poly);'
|
| 450 |
+
.print
|
| 451 |
+
EXPLAIN QUERY PLAN
|
| 452 |
+
SELECT geopoly_svg(_shape,
|
| 453 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 454 |
+
)
|
| 455 |
+
FROM geo1, querypoly
|
| 456 |
+
WHERE geopoly_within(_shape, poly);
|
| 457 |
+
.print '</pre>'
|
| 458 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 459 |
+
SELECT geopoly_svg(_shape,
|
| 460 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 461 |
+
)
|
| 462 |
+
FROM geo1, querypoly
|
| 463 |
+
WHERE geopoly_within(_shape, poly);
|
| 464 |
+
SELECT geopoly_svg(poly,
|
| 465 |
+
printf('style="fill:%s;fill-opacity:0.5;"',clr)
|
| 466 |
+
)
|
| 467 |
+
FROM querypoly;
|
| 468 |
+
.print '</svg>'
|
| 469 |
+
|
| 470 |
+
.print '<h1>Bounding-Box WITHIN Query</h1>'
|
| 471 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 472 |
+
SELECT geopoly_svg(_shape,
|
| 473 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 474 |
+
),
|
| 475 |
+
geopoly_svg(geopoly_bbox(_shape),
|
| 476 |
+
'style="fill:none;stroke:black;stroke-width:1"'
|
| 477 |
+
)
|
| 478 |
+
FROM geo1, querypoly
|
| 479 |
+
WHERE geopoly_within(geopoly_bbox(_shape), geopoly_bbox(poly));
|
| 480 |
+
SELECT geopoly_svg(poly,
|
| 481 |
+
printf('style="fill:%s;fill-opacity:0.5;"',clr)
|
| 482 |
+
)
|
| 483 |
+
FROM querypoly;
|
| 484 |
+
SELECT geopoly_svg(geopoly_bbox(poly),
|
| 485 |
+
'style="fill:none;stroke:black;stroke-width:3"'
|
| 486 |
+
)
|
| 487 |
+
FROM querypoly;
|
| 488 |
+
.print '</svg>'
|
| 489 |
+
|
| 490 |
+
.print '<h1>Not Overlap Query</h1>'
|
| 491 |
+
.print '<pre>'
|
| 492 |
+
.print 'SELECT *'
|
| 493 |
+
.print ' FROM geo1, querypoly'
|
| 494 |
+
.print ' WHERE NOT geopoly_overlap(_shape, poly);'
|
| 495 |
+
.print
|
| 496 |
+
EXPLAIN QUERY PLAN
|
| 497 |
+
SELECT geopoly_svg(_shape,
|
| 498 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 499 |
+
)
|
| 500 |
+
FROM geo1, querypoly
|
| 501 |
+
WHERE NOT geopoly_overlap(_shape, poly);
|
| 502 |
+
.print '</pre>'
|
| 503 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 504 |
+
SELECT geopoly_svg(_shape,
|
| 505 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 506 |
+
)
|
| 507 |
+
FROM geo1, querypoly
|
| 508 |
+
WHERE NOT geopoly_overlap(_shape, poly);
|
| 509 |
+
SELECT geopoly_svg(poly,
|
| 510 |
+
printf('style="fill:%s;fill-opacity:0.5;"',clr)
|
| 511 |
+
)
|
| 512 |
+
FROM querypoly;
|
| 513 |
+
.print '</svg>'
|
| 514 |
+
|
| 515 |
+
.print '<h1>Not Within Query</h1>'
|
| 516 |
+
.print '<pre>'
|
| 517 |
+
.print 'SELECT *'
|
| 518 |
+
.print ' FROM geo1, querypoly'
|
| 519 |
+
.print ' WHERE NOT geopoly_within(_shape, poly);'
|
| 520 |
+
.print
|
| 521 |
+
EXPLAIN QUERY PLAN
|
| 522 |
+
SELECT geopoly_svg(_shape,
|
| 523 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 524 |
+
)
|
| 525 |
+
FROM geo1, querypoly
|
| 526 |
+
WHERE NOT geopoly_within(_shape, poly);
|
| 527 |
+
.print '</pre>'
|
| 528 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 529 |
+
SELECT geopoly_svg(_shape,
|
| 530 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 531 |
+
)
|
| 532 |
+
FROM geo1, querypoly
|
| 533 |
+
WHERE NOT geopoly_within(_shape, poly);
|
| 534 |
+
SELECT geopoly_svg(poly,
|
| 535 |
+
printf('style="fill:%s;fill-opacity:0.5;"',clr)
|
| 536 |
+
)
|
| 537 |
+
FROM querypoly;
|
| 538 |
+
.print '</svg>'
|
| 539 |
+
|
| 540 |
+
.print '<h1>Color-Change For Overlapping Elements</h1>'
|
| 541 |
+
BEGIN;
|
| 542 |
+
UPDATE geo1
|
| 543 |
+
SET clr=CASE WHEN rowid IN (SELECT geo1.rowid FROM geo1, querypoly
|
| 544 |
+
WHERE geopoly_overlap(_shape,poly))
|
| 545 |
+
THEN 'red' ELSE 'blue' END;
|
| 546 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 547 |
+
SELECT geopoly_svg(_shape,
|
| 548 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 549 |
+
)
|
| 550 |
+
FROM geo1;
|
| 551 |
+
SELECT geopoly_svg(poly,'style="fill:none;stroke:black;stroke-width:2"')
|
| 552 |
+
FROM querypoly;
|
| 553 |
+
ROLLBACK;
|
| 554 |
+
.print '</svg>'
|
| 555 |
+
|
| 556 |
+
.print '<h1>Color-Change And Move Overlapping Elements</h1>'
|
| 557 |
+
BEGIN;
|
| 558 |
+
UPDATE geo1
|
| 559 |
+
SET clr=CASE WHEN rowid IN (SELECT geo1.rowid FROM geo1, querypoly
|
| 560 |
+
WHERE geopoly_overlap(_shape,poly))
|
| 561 |
+
THEN 'red' ELSE '#76ccff' END;
|
| 562 |
+
UPDATE geo1
|
| 563 |
+
SET _shape=geopoly_xform(_shape,1,0,0,1,300,0)
|
| 564 |
+
WHERE geopoly_overlap(_shape,(SELECT poly FROM querypoly));
|
| 565 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 566 |
+
SELECT geopoly_svg(_shape,
|
| 567 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 568 |
+
)
|
| 569 |
+
FROM geo1;
|
| 570 |
+
SELECT geopoly_svg(poly,'style="fill:none;stroke:black;stroke-width:2"')
|
| 571 |
+
FROM querypoly;
|
| 572 |
+
--ROLLBACK;
|
| 573 |
+
.print '</svg>'
|
| 574 |
+
|
| 575 |
+
|
| 576 |
+
.print '<h1>Overlap With Translated Query Polygon</h1>'
|
| 577 |
+
UPDATE querypoly SET poly=geopoly_xform(poly,1,0,0,1,300,0);
|
| 578 |
+
.print '<svg width="1000" height="800" style="border:1px solid black">'
|
| 579 |
+
SELECT geopoly_svg(_shape,
|
| 580 |
+
printf('style="fill:none;stroke:%s;stroke-width:1"',geo1.clr)
|
| 581 |
+
)
|
| 582 |
+
FROM geo1
|
| 583 |
+
WHERE geopoly_overlap(_shape,(SELECT poly FROM querypoly));
|
| 584 |
+
SELECT geopoly_svg(poly,'style="fill:none;stroke:black;stroke-width:2"')
|
| 585 |
+
FROM querypoly;
|
| 586 |
+
ROLLBACK;
|
| 587 |
+
.print '</svg>'
|
| 588 |
+
|
| 589 |
+
.print '<h1>Regular Polygons</h1>'
|
| 590 |
+
.print '<svg width="1000" height="200" style="border:1px solid black">'
|
| 591 |
+
SELECT geopoly_svg(geopoly_regular(100,100,40,3),'style="fill:none;stroke:red;stroke-width:1"');
|
| 592 |
+
SELECT geopoly_svg(geopoly_regular(200,100,40,4),'style="fill:none;stroke:orange;stroke-width:1"');
|
| 593 |
+
SELECT geopoly_svg(geopoly_regular(300,100,40,5),'style="fill:none;stroke:green;stroke-width:1"');
|
| 594 |
+
SELECT geopoly_svg(geopoly_regular(400,100,40,6),'style="fill:none;stroke:blue;stroke-width:1"');
|
| 595 |
+
SELECT geopoly_svg(geopoly_regular(500,100,40,7),'style="fill:none;stroke:purple;stroke-width:1"');
|
| 596 |
+
SELECT geopoly_svg(geopoly_regular(600,100,40,8),'style="fill:none;stroke:red;stroke-width:1"');
|
| 597 |
+
SELECT geopoly_svg(geopoly_regular(700,100,40,10),'style="fill:none;stroke:orange;stroke-width:1"');
|
| 598 |
+
SELECT geopoly_svg(geopoly_regular(800,100,40,20),'style="fill:none;stroke:green;stroke-width:1"');
|
| 599 |
+
SELECT geopoly_svg(geopoly_regular(900,100,40,30),'style="fill:none;stroke:blue;stroke-width:1"');
|
| 600 |
+
.print '</svg>'
|
| 601 |
+
|
| 602 |
+
.print '</html>'
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/wasm/api/sqlite3-wasm.c
ADDED
|
@@ -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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
** This file requires access to sqlite3.c static state in order to
|
| 3 |
+
** implement certain WASM-specific features, and thus directly
|
| 4 |
+
** includes that file. Unlike the rest of sqlite3.c, this file
|
| 5 |
+
** requires compiling with -std=c99 (or equivalent, or a later C
|
| 6 |
+
** version) because it makes use of features not available in C89.
|
| 7 |
+
**
|
| 8 |
+
** At its simplest, to build sqlite3.wasm either place this file
|
| 9 |
+
** in the same directory as sqlite3.c/h before compilation or use the
|
| 10 |
+
** -I/path flag to tell the compiler where to find both of those
|
| 11 |
+
** files, then compile this file. For example:
|
| 12 |
+
**
|
| 13 |
+
** emcc -o sqlite3.wasm ... -I/path/to/sqlite3-c-and-h sqlite3-wasm.c
|
| 14 |
+
*/
|
| 15 |
+
#define SQLITE_WASM
|
| 16 |
+
#ifdef SQLITE_WASM_ENABLE_C_TESTS
|
| 17 |
+
# undef SQLITE_WASM_ENABLE_C_TESTS
|
| 18 |
+
# define SQLITE_WASM_ENABLE_C_TESTS 1
|
| 19 |
+
/*
|
| 20 |
+
** Code blocked off by SQLITE_WASM_ENABLE_C_TESTS is intended solely
|
| 21 |
+
** for use in unit/regression testing. They may be safely omitted from
|
| 22 |
+
** client-side builds. The main unit test script, tester1.js, will
|
| 23 |
+
** skip related tests if it doesn't find the corresponding functions
|
| 24 |
+
** in the WASM exports.
|
| 25 |
+
*/
|
| 26 |
+
#else
|
| 27 |
+
# define SQLITE_WASM_ENABLE_C_TESTS 0
|
| 28 |
+
#endif
|
| 29 |
+
|
| 30 |
+
/*
|
| 31 |
+
** Threading and file locking: JS is single-threaded. Each Worker
|
| 32 |
+
** thread is a separate instance of the JS engine so can never access
|
| 33 |
+
** the same db handle as another thread, thus multi-threading support
|
| 34 |
+
** is unnecessary in the library. Because the filesystems are virtual
|
| 35 |
+
** and local to a given wasm runtime instance, two Workers can never
|
| 36 |
+
** access the same db file at once, with the exception of OPFS.
|
| 37 |
+
**
|
| 38 |
+
** Summary: except for the case of OPFS, which supports locking using
|
| 39 |
+
** its own API, threading and file locking support are unnecessary in
|
| 40 |
+
** the wasm build.
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
/*
|
| 44 |
+
** Undefine any SQLITE_... config flags which we specifically do not
|
| 45 |
+
** want defined. Please keep these alphabetized.
|
| 46 |
+
*/
|
| 47 |
+
#undef SQLITE_OMIT_DESERIALIZE
|
| 48 |
+
#undef SQLITE_OMIT_MEMORYDB
|
| 49 |
+
|
| 50 |
+
/*
|
| 51 |
+
** Define any SQLITE_... config defaults we want if they aren't
|
| 52 |
+
** overridden by the builder. Please keep these alphabetized.
|
| 53 |
+
*/
|
| 54 |
+
|
| 55 |
+
/**********************************************************************/
|
| 56 |
+
/* SQLITE_D... */
|
| 57 |
+
#ifndef SQLITE_DEFAULT_CACHE_SIZE
|
| 58 |
+
/*
|
| 59 |
+
** The OPFS impls benefit tremendously from an increased cache size
|
| 60 |
+
** when working on large workloads, e.g. speedtest1 --size 50 or
|
| 61 |
+
** higher. On smaller workloads, e.g. speedtest1 --size 25, they
|
| 62 |
+
** clearly benefit from having 4mb of cache, but not as much as a
|
| 63 |
+
** larger cache benefits the larger workloads. Speed differences
|
| 64 |
+
** between 2x and nearly 3x have been measured with ample page cache.
|
| 65 |
+
*/
|
| 66 |
+
# define SQLITE_DEFAULT_CACHE_SIZE -16384
|
| 67 |
+
#endif
|
| 68 |
+
#if !defined(SQLITE_DEFAULT_PAGE_SIZE)
|
| 69 |
+
/*
|
| 70 |
+
** OPFS performance is improved by approx. 12% with a page size of 8kb
|
| 71 |
+
** instead of 4kb. Performance with 16kb is equivalent to 8kb.
|
| 72 |
+
**
|
| 73 |
+
** Performance difference of kvvfs with a page size of 8kb compared to
|
| 74 |
+
** 4kb, as measured by speedtest1 --size 4, is indeterminate:
|
| 75 |
+
** measurements are all over the place either way and not
|
| 76 |
+
** significantly different.
|
| 77 |
+
*/
|
| 78 |
+
# define SQLITE_DEFAULT_PAGE_SIZE 8192
|
| 79 |
+
#endif
|
| 80 |
+
#ifndef SQLITE_DEFAULT_UNIX_VFS
|
| 81 |
+
# define SQLITE_DEFAULT_UNIX_VFS "unix-none"
|
| 82 |
+
#endif
|
| 83 |
+
#undef SQLITE_DQS
|
| 84 |
+
#define SQLITE_DQS 0
|
| 85 |
+
|
| 86 |
+
/**********************************************************************/
|
| 87 |
+
/* SQLITE_ENABLE_... */
|
| 88 |
+
/*
|
| 89 |
+
** Unconditionally enable API_ARMOR in the WASM build. It ensures that
|
| 90 |
+
** public APIs behave predictable in the face of passing illegal NULLs
|
| 91 |
+
** or ranges which might otherwise invoke undefined behavior.
|
| 92 |
+
*/
|
| 93 |
+
#undef SQLITE_ENABLE_API_ARMOR
|
| 94 |
+
#define SQLITE_ENABLE_API_ARMOR 1
|
| 95 |
+
|
| 96 |
+
/**********************************************************************/
|
| 97 |
+
/* SQLITE_O... */
|
| 98 |
+
#undef SQLITE_OMIT_DEPRECATED
|
| 99 |
+
#define SQLITE_OMIT_DEPRECATED 1
|
| 100 |
+
#undef SQLITE_OMIT_LOAD_EXTENSION
|
| 101 |
+
#define SQLITE_OMIT_LOAD_EXTENSION 1
|
| 102 |
+
#undef SQLITE_OMIT_SHARED_CACHE
|
| 103 |
+
#define SQLITE_OMIT_SHARED_CACHE 1
|
| 104 |
+
#undef SQLITE_OMIT_UTF16
|
| 105 |
+
#define SQLITE_OMIT_UTF16 1
|
| 106 |
+
#undef SQLITE_OS_KV_OPTIONAL
|
| 107 |
+
#define SQLITE_OS_KV_OPTIONAL 1
|
| 108 |
+
|
| 109 |
+
/**********************************************************************/
|
| 110 |
+
/* SQLITE_S... */
|
| 111 |
+
#ifndef SQLITE_STRICT_SUBTYPE
|
| 112 |
+
# define SQLITE_STRICT_SUBTYPE 1
|
| 113 |
+
#endif
|
| 114 |
+
|
| 115 |
+
/**********************************************************************/
|
| 116 |
+
/* SQLITE_T... */
|
| 117 |
+
#ifndef SQLITE_TEMP_STORE
|
| 118 |
+
# define SQLITE_TEMP_STORE 2
|
| 119 |
+
#endif
|
| 120 |
+
#ifndef SQLITE_THREADSAFE
|
| 121 |
+
# define SQLITE_THREADSAFE 0
|
| 122 |
+
#endif
|
| 123 |
+
|
| 124 |
+
/**********************************************************************/
|
| 125 |
+
/* SQLITE_USE_... */
|
| 126 |
+
#ifndef SQLITE_USE_URI
|
| 127 |
+
# define SQLITE_USE_URI 1
|
| 128 |
+
#endif
|
| 129 |
+
|
| 130 |
+
#ifdef SQLITE_WASM_EXTRA_INIT
|
| 131 |
+
# define SQLITE_EXTRA_INIT sqlite3_wasm_extra_init
|
| 132 |
+
#endif
|
| 133 |
+
|
| 134 |
+
/*
|
| 135 |
+
** If SQLITE_WASM_BARE_BONES is defined, undefine most of the ENABLE
|
| 136 |
+
** macros.
|
| 137 |
+
*/
|
| 138 |
+
#ifdef SQLITE_WASM_BARE_BONES
|
| 139 |
+
# undef SQLITE_ENABLE_DBPAGE_VTAB
|
| 140 |
+
# undef SQLITE_ENABLE_DBSTAT_VTAB
|
| 141 |
+
# undef SQLITE_ENABLE_EXPLAIN_COMMENTS
|
| 142 |
+
# undef SQLITE_ENABLE_FTS5
|
| 143 |
+
# undef SQLITE_ENABLE_OFFSET_SQL_FUNC
|
| 144 |
+
# undef SQLITE_ENABLE_PREUPDATE_HOOK
|
| 145 |
+
# undef SQLITE_ENABLE_RTREE
|
| 146 |
+
# undef SQLITE_ENABLE_SESSION
|
| 147 |
+
# undef SQLITE_ENABLE_STMTVTAB
|
| 148 |
+
# undef SQLITE_OMIT_AUTHORIZATION
|
| 149 |
+
# define SQLITE_OMIT_AUTHORIZATION
|
| 150 |
+
# undef SQLITE_OMIT_GET_TABLE
|
| 151 |
+
# define SQLITE_OMIT_GET_TABLE
|
| 152 |
+
# undef SQLITE_OMIT_INCRBLOB
|
| 153 |
+
# define SQLITE_OMIT_INCRBLOB
|
| 154 |
+
# undef SQLITE_OMIT_INTROSPECTION_PRAGMAS
|
| 155 |
+
# define SQLITE_OMIT_INTROSPECTION_PRAGMAS
|
| 156 |
+
# undef SQLITE_OMIT_JSON
|
| 157 |
+
# define SQLITE_OMIT_JSON
|
| 158 |
+
# undef SQLITE_OMIT_PROGRESS_CALLBACK
|
| 159 |
+
# define SQLITE_OMIT_PROGRESS_CALLBACK
|
| 160 |
+
# undef SQLITE_OMIT_WAL
|
| 161 |
+
# define SQLITE_OMIT_WAL
|
| 162 |
+
/*
|
| 163 |
+
The following OMITs do not work with the standard amalgamation, so
|
| 164 |
+
require a custom build:
|
| 165 |
+
|
| 166 |
+
fossil clean -x
|
| 167 |
+
./configure
|
| 168 |
+
OPTS='...' make -e sqlite3
|
| 169 |
+
|
| 170 |
+
where ... has a -D... for each of the following OMIT flags:
|
| 171 |
+
|
| 172 |
+
# undef SQLITE_OMIT_EXPLAIN
|
| 173 |
+
# define SQLITE_OMIT_EXPLAIN
|
| 174 |
+
|
| 175 |
+
# undef SQLITE_OMIT_TRIGGER
|
| 176 |
+
# define SQLITE_OMIT_TRIGGER
|
| 177 |
+
|
| 178 |
+
# undef SQLITE_OMIT_VIRTUALTABLE
|
| 179 |
+
# define SQLITE_OMIT_VIRTUALTABLE
|
| 180 |
+
|
| 181 |
+
# undef SQLITE_OMIT_WINDOWFUNC
|
| 182 |
+
# define SQLITE_OMIT_WINDOWFUNC
|
| 183 |
+
|
| 184 |
+
As of this writing (2024-07-25), such a build fails in various ways
|
| 185 |
+
for as-yet-unknown reasons.
|
| 186 |
+
*/
|
| 187 |
+
#endif
|
| 188 |
+
|
| 189 |
+
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_BARE_BONES)
|
| 190 |
+
# define SQLITE_WASM_HAS_VTAB 1
|
| 191 |
+
#else
|
| 192 |
+
# define SQLITE_WASM_HAS_VTAB 0
|
| 193 |
+
#endif
|
| 194 |
+
|
| 195 |
+
#include <assert.h>
|
| 196 |
+
|
| 197 |
+
/*
|
| 198 |
+
** SQLITE_WASM_EXPORT is functionally identical to EMSCRIPTEN_KEEPALIVE
|
| 199 |
+
** but is not Emscripten-specific. It explicitly marks functions for
|
| 200 |
+
** export into the target wasm file without requiring explicit listing
|
| 201 |
+
** of those functions in Emscripten's -sEXPORTED_FUNCTIONS=... list
|
| 202 |
+
** (or equivalent in other build platforms). Any function with neither
|
| 203 |
+
** this attribute nor which is listed as an explicit export will not
|
| 204 |
+
** be exported from the wasm file (but may still be used internally
|
| 205 |
+
** within the wasm file).
|
| 206 |
+
**
|
| 207 |
+
** The functions in this file (sqlite3-wasm.c) which require exporting
|
| 208 |
+
** are marked with this flag. They may also be added to any explicit
|
| 209 |
+
** build-time export list but need not be. All of these APIs are
|
| 210 |
+
** intended for use only within the project's own JS/WASM code, and
|
| 211 |
+
** not by client code, so an argument can be made for reducing their
|
| 212 |
+
** visibility by not including them in any build-time export lists.
|
| 213 |
+
**
|
| 214 |
+
** 2022-09-11: it's not yet _proven_ that this approach works in
|
| 215 |
+
** non-Emscripten builds. If not, such builds will need to export
|
| 216 |
+
** those using the --export=... wasm-ld flag (or equivalent). As of
|
| 217 |
+
** this writing we are tied to Emscripten for various reasons
|
| 218 |
+
** and cannot test the library with other build environments.
|
| 219 |
+
*/
|
| 220 |
+
#define SQLITE_WASM_EXPORT __attribute__((used,visibility("default")))
|
| 221 |
+
// See also:
|
| 222 |
+
//__attribute__((export_name("theExportedName"), used, visibility("default")))
|
| 223 |
+
|
| 224 |
+
/*
|
| 225 |
+
** Which sqlite3.c we're using needs to be configurable to enable
|
| 226 |
+
** building against a custom copy, e.g. the SEE variant. Note that we
|
| 227 |
+
** #include the .c file, rather than the header, so that the WASM
|
| 228 |
+
** extensions have access to private API internals.
|
| 229 |
+
**
|
| 230 |
+
** The caveat here is that custom variants need to account for
|
| 231 |
+
** exporting any necessary symbols (e.g. sqlite3_activate_see()). We
|
| 232 |
+
** cannot export them from here using SQLITE_WASM_EXPORT because that
|
| 233 |
+
** attribute (apparently) has to be part of the function definition.
|
| 234 |
+
*/
|
| 235 |
+
#ifndef SQLITE_C
|
| 236 |
+
# define SQLITE_C sqlite3.c /* yes, .c instead of .h. */
|
| 237 |
+
#endif
|
| 238 |
+
#define INC__STRINGIFY_(f) #f
|
| 239 |
+
#define INC__STRINGIFY(f) INC__STRINGIFY_(f)
|
| 240 |
+
#include INC__STRINGIFY(SQLITE_C)
|
| 241 |
+
#undef INC__STRINGIFY_
|
| 242 |
+
#undef INC__STRINGIFY
|
| 243 |
+
#undef SQLITE_C
|
| 244 |
+
|
| 245 |
+
#if 0
|
| 246 |
+
/*
|
| 247 |
+
** An EXPERIMENT in implementing a stack-based allocator analog to
|
| 248 |
+
** Emscripten's stackSave(), stackAlloc(), stackRestore().
|
| 249 |
+
** Unfortunately, this cannot work together with Emscripten because
|
| 250 |
+
** Emscripten defines its own native one and we'd stomp on each
|
| 251 |
+
** other's memory. Other than that complication, basic tests show it
|
| 252 |
+
** to work just fine.
|
| 253 |
+
**
|
| 254 |
+
** Another option is to malloc() a chunk of our own and call that our
|
| 255 |
+
** "stack".
|
| 256 |
+
*/
|
| 257 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_end(void){
|
| 258 |
+
extern void __heap_base
|
| 259 |
+
/* see https://stackoverflow.com/questions/10038964 */;
|
| 260 |
+
return &__heap_base;
|
| 261 |
+
}
|
| 262 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_begin(void){
|
| 263 |
+
extern void __data_end;
|
| 264 |
+
return &__data_end;
|
| 265 |
+
}
|
| 266 |
+
static void * pWasmStackPtr = 0;
|
| 267 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_ptr(void){
|
| 268 |
+
if(!pWasmStackPtr) pWasmStackPtr = sqlite3__wasm_stack_end();
|
| 269 |
+
return pWasmStackPtr;
|
| 270 |
+
}
|
| 271 |
+
SQLITE_WASM_EXPORT void sqlite3__wasm_stack_restore(void * p){
|
| 272 |
+
pWasmStackPtr = p;
|
| 273 |
+
}
|
| 274 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_alloc(int n){
|
| 275 |
+
if(n<=0) return 0;
|
| 276 |
+
n = (n + 7) & ~7 /* align to 8-byte boundary */;
|
| 277 |
+
unsigned char * const p = (unsigned char *)sqlite3__wasm_stack_ptr();
|
| 278 |
+
unsigned const char * const b = (unsigned const char *)sqlite3__wasm_stack_begin();
|
| 279 |
+
if(b + n >= p || b + n < b/*overflow*/) return 0;
|
| 280 |
+
return pWasmStackPtr = p - n;
|
| 281 |
+
}
|
| 282 |
+
#endif /* stack allocator experiment */
|
| 283 |
+
|
| 284 |
+
/*
|
| 285 |
+
** State for the "pseudo-stack" allocator implemented in
|
| 286 |
+
** sqlite3__wasm_pstack_xyz(). In order to avoid colliding with
|
| 287 |
+
** Emscripten-controled stack space, it carves out a bit of stack
|
| 288 |
+
** memory to use for that purpose. This memory ends up in the
|
| 289 |
+
** WASM-managed memory, such that routines which manipulate the wasm
|
| 290 |
+
** heap can also be used to manipulate this memory.
|
| 291 |
+
**
|
| 292 |
+
** This particular allocator is intended for small allocations such as
|
| 293 |
+
** storage for output pointers. We cannot reasonably size it large
|
| 294 |
+
** enough for general-purpose string conversions because some of our
|
| 295 |
+
** tests use input files (strings) of 16MB+.
|
| 296 |
+
*/
|
| 297 |
+
static unsigned char PStack_mem[512 * 8] = {0};
|
| 298 |
+
static struct {
|
| 299 |
+
unsigned const char * const pBegin;/* Start (inclusive) of memory */
|
| 300 |
+
unsigned const char * const pEnd; /* One-after-the-end of memory */
|
| 301 |
+
unsigned char * pPos; /* Current stack pointer */
|
| 302 |
+
} PStack = {
|
| 303 |
+
&PStack_mem[0],
|
| 304 |
+
&PStack_mem[0] + sizeof(PStack_mem),
|
| 305 |
+
&PStack_mem[0] + sizeof(PStack_mem)
|
| 306 |
+
};
|
| 307 |
+
/*
|
| 308 |
+
** Returns the current pstack position.
|
| 309 |
+
*/
|
| 310 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_pstack_ptr(void){
|
| 311 |
+
return PStack.pPos;
|
| 312 |
+
}
|
| 313 |
+
/*
|
| 314 |
+
** Sets the pstack position poitner to p. Results are undefined if the
|
| 315 |
+
** given value did not come from sqlite3__wasm_pstack_ptr().
|
| 316 |
+
*/
|
| 317 |
+
SQLITE_WASM_EXPORT void sqlite3__wasm_pstack_restore(unsigned char * p){
|
| 318 |
+
assert(p>=PStack.pBegin && p<=PStack.pEnd && p>=PStack.pPos);
|
| 319 |
+
assert(0==((unsigned long long)p & 0x7));
|
| 320 |
+
if(p>=PStack.pBegin && p<=PStack.pEnd /*&& p>=PStack.pPos*/){
|
| 321 |
+
PStack.pPos = p;
|
| 322 |
+
}
|
| 323 |
+
}
|
| 324 |
+
/*
|
| 325 |
+
** Allocate and zero out n bytes from the pstack. Returns a pointer to
|
| 326 |
+
** the memory on success, 0 on error (including a negative n value). n
|
| 327 |
+
** is always adjusted to be a multiple of 8 and returned memory is
|
| 328 |
+
** always zeroed out before returning (because this keeps the client
|
| 329 |
+
** JS code from having to do so, and most uses of the pstack will
|
| 330 |
+
** call for doing so).
|
| 331 |
+
*/
|
| 332 |
+
SQLITE_WASM_EXPORT void * sqlite3__wasm_pstack_alloc(int n){
|
| 333 |
+
if( n<=0 ) return 0;
|
| 334 |
+
//if( n & 0x7 ) n += 8 - (n & 0x7) /* align to 8-byte boundary */;
|
| 335 |
+
n = (n + 7) & ~7 /* align to 8-byte boundary */;
|
| 336 |
+
if( PStack.pBegin + n > PStack.pPos /*not enough space left*/
|
| 337 |
+
|| PStack.pBegin + n <= PStack.pBegin /*overflow*/ ) return 0;
|
| 338 |
+
memset((PStack.pPos = PStack.pPos - n), 0, (unsigned int)n);
|
| 339 |
+
return PStack.pPos;
|
| 340 |
+
}
|
| 341 |
+
/*
|
| 342 |
+
** Return the number of bytes left which can be
|
| 343 |
+
** sqlite3__wasm_pstack_alloc()'d.
|
| 344 |
+
*/
|
| 345 |
+
SQLITE_WASM_EXPORT int sqlite3__wasm_pstack_remaining(void){
|
| 346 |
+
assert(PStack.pPos >= PStack.pBegin);
|
| 347 |
+
assert(PStack.pPos <= PStack.pEnd);
|
| 348 |
+
return (int)(PStack.pPos - PStack.pBegin);
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
/*
|
| 352 |
+
** Return the total number of bytes available in the pstack, including
|
| 353 |
+
** any space which is currently allocated. This value is a
|
| 354 |
+
** compile-time constant.
|
| 355 |
+
*/
|
| 356 |
+
SQLITE_WASM_EXPORT int sqlite3__wasm_pstack_quota(void){
|
| 357 |
+
return (int)(PStack.pEnd - PStack.pBegin);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
/*
|
| 361 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 362 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 363 |
+
**
|
| 364 |
+
** For purposes of certain hand-crafted C/Wasm function bindings, we
|
| 365 |
+
** need a way of reporting errors which is consistent with the rest of
|
| 366 |
+
** the C API, as opposed to throwing JS exceptions. To that end, this
|
| 367 |
+
** internal-use-only function is a thin proxy around
|
| 368 |
+
** sqlite3ErrorWithMessage(). The intent is that it only be used from
|
| 369 |
+
** Wasm bindings such as sqlite3_prepare_v2/v3(), and definitely not
|
| 370 |
+
** from client code.
|
| 371 |
+
**
|
| 372 |
+
** Returns err_code.
|
| 373 |
+
*/
|
| 374 |
+
SQLITE_WASM_EXPORT
|
| 375 |
+
int sqlite3__wasm_db_error(sqlite3*db, int err_code, const char *zMsg){
|
| 376 |
+
if( db!=0 ){
|
| 377 |
+
if( 0!=zMsg ){
|
| 378 |
+
const int nMsg = sqlite3Strlen30(zMsg);
|
| 379 |
+
sqlite3_mutex_enter(sqlite3_db_mutex(db));
|
| 380 |
+
sqlite3ErrorWithMsg(db, err_code, "%.*s", nMsg, zMsg);
|
| 381 |
+
sqlite3_mutex_leave(sqlite3_db_mutex(db));
|
| 382 |
+
}else{
|
| 383 |
+
sqlite3ErrorWithMsg(db, err_code, NULL);
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
return err_code;
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
#if SQLITE_WASM_ENABLE_C_TESTS
|
| 390 |
+
struct WasmTestStruct {
|
| 391 |
+
int v4;
|
| 392 |
+
void * ppV;
|
| 393 |
+
const char * cstr;
|
| 394 |
+
int64_t v8;
|
| 395 |
+
void (*xFunc)(void*);
|
| 396 |
+
};
|
| 397 |
+
typedef struct WasmTestStruct WasmTestStruct;
|
| 398 |
+
SQLITE_WASM_EXPORT
|
| 399 |
+
void sqlite3__wasm_test_struct(WasmTestStruct * s){
|
| 400 |
+
if(s){
|
| 401 |
+
s->v4 *= 2;
|
| 402 |
+
s->v8 = s->v4 * 2;
|
| 403 |
+
s->ppV = s;
|
| 404 |
+
s->cstr = __FILE__;
|
| 405 |
+
if(s->xFunc) s->xFunc(s);
|
| 406 |
+
}
|
| 407 |
+
return;
|
| 408 |
+
}
|
| 409 |
+
#endif /* SQLITE_WASM_ENABLE_C_TESTS */
|
| 410 |
+
|
| 411 |
+
/*
|
| 412 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 413 |
+
** for use by the sqlite project's own JS/WASM bindings. Unlike the
|
| 414 |
+
** rest of the sqlite3 API, this part requires C99 for snprintf() and
|
| 415 |
+
** variadic macros.
|
| 416 |
+
**
|
| 417 |
+
** Returns a string containing a JSON-format "enum" of C-level
|
| 418 |
+
** constants and struct-related metadata intended to be imported into
|
| 419 |
+
** the JS environment. The JSON is initialized the first time this
|
| 420 |
+
** function is called and that result is reused for all future calls.
|
| 421 |
+
**
|
| 422 |
+
** If this function returns NULL then it means that the internal
|
| 423 |
+
** buffer is not large enough for the generated JSON and needs to be
|
| 424 |
+
** increased. In debug builds that will trigger an assert().
|
| 425 |
+
*/
|
| 426 |
+
SQLITE_WASM_EXPORT
|
| 427 |
+
const char * sqlite3__wasm_enum_json(void){
|
| 428 |
+
static char aBuffer[1024 * 20] = {0} /* where the JSON goes */;
|
| 429 |
+
int n = 0, nChildren = 0, nStruct = 0
|
| 430 |
+
/* output counters for figuring out where commas go */;
|
| 431 |
+
char * zPos = &aBuffer[1] /* skip first byte for now to help protect
|
| 432 |
+
** against a small race condition */;
|
| 433 |
+
char const * const zEnd = &aBuffer[0] + sizeof(aBuffer) /* one-past-the-end */;
|
| 434 |
+
if(aBuffer[0]) return aBuffer;
|
| 435 |
+
/* Leave aBuffer[0] at 0 until the end to help guard against a tiny
|
| 436 |
+
** race condition. If this is called twice concurrently, they might
|
| 437 |
+
** end up both writing to aBuffer, but they'll both write the same
|
| 438 |
+
** thing, so that's okay. If we set byte 0 up front then the 2nd
|
| 439 |
+
** instance might return and use the string before the 1st instance
|
| 440 |
+
** is done filling it. */
|
| 441 |
+
|
| 442 |
+
/* Core output macros... */
|
| 443 |
+
#define lenCheck assert(zPos < zEnd - 128 \
|
| 444 |
+
&& "sqlite3__wasm_enum_json() buffer is too small."); \
|
| 445 |
+
if( zPos >= zEnd - 128 ) return 0
|
| 446 |
+
#define outf(format,...) \
|
| 447 |
+
zPos += snprintf(zPos, ((size_t)(zEnd - zPos)), format, __VA_ARGS__); \
|
| 448 |
+
lenCheck
|
| 449 |
+
#define out(TXT) outf("%s",TXT)
|
| 450 |
+
#define CloseBrace(LEVEL) \
|
| 451 |
+
assert(LEVEL<5); memset(zPos, '}', LEVEL); zPos+=LEVEL; lenCheck
|
| 452 |
+
|
| 453 |
+
/* Macros for emitting maps of integer- and string-type macros to
|
| 454 |
+
** their values. */
|
| 455 |
+
#define DefGroup(KEY) n = 0; \
|
| 456 |
+
outf("%s\"" #KEY "\": {",(nChildren++ ? "," : ""));
|
| 457 |
+
#define DefInt(KEY) \
|
| 458 |
+
outf("%s\"%s\": %d", (n++ ? ", " : ""), #KEY, (int)KEY)
|
| 459 |
+
#define DefStr(KEY) \
|
| 460 |
+
outf("%s\"%s\": \"%s\"", (n++ ? ", " : ""), #KEY, KEY)
|
| 461 |
+
#define _DefGroup CloseBrace(1)
|
| 462 |
+
|
| 463 |
+
/* The following groups are sorted alphabetic by group name. */
|
| 464 |
+
DefGroup(access){
|
| 465 |
+
DefInt(SQLITE_ACCESS_EXISTS);
|
| 466 |
+
DefInt(SQLITE_ACCESS_READWRITE);
|
| 467 |
+
DefInt(SQLITE_ACCESS_READ)/*docs say this is unused*/;
|
| 468 |
+
} _DefGroup;
|
| 469 |
+
|
| 470 |
+
DefGroup(authorizer){
|
| 471 |
+
DefInt(SQLITE_DENY);
|
| 472 |
+
DefInt(SQLITE_IGNORE);
|
| 473 |
+
DefInt(SQLITE_CREATE_INDEX);
|
| 474 |
+
DefInt(SQLITE_CREATE_TABLE);
|
| 475 |
+
DefInt(SQLITE_CREATE_TEMP_INDEX);
|
| 476 |
+
DefInt(SQLITE_CREATE_TEMP_TABLE);
|
| 477 |
+
DefInt(SQLITE_CREATE_TEMP_TRIGGER);
|
| 478 |
+
DefInt(SQLITE_CREATE_TEMP_VIEW);
|
| 479 |
+
DefInt(SQLITE_CREATE_TRIGGER);
|
| 480 |
+
DefInt(SQLITE_CREATE_VIEW);
|
| 481 |
+
DefInt(SQLITE_DELETE);
|
| 482 |
+
DefInt(SQLITE_DROP_INDEX);
|
| 483 |
+
DefInt(SQLITE_DROP_TABLE);
|
| 484 |
+
DefInt(SQLITE_DROP_TEMP_INDEX);
|
| 485 |
+
DefInt(SQLITE_DROP_TEMP_TABLE);
|
| 486 |
+
DefInt(SQLITE_DROP_TEMP_TRIGGER);
|
| 487 |
+
DefInt(SQLITE_DROP_TEMP_VIEW);
|
| 488 |
+
DefInt(SQLITE_DROP_TRIGGER);
|
| 489 |
+
DefInt(SQLITE_DROP_VIEW);
|
| 490 |
+
DefInt(SQLITE_INSERT);
|
| 491 |
+
DefInt(SQLITE_PRAGMA);
|
| 492 |
+
DefInt(SQLITE_READ);
|
| 493 |
+
DefInt(SQLITE_SELECT);
|
| 494 |
+
DefInt(SQLITE_TRANSACTION);
|
| 495 |
+
DefInt(SQLITE_UPDATE);
|
| 496 |
+
DefInt(SQLITE_ATTACH);
|
| 497 |
+
DefInt(SQLITE_DETACH);
|
| 498 |
+
DefInt(SQLITE_ALTER_TABLE);
|
| 499 |
+
DefInt(SQLITE_REINDEX);
|
| 500 |
+
DefInt(SQLITE_ANALYZE);
|
| 501 |
+
DefInt(SQLITE_CREATE_VTABLE);
|
| 502 |
+
DefInt(SQLITE_DROP_VTABLE);
|
| 503 |
+
DefInt(SQLITE_FUNCTION);
|
| 504 |
+
DefInt(SQLITE_SAVEPOINT);
|
| 505 |
+
//DefInt(SQLITE_COPY) /* No longer used */;
|
| 506 |
+
DefInt(SQLITE_RECURSIVE);
|
| 507 |
+
} _DefGroup;
|
| 508 |
+
|
| 509 |
+
DefGroup(blobFinalizers) {
|
| 510 |
+
/* SQLITE_STATIC/TRANSIENT need to be handled explicitly as
|
| 511 |
+
** integers to avoid casting-related warnings. */
|
| 512 |
+
out("\"SQLITE_STATIC\":0, \"SQLITE_TRANSIENT\":-1");
|
| 513 |
+
outf(",\"SQLITE_WASM_DEALLOC\": %lld",
|
| 514 |
+
(sqlite3_int64)(sqlite3_free));
|
| 515 |
+
} _DefGroup;
|
| 516 |
+
|
| 517 |
+
DefGroup(changeset){
|
| 518 |
+
#ifdef SQLITE_CHANGESETSTART_INVERT
|
| 519 |
+
DefInt(SQLITE_CHANGESETSTART_INVERT);
|
| 520 |
+
DefInt(SQLITE_CHANGESETAPPLY_NOSAVEPOINT);
|
| 521 |
+
DefInt(SQLITE_CHANGESETAPPLY_INVERT);
|
| 522 |
+
DefInt(SQLITE_CHANGESETAPPLY_IGNORENOOP);
|
| 523 |
+
|
| 524 |
+
DefInt(SQLITE_CHANGESET_DATA);
|
| 525 |
+
DefInt(SQLITE_CHANGESET_NOTFOUND);
|
| 526 |
+
DefInt(SQLITE_CHANGESET_CONFLICT);
|
| 527 |
+
DefInt(SQLITE_CHANGESET_CONSTRAINT);
|
| 528 |
+
DefInt(SQLITE_CHANGESET_FOREIGN_KEY);
|
| 529 |
+
|
| 530 |
+
DefInt(SQLITE_CHANGESET_OMIT);
|
| 531 |
+
DefInt(SQLITE_CHANGESET_REPLACE);
|
| 532 |
+
DefInt(SQLITE_CHANGESET_ABORT);
|
| 533 |
+
#endif
|
| 534 |
+
} _DefGroup;
|
| 535 |
+
|
| 536 |
+
DefGroup(config){
|
| 537 |
+
DefInt(SQLITE_CONFIG_SINGLETHREAD);
|
| 538 |
+
DefInt(SQLITE_CONFIG_MULTITHREAD);
|
| 539 |
+
DefInt(SQLITE_CONFIG_SERIALIZED);
|
| 540 |
+
DefInt(SQLITE_CONFIG_MALLOC);
|
| 541 |
+
DefInt(SQLITE_CONFIG_GETMALLOC);
|
| 542 |
+
DefInt(SQLITE_CONFIG_SCRATCH);
|
| 543 |
+
DefInt(SQLITE_CONFIG_PAGECACHE);
|
| 544 |
+
DefInt(SQLITE_CONFIG_HEAP);
|
| 545 |
+
DefInt(SQLITE_CONFIG_MEMSTATUS);
|
| 546 |
+
DefInt(SQLITE_CONFIG_MUTEX);
|
| 547 |
+
DefInt(SQLITE_CONFIG_GETMUTEX);
|
| 548 |
+
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
|
| 549 |
+
DefInt(SQLITE_CONFIG_LOOKASIDE);
|
| 550 |
+
DefInt(SQLITE_CONFIG_PCACHE);
|
| 551 |
+
DefInt(SQLITE_CONFIG_GETPCACHE);
|
| 552 |
+
DefInt(SQLITE_CONFIG_LOG);
|
| 553 |
+
DefInt(SQLITE_CONFIG_URI);
|
| 554 |
+
DefInt(SQLITE_CONFIG_PCACHE2);
|
| 555 |
+
DefInt(SQLITE_CONFIG_GETPCACHE2);
|
| 556 |
+
DefInt(SQLITE_CONFIG_COVERING_INDEX_SCAN);
|
| 557 |
+
DefInt(SQLITE_CONFIG_SQLLOG);
|
| 558 |
+
DefInt(SQLITE_CONFIG_MMAP_SIZE);
|
| 559 |
+
DefInt(SQLITE_CONFIG_WIN32_HEAPSIZE);
|
| 560 |
+
DefInt(SQLITE_CONFIG_PCACHE_HDRSZ);
|
| 561 |
+
DefInt(SQLITE_CONFIG_PMASZ);
|
| 562 |
+
DefInt(SQLITE_CONFIG_STMTJRNL_SPILL);
|
| 563 |
+
DefInt(SQLITE_CONFIG_SMALL_MALLOC);
|
| 564 |
+
DefInt(SQLITE_CONFIG_SORTERREF_SIZE);
|
| 565 |
+
DefInt(SQLITE_CONFIG_MEMDB_MAXSIZE);
|
| 566 |
+
/* maintenance note: we specifically do not include
|
| 567 |
+
SQLITE_CONFIG_ROWID_IN_VIEW here, on the grounds that
|
| 568 |
+
it's only for legacy support and no apps written with
|
| 569 |
+
this API require that. */
|
| 570 |
+
} _DefGroup;
|
| 571 |
+
|
| 572 |
+
DefGroup(dataTypes) {
|
| 573 |
+
DefInt(SQLITE_INTEGER);
|
| 574 |
+
DefInt(SQLITE_FLOAT);
|
| 575 |
+
DefInt(SQLITE_TEXT);
|
| 576 |
+
DefInt(SQLITE_BLOB);
|
| 577 |
+
DefInt(SQLITE_NULL);
|
| 578 |
+
} _DefGroup;
|
| 579 |
+
|
| 580 |
+
DefGroup(dbConfig){
|
| 581 |
+
DefInt(SQLITE_DBCONFIG_MAINDBNAME);
|
| 582 |
+
DefInt(SQLITE_DBCONFIG_LOOKASIDE);
|
| 583 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_FKEY);
|
| 584 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_TRIGGER);
|
| 585 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION);
|
| 586 |
+
DefInt(SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE);
|
| 587 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_QPSG);
|
| 588 |
+
DefInt(SQLITE_DBCONFIG_TRIGGER_EQP);
|
| 589 |
+
DefInt(SQLITE_DBCONFIG_RESET_DATABASE);
|
| 590 |
+
DefInt(SQLITE_DBCONFIG_DEFENSIVE);
|
| 591 |
+
DefInt(SQLITE_DBCONFIG_WRITABLE_SCHEMA);
|
| 592 |
+
DefInt(SQLITE_DBCONFIG_LEGACY_ALTER_TABLE);
|
| 593 |
+
DefInt(SQLITE_DBCONFIG_DQS_DML);
|
| 594 |
+
DefInt(SQLITE_DBCONFIG_DQS_DDL);
|
| 595 |
+
DefInt(SQLITE_DBCONFIG_ENABLE_VIEW);
|
| 596 |
+
DefInt(SQLITE_DBCONFIG_LEGACY_FILE_FORMAT);
|
| 597 |
+
DefInt(SQLITE_DBCONFIG_TRUSTED_SCHEMA);
|
| 598 |
+
DefInt(SQLITE_DBCONFIG_STMT_SCANSTATUS);
|
| 599 |
+
DefInt(SQLITE_DBCONFIG_REVERSE_SCANORDER);
|
| 600 |
+
DefInt(SQLITE_DBCONFIG_MAX);
|
| 601 |
+
} _DefGroup;
|
| 602 |
+
|
| 603 |
+
DefGroup(dbStatus){
|
| 604 |
+
DefInt(SQLITE_DBSTATUS_LOOKASIDE_USED);
|
| 605 |
+
DefInt(SQLITE_DBSTATUS_CACHE_USED);
|
| 606 |
+
DefInt(SQLITE_DBSTATUS_SCHEMA_USED);
|
| 607 |
+
DefInt(SQLITE_DBSTATUS_STMT_USED);
|
| 608 |
+
DefInt(SQLITE_DBSTATUS_LOOKASIDE_HIT);
|
| 609 |
+
DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE);
|
| 610 |
+
DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL);
|
| 611 |
+
DefInt(SQLITE_DBSTATUS_CACHE_HIT);
|
| 612 |
+
DefInt(SQLITE_DBSTATUS_CACHE_MISS);
|
| 613 |
+
DefInt(SQLITE_DBSTATUS_CACHE_WRITE);
|
| 614 |
+
DefInt(SQLITE_DBSTATUS_DEFERRED_FKS);
|
| 615 |
+
DefInt(SQLITE_DBSTATUS_CACHE_USED_SHARED);
|
| 616 |
+
DefInt(SQLITE_DBSTATUS_CACHE_SPILL);
|
| 617 |
+
DefInt(SQLITE_DBSTATUS_MAX);
|
| 618 |
+
} _DefGroup;
|
| 619 |
+
|
| 620 |
+
DefGroup(encodings) {
|
| 621 |
+
/* Noting that the wasm binding only aims to support UTF-8. */
|
| 622 |
+
DefInt(SQLITE_UTF8);
|
| 623 |
+
DefInt(SQLITE_UTF16LE);
|
| 624 |
+
DefInt(SQLITE_UTF16BE);
|
| 625 |
+
DefInt(SQLITE_UTF16);
|
| 626 |
+
/*deprecated DefInt(SQLITE_ANY); */
|
| 627 |
+
DefInt(SQLITE_UTF16_ALIGNED);
|
| 628 |
+
} _DefGroup;
|
| 629 |
+
|
| 630 |
+
DefGroup(fcntl) {
|
| 631 |
+
DefInt(SQLITE_FCNTL_LOCKSTATE);
|
| 632 |
+
DefInt(SQLITE_FCNTL_GET_LOCKPROXYFILE);
|
| 633 |
+
DefInt(SQLITE_FCNTL_SET_LOCKPROXYFILE);
|
| 634 |
+
DefInt(SQLITE_FCNTL_LAST_ERRNO);
|
| 635 |
+
DefInt(SQLITE_FCNTL_SIZE_HINT);
|
| 636 |
+
DefInt(SQLITE_FCNTL_CHUNK_SIZE);
|
| 637 |
+
DefInt(SQLITE_FCNTL_FILE_POINTER);
|
| 638 |
+
DefInt(SQLITE_FCNTL_SYNC_OMITTED);
|
| 639 |
+
DefInt(SQLITE_FCNTL_WIN32_AV_RETRY);
|
| 640 |
+
DefInt(SQLITE_FCNTL_PERSIST_WAL);
|
| 641 |
+
DefInt(SQLITE_FCNTL_OVERWRITE);
|
| 642 |
+
DefInt(SQLITE_FCNTL_VFSNAME);
|
| 643 |
+
DefInt(SQLITE_FCNTL_POWERSAFE_OVERWRITE);
|
| 644 |
+
DefInt(SQLITE_FCNTL_PRAGMA);
|
| 645 |
+
DefInt(SQLITE_FCNTL_BUSYHANDLER);
|
| 646 |
+
DefInt(SQLITE_FCNTL_TEMPFILENAME);
|
| 647 |
+
DefInt(SQLITE_FCNTL_MMAP_SIZE);
|
| 648 |
+
DefInt(SQLITE_FCNTL_TRACE);
|
| 649 |
+
DefInt(SQLITE_FCNTL_HAS_MOVED);
|
| 650 |
+
DefInt(SQLITE_FCNTL_SYNC);
|
| 651 |
+
DefInt(SQLITE_FCNTL_COMMIT_PHASETWO);
|
| 652 |
+
DefInt(SQLITE_FCNTL_WIN32_SET_HANDLE);
|
| 653 |
+
DefInt(SQLITE_FCNTL_WAL_BLOCK);
|
| 654 |
+
DefInt(SQLITE_FCNTL_ZIPVFS);
|
| 655 |
+
DefInt(SQLITE_FCNTL_RBU);
|
| 656 |
+
DefInt(SQLITE_FCNTL_VFS_POINTER);
|
| 657 |
+
DefInt(SQLITE_FCNTL_JOURNAL_POINTER);
|
| 658 |
+
DefInt(SQLITE_FCNTL_WIN32_GET_HANDLE);
|
| 659 |
+
DefInt(SQLITE_FCNTL_PDB);
|
| 660 |
+
DefInt(SQLITE_FCNTL_BEGIN_ATOMIC_WRITE);
|
| 661 |
+
DefInt(SQLITE_FCNTL_COMMIT_ATOMIC_WRITE);
|
| 662 |
+
DefInt(SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE);
|
| 663 |
+
DefInt(SQLITE_FCNTL_LOCK_TIMEOUT);
|
| 664 |
+
DefInt(SQLITE_FCNTL_DATA_VERSION);
|
| 665 |
+
DefInt(SQLITE_FCNTL_SIZE_LIMIT);
|
| 666 |
+
DefInt(SQLITE_FCNTL_CKPT_DONE);
|
| 667 |
+
DefInt(SQLITE_FCNTL_RESERVE_BYTES);
|
| 668 |
+
DefInt(SQLITE_FCNTL_CKPT_START);
|
| 669 |
+
DefInt(SQLITE_FCNTL_EXTERNAL_READER);
|
| 670 |
+
DefInt(SQLITE_FCNTL_CKSM_FILE);
|
| 671 |
+
DefInt(SQLITE_FCNTL_RESET_CACHE);
|
| 672 |
+
} _DefGroup;
|
| 673 |
+
|
| 674 |
+
DefGroup(flock) {
|
| 675 |
+
DefInt(SQLITE_LOCK_NONE);
|
| 676 |
+
DefInt(SQLITE_LOCK_SHARED);
|
| 677 |
+
DefInt(SQLITE_LOCK_RESERVED);
|
| 678 |
+
DefInt(SQLITE_LOCK_PENDING);
|
| 679 |
+
DefInt(SQLITE_LOCK_EXCLUSIVE);
|
| 680 |
+
} _DefGroup;
|
| 681 |
+
|
| 682 |
+
DefGroup(ioCap) {
|
| 683 |
+
DefInt(SQLITE_IOCAP_ATOMIC);
|
| 684 |
+
DefInt(SQLITE_IOCAP_ATOMIC512);
|
| 685 |
+
DefInt(SQLITE_IOCAP_ATOMIC1K);
|
| 686 |
+
DefInt(SQLITE_IOCAP_ATOMIC2K);
|
| 687 |
+
DefInt(SQLITE_IOCAP_ATOMIC4K);
|
| 688 |
+
DefInt(SQLITE_IOCAP_ATOMIC8K);
|
| 689 |
+
DefInt(SQLITE_IOCAP_ATOMIC16K);
|
| 690 |
+
DefInt(SQLITE_IOCAP_ATOMIC32K);
|
| 691 |
+
DefInt(SQLITE_IOCAP_ATOMIC64K);
|
| 692 |
+
DefInt(SQLITE_IOCAP_SAFE_APPEND);
|
| 693 |
+
DefInt(SQLITE_IOCAP_SEQUENTIAL);
|
| 694 |
+
DefInt(SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN);
|
| 695 |
+
DefInt(SQLITE_IOCAP_POWERSAFE_OVERWRITE);
|
| 696 |
+
DefInt(SQLITE_IOCAP_IMMUTABLE);
|
| 697 |
+
DefInt(SQLITE_IOCAP_BATCH_ATOMIC);
|
| 698 |
+
} _DefGroup;
|
| 699 |
+
|
| 700 |
+
DefGroup(limits) {
|
| 701 |
+
DefInt(SQLITE_MAX_ALLOCATION_SIZE);
|
| 702 |
+
DefInt(SQLITE_LIMIT_LENGTH);
|
| 703 |
+
DefInt(SQLITE_MAX_LENGTH);
|
| 704 |
+
DefInt(SQLITE_LIMIT_SQL_LENGTH);
|
| 705 |
+
DefInt(SQLITE_MAX_SQL_LENGTH);
|
| 706 |
+
DefInt(SQLITE_LIMIT_COLUMN);
|
| 707 |
+
DefInt(SQLITE_MAX_COLUMN);
|
| 708 |
+
DefInt(SQLITE_LIMIT_EXPR_DEPTH);
|
| 709 |
+
DefInt(SQLITE_MAX_EXPR_DEPTH);
|
| 710 |
+
DefInt(SQLITE_LIMIT_COMPOUND_SELECT);
|
| 711 |
+
DefInt(SQLITE_MAX_COMPOUND_SELECT);
|
| 712 |
+
DefInt(SQLITE_LIMIT_VDBE_OP);
|
| 713 |
+
DefInt(SQLITE_MAX_VDBE_OP);
|
| 714 |
+
DefInt(SQLITE_LIMIT_FUNCTION_ARG);
|
| 715 |
+
DefInt(SQLITE_MAX_FUNCTION_ARG);
|
| 716 |
+
DefInt(SQLITE_LIMIT_ATTACHED);
|
| 717 |
+
DefInt(SQLITE_MAX_ATTACHED);
|
| 718 |
+
DefInt(SQLITE_LIMIT_LIKE_PATTERN_LENGTH);
|
| 719 |
+
DefInt(SQLITE_MAX_LIKE_PATTERN_LENGTH);
|
| 720 |
+
DefInt(SQLITE_LIMIT_VARIABLE_NUMBER);
|
| 721 |
+
DefInt(SQLITE_MAX_VARIABLE_NUMBER);
|
| 722 |
+
DefInt(SQLITE_LIMIT_TRIGGER_DEPTH);
|
| 723 |
+
DefInt(SQLITE_MAX_TRIGGER_DEPTH);
|
| 724 |
+
DefInt(SQLITE_LIMIT_WORKER_THREADS);
|
| 725 |
+
DefInt(SQLITE_MAX_WORKER_THREADS);
|
| 726 |
+
} _DefGroup;
|
| 727 |
+
|
| 728 |
+
DefGroup(openFlags) {
|
| 729 |
+
/* Noting that not all of these will have any effect in
|
| 730 |
+
** WASM-space. */
|
| 731 |
+
DefInt(SQLITE_OPEN_READONLY);
|
| 732 |
+
DefInt(SQLITE_OPEN_READWRITE);
|
| 733 |
+
DefInt(SQLITE_OPEN_CREATE);
|
| 734 |
+
DefInt(SQLITE_OPEN_URI);
|
| 735 |
+
DefInt(SQLITE_OPEN_MEMORY);
|
| 736 |
+
DefInt(SQLITE_OPEN_NOMUTEX);
|
| 737 |
+
DefInt(SQLITE_OPEN_FULLMUTEX);
|
| 738 |
+
DefInt(SQLITE_OPEN_SHAREDCACHE);
|
| 739 |
+
DefInt(SQLITE_OPEN_PRIVATECACHE);
|
| 740 |
+
DefInt(SQLITE_OPEN_EXRESCODE);
|
| 741 |
+
DefInt(SQLITE_OPEN_NOFOLLOW);
|
| 742 |
+
/* OPEN flags for use with VFSes... */
|
| 743 |
+
DefInt(SQLITE_OPEN_MAIN_DB);
|
| 744 |
+
DefInt(SQLITE_OPEN_MAIN_JOURNAL);
|
| 745 |
+
DefInt(SQLITE_OPEN_TEMP_DB);
|
| 746 |
+
DefInt(SQLITE_OPEN_TEMP_JOURNAL);
|
| 747 |
+
DefInt(SQLITE_OPEN_TRANSIENT_DB);
|
| 748 |
+
DefInt(SQLITE_OPEN_SUBJOURNAL);
|
| 749 |
+
DefInt(SQLITE_OPEN_SUPER_JOURNAL);
|
| 750 |
+
DefInt(SQLITE_OPEN_WAL);
|
| 751 |
+
DefInt(SQLITE_OPEN_DELETEONCLOSE);
|
| 752 |
+
DefInt(SQLITE_OPEN_EXCLUSIVE);
|
| 753 |
+
} _DefGroup;
|
| 754 |
+
|
| 755 |
+
DefGroup(prepareFlags) {
|
| 756 |
+
DefInt(SQLITE_PREPARE_PERSISTENT);
|
| 757 |
+
DefInt(SQLITE_PREPARE_NORMALIZE);
|
| 758 |
+
DefInt(SQLITE_PREPARE_NO_VTAB);
|
| 759 |
+
} _DefGroup;
|
| 760 |
+
|
| 761 |
+
DefGroup(resultCodes) {
|
| 762 |
+
DefInt(SQLITE_OK);
|
| 763 |
+
DefInt(SQLITE_ERROR);
|
| 764 |
+
DefInt(SQLITE_INTERNAL);
|
| 765 |
+
DefInt(SQLITE_PERM);
|
| 766 |
+
DefInt(SQLITE_ABORT);
|
| 767 |
+
DefInt(SQLITE_BUSY);
|
| 768 |
+
DefInt(SQLITE_LOCKED);
|
| 769 |
+
DefInt(SQLITE_NOMEM);
|
| 770 |
+
DefInt(SQLITE_READONLY);
|
| 771 |
+
DefInt(SQLITE_INTERRUPT);
|
| 772 |
+
DefInt(SQLITE_IOERR);
|
| 773 |
+
DefInt(SQLITE_CORRUPT);
|
| 774 |
+
DefInt(SQLITE_NOTFOUND);
|
| 775 |
+
DefInt(SQLITE_FULL);
|
| 776 |
+
DefInt(SQLITE_CANTOPEN);
|
| 777 |
+
DefInt(SQLITE_PROTOCOL);
|
| 778 |
+
DefInt(SQLITE_EMPTY);
|
| 779 |
+
DefInt(SQLITE_SCHEMA);
|
| 780 |
+
DefInt(SQLITE_TOOBIG);
|
| 781 |
+
DefInt(SQLITE_CONSTRAINT);
|
| 782 |
+
DefInt(SQLITE_MISMATCH);
|
| 783 |
+
DefInt(SQLITE_MISUSE);
|
| 784 |
+
DefInt(SQLITE_NOLFS);
|
| 785 |
+
DefInt(SQLITE_AUTH);
|
| 786 |
+
DefInt(SQLITE_FORMAT);
|
| 787 |
+
DefInt(SQLITE_RANGE);
|
| 788 |
+
DefInt(SQLITE_NOTADB);
|
| 789 |
+
DefInt(SQLITE_NOTICE);
|
| 790 |
+
DefInt(SQLITE_WARNING);
|
| 791 |
+
DefInt(SQLITE_ROW);
|
| 792 |
+
DefInt(SQLITE_DONE);
|
| 793 |
+
// Extended Result Codes
|
| 794 |
+
DefInt(SQLITE_ERROR_MISSING_COLLSEQ);
|
| 795 |
+
DefInt(SQLITE_ERROR_RETRY);
|
| 796 |
+
DefInt(SQLITE_ERROR_SNAPSHOT);
|
| 797 |
+
DefInt(SQLITE_IOERR_READ);
|
| 798 |
+
DefInt(SQLITE_IOERR_SHORT_READ);
|
| 799 |
+
DefInt(SQLITE_IOERR_WRITE);
|
| 800 |
+
DefInt(SQLITE_IOERR_FSYNC);
|
| 801 |
+
DefInt(SQLITE_IOERR_DIR_FSYNC);
|
| 802 |
+
DefInt(SQLITE_IOERR_TRUNCATE);
|
| 803 |
+
DefInt(SQLITE_IOERR_FSTAT);
|
| 804 |
+
DefInt(SQLITE_IOERR_UNLOCK);
|
| 805 |
+
DefInt(SQLITE_IOERR_RDLOCK);
|
| 806 |
+
DefInt(SQLITE_IOERR_DELETE);
|
| 807 |
+
DefInt(SQLITE_IOERR_BLOCKED);
|
| 808 |
+
DefInt(SQLITE_IOERR_NOMEM);
|
| 809 |
+
DefInt(SQLITE_IOERR_ACCESS);
|
| 810 |
+
DefInt(SQLITE_IOERR_CHECKRESERVEDLOCK);
|
| 811 |
+
DefInt(SQLITE_IOERR_LOCK);
|
| 812 |
+
DefInt(SQLITE_IOERR_CLOSE);
|
| 813 |
+
DefInt(SQLITE_IOERR_DIR_CLOSE);
|
| 814 |
+
DefInt(SQLITE_IOERR_SHMOPEN);
|
| 815 |
+
DefInt(SQLITE_IOERR_SHMSIZE);
|
| 816 |
+
DefInt(SQLITE_IOERR_SHMLOCK);
|
| 817 |
+
DefInt(SQLITE_IOERR_SHMMAP);
|
| 818 |
+
DefInt(SQLITE_IOERR_SEEK);
|
| 819 |
+
DefInt(SQLITE_IOERR_DELETE_NOENT);
|
| 820 |
+
DefInt(SQLITE_IOERR_MMAP);
|
| 821 |
+
DefInt(SQLITE_IOERR_GETTEMPPATH);
|
| 822 |
+
DefInt(SQLITE_IOERR_CONVPATH);
|
| 823 |
+
DefInt(SQLITE_IOERR_VNODE);
|
| 824 |
+
DefInt(SQLITE_IOERR_AUTH);
|
| 825 |
+
DefInt(SQLITE_IOERR_BEGIN_ATOMIC);
|
| 826 |
+
DefInt(SQLITE_IOERR_COMMIT_ATOMIC);
|
| 827 |
+
DefInt(SQLITE_IOERR_ROLLBACK_ATOMIC);
|
| 828 |
+
DefInt(SQLITE_IOERR_DATA);
|
| 829 |
+
DefInt(SQLITE_IOERR_CORRUPTFS);
|
| 830 |
+
DefInt(SQLITE_LOCKED_SHAREDCACHE);
|
| 831 |
+
DefInt(SQLITE_LOCKED_VTAB);
|
| 832 |
+
DefInt(SQLITE_BUSY_RECOVERY);
|
| 833 |
+
DefInt(SQLITE_BUSY_SNAPSHOT);
|
| 834 |
+
DefInt(SQLITE_BUSY_TIMEOUT);
|
| 835 |
+
DefInt(SQLITE_CANTOPEN_NOTEMPDIR);
|
| 836 |
+
DefInt(SQLITE_CANTOPEN_ISDIR);
|
| 837 |
+
DefInt(SQLITE_CANTOPEN_FULLPATH);
|
| 838 |
+
DefInt(SQLITE_CANTOPEN_CONVPATH);
|
| 839 |
+
//DefInt(SQLITE_CANTOPEN_DIRTYWAL)/*docs say not used*/;
|
| 840 |
+
DefInt(SQLITE_CANTOPEN_SYMLINK);
|
| 841 |
+
DefInt(SQLITE_CORRUPT_VTAB);
|
| 842 |
+
DefInt(SQLITE_CORRUPT_SEQUENCE);
|
| 843 |
+
DefInt(SQLITE_CORRUPT_INDEX);
|
| 844 |
+
DefInt(SQLITE_READONLY_RECOVERY);
|
| 845 |
+
DefInt(SQLITE_READONLY_CANTLOCK);
|
| 846 |
+
DefInt(SQLITE_READONLY_ROLLBACK);
|
| 847 |
+
DefInt(SQLITE_READONLY_DBMOVED);
|
| 848 |
+
DefInt(SQLITE_READONLY_CANTINIT);
|
| 849 |
+
DefInt(SQLITE_READONLY_DIRECTORY);
|
| 850 |
+
DefInt(SQLITE_ABORT_ROLLBACK);
|
| 851 |
+
DefInt(SQLITE_CONSTRAINT_CHECK);
|
| 852 |
+
DefInt(SQLITE_CONSTRAINT_COMMITHOOK);
|
| 853 |
+
DefInt(SQLITE_CONSTRAINT_FOREIGNKEY);
|
| 854 |
+
DefInt(SQLITE_CONSTRAINT_FUNCTION);
|
| 855 |
+
DefInt(SQLITE_CONSTRAINT_NOTNULL);
|
| 856 |
+
DefInt(SQLITE_CONSTRAINT_PRIMARYKEY);
|
| 857 |
+
DefInt(SQLITE_CONSTRAINT_TRIGGER);
|
| 858 |
+
DefInt(SQLITE_CONSTRAINT_UNIQUE);
|
| 859 |
+
DefInt(SQLITE_CONSTRAINT_VTAB);
|
| 860 |
+
DefInt(SQLITE_CONSTRAINT_ROWID);
|
| 861 |
+
DefInt(SQLITE_CONSTRAINT_PINNED);
|
| 862 |
+
DefInt(SQLITE_CONSTRAINT_DATATYPE);
|
| 863 |
+
DefInt(SQLITE_NOTICE_RECOVER_WAL);
|
| 864 |
+
DefInt(SQLITE_NOTICE_RECOVER_ROLLBACK);
|
| 865 |
+
DefInt(SQLITE_WARNING_AUTOINDEX);
|
| 866 |
+
DefInt(SQLITE_AUTH_USER);
|
| 867 |
+
DefInt(SQLITE_OK_LOAD_PERMANENTLY);
|
| 868 |
+
//DefInt(SQLITE_OK_SYMLINK) /* internal use only */;
|
| 869 |
+
} _DefGroup;
|
| 870 |
+
|
| 871 |
+
DefGroup(serialize){
|
| 872 |
+
DefInt(SQLITE_SERIALIZE_NOCOPY);
|
| 873 |
+
DefInt(SQLITE_DESERIALIZE_FREEONCLOSE);
|
| 874 |
+
DefInt(SQLITE_DESERIALIZE_READONLY);
|
| 875 |
+
DefInt(SQLITE_DESERIALIZE_RESIZEABLE);
|
| 876 |
+
} _DefGroup;
|
| 877 |
+
|
| 878 |
+
DefGroup(session){
|
| 879 |
+
#ifdef SQLITE_SESSION_CONFIG_STRMSIZE
|
| 880 |
+
DefInt(SQLITE_SESSION_CONFIG_STRMSIZE);
|
| 881 |
+
DefInt(SQLITE_SESSION_OBJCONFIG_SIZE);
|
| 882 |
+
#endif
|
| 883 |
+
} _DefGroup;
|
| 884 |
+
|
| 885 |
+
DefGroup(sqlite3Status){
|
| 886 |
+
DefInt(SQLITE_STATUS_MEMORY_USED);
|
| 887 |
+
DefInt(SQLITE_STATUS_PAGECACHE_USED);
|
| 888 |
+
DefInt(SQLITE_STATUS_PAGECACHE_OVERFLOW);
|
| 889 |
+
//DefInt(SQLITE_STATUS_SCRATCH_USED) /* NOT USED */;
|
| 890 |
+
//DefInt(SQLITE_STATUS_SCRATCH_OVERFLOW) /* NOT USED */;
|
| 891 |
+
DefInt(SQLITE_STATUS_MALLOC_SIZE);
|
| 892 |
+
DefInt(SQLITE_STATUS_PARSER_STACK);
|
| 893 |
+
DefInt(SQLITE_STATUS_PAGECACHE_SIZE);
|
| 894 |
+
//DefInt(SQLITE_STATUS_SCRATCH_SIZE) /* NOT USED */;
|
| 895 |
+
DefInt(SQLITE_STATUS_MALLOC_COUNT);
|
| 896 |
+
} _DefGroup;
|
| 897 |
+
|
| 898 |
+
DefGroup(stmtStatus){
|
| 899 |
+
DefInt(SQLITE_STMTSTATUS_FULLSCAN_STEP);
|
| 900 |
+
DefInt(SQLITE_STMTSTATUS_SORT);
|
| 901 |
+
DefInt(SQLITE_STMTSTATUS_AUTOINDEX);
|
| 902 |
+
DefInt(SQLITE_STMTSTATUS_VM_STEP);
|
| 903 |
+
DefInt(SQLITE_STMTSTATUS_REPREPARE);
|
| 904 |
+
DefInt(SQLITE_STMTSTATUS_RUN);
|
| 905 |
+
DefInt(SQLITE_STMTSTATUS_FILTER_MISS);
|
| 906 |
+
DefInt(SQLITE_STMTSTATUS_FILTER_HIT);
|
| 907 |
+
DefInt(SQLITE_STMTSTATUS_MEMUSED);
|
| 908 |
+
} _DefGroup;
|
| 909 |
+
|
| 910 |
+
DefGroup(syncFlags) {
|
| 911 |
+
DefInt(SQLITE_SYNC_NORMAL);
|
| 912 |
+
DefInt(SQLITE_SYNC_FULL);
|
| 913 |
+
DefInt(SQLITE_SYNC_DATAONLY);
|
| 914 |
+
} _DefGroup;
|
| 915 |
+
|
| 916 |
+
DefGroup(trace) {
|
| 917 |
+
DefInt(SQLITE_TRACE_STMT);
|
| 918 |
+
DefInt(SQLITE_TRACE_PROFILE);
|
| 919 |
+
DefInt(SQLITE_TRACE_ROW);
|
| 920 |
+
DefInt(SQLITE_TRACE_CLOSE);
|
| 921 |
+
} _DefGroup;
|
| 922 |
+
|
| 923 |
+
DefGroup(txnState){
|
| 924 |
+
DefInt(SQLITE_TXN_NONE);
|
| 925 |
+
DefInt(SQLITE_TXN_READ);
|
| 926 |
+
DefInt(SQLITE_TXN_WRITE);
|
| 927 |
+
} _DefGroup;
|
| 928 |
+
|
| 929 |
+
DefGroup(udfFlags) {
|
| 930 |
+
DefInt(SQLITE_DETERMINISTIC);
|
| 931 |
+
DefInt(SQLITE_DIRECTONLY);
|
| 932 |
+
DefInt(SQLITE_INNOCUOUS);
|
| 933 |
+
DefInt(SQLITE_SUBTYPE);
|
| 934 |
+
DefInt(SQLITE_RESULT_SUBTYPE);
|
| 935 |
+
} _DefGroup;
|
| 936 |
+
|
| 937 |
+
DefGroup(version) {
|
| 938 |
+
DefInt(SQLITE_VERSION_NUMBER);
|
| 939 |
+
DefStr(SQLITE_VERSION);
|
| 940 |
+
DefStr(SQLITE_SOURCE_ID);
|
| 941 |
+
} _DefGroup;
|
| 942 |
+
|
| 943 |
+
DefGroup(vtab) {
|
| 944 |
+
#if SQLITE_WASM_HAS_VTAB
|
| 945 |
+
DefInt(SQLITE_INDEX_SCAN_UNIQUE);
|
| 946 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_EQ);
|
| 947 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_GT);
|
| 948 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_LE);
|
| 949 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_LT);
|
| 950 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_GE);
|
| 951 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_MATCH);
|
| 952 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_LIKE);
|
| 953 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_GLOB);
|
| 954 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_REGEXP);
|
| 955 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_NE);
|
| 956 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_ISNOT);
|
| 957 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_ISNOTNULL);
|
| 958 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_ISNULL);
|
| 959 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_IS);
|
| 960 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_LIMIT);
|
| 961 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_OFFSET);
|
| 962 |
+
DefInt(SQLITE_INDEX_CONSTRAINT_FUNCTION);
|
| 963 |
+
DefInt(SQLITE_VTAB_CONSTRAINT_SUPPORT);
|
| 964 |
+
DefInt(SQLITE_VTAB_INNOCUOUS);
|
| 965 |
+
DefInt(SQLITE_VTAB_DIRECTONLY);
|
| 966 |
+
DefInt(SQLITE_VTAB_USES_ALL_SCHEMAS);
|
| 967 |
+
DefInt(SQLITE_ROLLBACK);
|
| 968 |
+
//DefInt(SQLITE_IGNORE); // Also used by sqlite3_authorizer() callback
|
| 969 |
+
DefInt(SQLITE_FAIL);
|
| 970 |
+
//DefInt(SQLITE_ABORT); // Also an error code
|
| 971 |
+
DefInt(SQLITE_REPLACE);
|
| 972 |
+
#endif /*SQLITE_WASM_HAS_VTAB*/
|
| 973 |
+
} _DefGroup;
|
| 974 |
+
|
| 975 |
+
#undef DefGroup
|
| 976 |
+
#undef DefStr
|
| 977 |
+
#undef DefInt
|
| 978 |
+
#undef _DefGroup
|
| 979 |
+
|
| 980 |
+
/*
|
| 981 |
+
** Emit an array of "StructBinder" struct descripions, which look
|
| 982 |
+
** like:
|
| 983 |
+
**
|
| 984 |
+
** {
|
| 985 |
+
** "name": "MyStruct",
|
| 986 |
+
** "sizeof": 16,
|
| 987 |
+
** "members": {
|
| 988 |
+
** "member1": {"offset": 0,"sizeof": 4,"signature": "i"},
|
| 989 |
+
** "member2": {"offset": 4,"sizeof": 4,"signature": "p"},
|
| 990 |
+
** "member3": {"offset": 8,"sizeof": 8,"signature": "j"}
|
| 991 |
+
** }
|
| 992 |
+
** }
|
| 993 |
+
**
|
| 994 |
+
** Detailed documentation for those bits are in the docs for the
|
| 995 |
+
** Jaccwabyt JS-side component.
|
| 996 |
+
*/
|
| 997 |
+
|
| 998 |
+
/** Macros for emitting StructBinder description. */
|
| 999 |
+
#define StructBinder__(TYPE) \
|
| 1000 |
+
n = 0; \
|
| 1001 |
+
outf("%s{", (nStruct++ ? ", " : "")); \
|
| 1002 |
+
out("\"name\": \"" # TYPE "\","); \
|
| 1003 |
+
outf("\"sizeof\": %d", (int)sizeof(TYPE)); \
|
| 1004 |
+
out(",\"members\": {");
|
| 1005 |
+
#define StructBinder_(T) StructBinder__(T)
|
| 1006 |
+
/** ^^^ indirection needed to expand CurrentStruct */
|
| 1007 |
+
#define StructBinder StructBinder_(CurrentStruct)
|
| 1008 |
+
#define _StructBinder CloseBrace(2)
|
| 1009 |
+
#define M(MEMBER,SIG) \
|
| 1010 |
+
outf("%s\"%s\": " \
|
| 1011 |
+
"{\"offset\":%d,\"sizeof\": %d,\"signature\":\"%s\"}", \
|
| 1012 |
+
(n++ ? ", " : ""), #MEMBER, \
|
| 1013 |
+
(int)offsetof(CurrentStruct,MEMBER), \
|
| 1014 |
+
(int)sizeof(((CurrentStruct*)0)->MEMBER), \
|
| 1015 |
+
SIG)
|
| 1016 |
+
|
| 1017 |
+
nStruct = 0;
|
| 1018 |
+
out(", \"structs\": ["); {
|
| 1019 |
+
|
| 1020 |
+
#define CurrentStruct sqlite3_vfs
|
| 1021 |
+
StructBinder {
|
| 1022 |
+
M(iVersion, "i");
|
| 1023 |
+
M(szOsFile, "i");
|
| 1024 |
+
M(mxPathname, "i");
|
| 1025 |
+
M(pNext, "p");
|
| 1026 |
+
M(zName, "s");
|
| 1027 |
+
M(pAppData, "p");
|
| 1028 |
+
M(xOpen, "i(pppip)");
|
| 1029 |
+
M(xDelete, "i(ppi)");
|
| 1030 |
+
M(xAccess, "i(ppip)");
|
| 1031 |
+
M(xFullPathname, "i(ppip)");
|
| 1032 |
+
M(xDlOpen, "p(pp)");
|
| 1033 |
+
M(xDlError, "p(pip)");
|
| 1034 |
+
M(xDlSym, "p()");
|
| 1035 |
+
M(xDlClose, "v(pp)");
|
| 1036 |
+
M(xRandomness, "i(pip)");
|
| 1037 |
+
M(xSleep, "i(pi)");
|
| 1038 |
+
M(xCurrentTime, "i(pp)");
|
| 1039 |
+
M(xGetLastError, "i(pip)");
|
| 1040 |
+
M(xCurrentTimeInt64, "i(pp)");
|
| 1041 |
+
M(xSetSystemCall, "i(ppp)");
|
| 1042 |
+
M(xGetSystemCall, "p(pp)");
|
| 1043 |
+
M(xNextSystemCall, "p(pp)");
|
| 1044 |
+
} _StructBinder;
|
| 1045 |
+
#undef CurrentStruct
|
| 1046 |
+
|
| 1047 |
+
#define CurrentStruct sqlite3_io_methods
|
| 1048 |
+
StructBinder {
|
| 1049 |
+
M(iVersion, "i");
|
| 1050 |
+
M(xClose, "i(p)");
|
| 1051 |
+
M(xRead, "i(ppij)");
|
| 1052 |
+
M(xWrite, "i(ppij)");
|
| 1053 |
+
M(xTruncate, "i(pj)");
|
| 1054 |
+
M(xSync, "i(pi)");
|
| 1055 |
+
M(xFileSize, "i(pp)");
|
| 1056 |
+
M(xLock, "i(pi)");
|
| 1057 |
+
M(xUnlock, "i(pi)");
|
| 1058 |
+
M(xCheckReservedLock, "i(pp)");
|
| 1059 |
+
M(xFileControl, "i(pip)");
|
| 1060 |
+
M(xSectorSize, "i(p)");
|
| 1061 |
+
M(xDeviceCharacteristics, "i(p)");
|
| 1062 |
+
M(xShmMap, "i(piiip)");
|
| 1063 |
+
M(xShmLock, "i(piii)");
|
| 1064 |
+
M(xShmBarrier, "v(p)");
|
| 1065 |
+
M(xShmUnmap, "i(pi)");
|
| 1066 |
+
M(xFetch, "i(pjip)");
|
| 1067 |
+
M(xUnfetch, "i(pjp)");
|
| 1068 |
+
} _StructBinder;
|
| 1069 |
+
#undef CurrentStruct
|
| 1070 |
+
|
| 1071 |
+
#define CurrentStruct sqlite3_file
|
| 1072 |
+
StructBinder {
|
| 1073 |
+
M(pMethods, "p");
|
| 1074 |
+
} _StructBinder;
|
| 1075 |
+
#undef CurrentStruct
|
| 1076 |
+
|
| 1077 |
+
#define CurrentStruct sqlite3_kvvfs_methods
|
| 1078 |
+
StructBinder {
|
| 1079 |
+
M(xRead, "i(sspi)");
|
| 1080 |
+
M(xWrite, "i(sss)");
|
| 1081 |
+
M(xDelete, "i(ss)");
|
| 1082 |
+
M(nKeySize, "i");
|
| 1083 |
+
} _StructBinder;
|
| 1084 |
+
#undef CurrentStruct
|
| 1085 |
+
|
| 1086 |
+
|
| 1087 |
+
#if SQLITE_WASM_HAS_VTAB
|
| 1088 |
+
#define CurrentStruct sqlite3_vtab
|
| 1089 |
+
StructBinder {
|
| 1090 |
+
M(pModule, "p");
|
| 1091 |
+
M(nRef, "i");
|
| 1092 |
+
M(zErrMsg, "p");
|
| 1093 |
+
} _StructBinder;
|
| 1094 |
+
#undef CurrentStruct
|
| 1095 |
+
|
| 1096 |
+
#define CurrentStruct sqlite3_vtab_cursor
|
| 1097 |
+
StructBinder {
|
| 1098 |
+
M(pVtab, "p");
|
| 1099 |
+
} _StructBinder;
|
| 1100 |
+
#undef CurrentStruct
|
| 1101 |
+
|
| 1102 |
+
#define CurrentStruct sqlite3_module
|
| 1103 |
+
StructBinder {
|
| 1104 |
+
M(iVersion, "i");
|
| 1105 |
+
M(xCreate, "i(ppippp)");
|
| 1106 |
+
M(xConnect, "i(ppippp)");
|
| 1107 |
+
M(xBestIndex, "i(pp)");
|
| 1108 |
+
M(xDisconnect, "i(p)");
|
| 1109 |
+
M(xDestroy, "i(p)");
|
| 1110 |
+
M(xOpen, "i(pp)");
|
| 1111 |
+
M(xClose, "i(p)");
|
| 1112 |
+
M(xFilter, "i(pisip)");
|
| 1113 |
+
M(xNext, "i(p)");
|
| 1114 |
+
M(xEof, "i(p)");
|
| 1115 |
+
M(xColumn, "i(ppi)");
|
| 1116 |
+
M(xRowid, "i(pp)");
|
| 1117 |
+
M(xUpdate, "i(pipp)");
|
| 1118 |
+
M(xBegin, "i(p)");
|
| 1119 |
+
M(xSync, "i(p)");
|
| 1120 |
+
M(xCommit, "i(p)");
|
| 1121 |
+
M(xRollback, "i(p)");
|
| 1122 |
+
M(xFindFunction, "i(pispp)");
|
| 1123 |
+
M(xRename, "i(ps)");
|
| 1124 |
+
// ^^^ v1. v2+ follows...
|
| 1125 |
+
M(xSavepoint, "i(pi)");
|
| 1126 |
+
M(xRelease, "i(pi)");
|
| 1127 |
+
M(xRollbackTo, "i(pi)");
|
| 1128 |
+
// ^^^ v2. v3+ follows...
|
| 1129 |
+
M(xShadowName, "i(s)");
|
| 1130 |
+
} _StructBinder;
|
| 1131 |
+
#undef CurrentStruct
|
| 1132 |
+
|
| 1133 |
+
/**
|
| 1134 |
+
** Workaround: in order to map the various inner structs from
|
| 1135 |
+
** sqlite3_index_info, we have to uplift those into constructs we
|
| 1136 |
+
** can access by type name. These structs _must_ match their
|
| 1137 |
+
** in-sqlite3_index_info counterparts byte for byte.
|
| 1138 |
+
*/
|
| 1139 |
+
typedef struct {
|
| 1140 |
+
int iColumn;
|
| 1141 |
+
unsigned char op;
|
| 1142 |
+
unsigned char usable;
|
| 1143 |
+
int iTermOffset;
|
| 1144 |
+
} sqlite3_index_constraint;
|
| 1145 |
+
typedef struct {
|
| 1146 |
+
int iColumn;
|
| 1147 |
+
unsigned char desc;
|
| 1148 |
+
} sqlite3_index_orderby;
|
| 1149 |
+
typedef struct {
|
| 1150 |
+
int argvIndex;
|
| 1151 |
+
unsigned char omit;
|
| 1152 |
+
} sqlite3_index_constraint_usage;
|
| 1153 |
+
{ /* Validate that the above struct sizeof()s match
|
| 1154 |
+
** expectations. We could improve upon this by
|
| 1155 |
+
** checking the offsetof() for each member. */
|
| 1156 |
+
const sqlite3_index_info siiCheck;
|
| 1157 |
+
#define IndexSzCheck(T,M) \
|
| 1158 |
+
(sizeof(T) == sizeof(*siiCheck.M))
|
| 1159 |
+
if(!IndexSzCheck(sqlite3_index_constraint,aConstraint)
|
| 1160 |
+
|| !IndexSzCheck(sqlite3_index_orderby,aOrderBy)
|
| 1161 |
+
|| !IndexSzCheck(sqlite3_index_constraint_usage,aConstraintUsage)){
|
| 1162 |
+
assert(!"sizeof mismatch in sqlite3_index_... struct(s)");
|
| 1163 |
+
return 0;
|
| 1164 |
+
}
|
| 1165 |
+
#undef IndexSzCheck
|
| 1166 |
+
}
|
| 1167 |
+
|
| 1168 |
+
#define CurrentStruct sqlite3_index_constraint
|
| 1169 |
+
StructBinder {
|
| 1170 |
+
M(iColumn, "i");
|
| 1171 |
+
M(op, "C");
|
| 1172 |
+
M(usable, "C");
|
| 1173 |
+
M(iTermOffset, "i");
|
| 1174 |
+
} _StructBinder;
|
| 1175 |
+
#undef CurrentStruct
|
| 1176 |
+
|
| 1177 |
+
#define CurrentStruct sqlite3_index_orderby
|
| 1178 |
+
StructBinder {
|
| 1179 |
+
M(iColumn, "i");
|
| 1180 |
+
M(desc, "C");
|
| 1181 |
+
} _StructBinder;
|
| 1182 |
+
#undef CurrentStruct
|
| 1183 |
+
|
| 1184 |
+
#define CurrentStruct sqlite3_index_constraint_usage
|
| 1185 |
+
StructBinder {
|
| 1186 |
+
M(argvIndex, "i");
|
| 1187 |
+
M(omit, "C");
|
| 1188 |
+
} _StructBinder;
|
| 1189 |
+
#undef CurrentStruct
|
| 1190 |
+
|
| 1191 |
+
#define CurrentStruct sqlite3_index_info
|
| 1192 |
+
StructBinder {
|
| 1193 |
+
M(nConstraint, "i");
|
| 1194 |
+
M(aConstraint, "p");
|
| 1195 |
+
M(nOrderBy, "i");
|
| 1196 |
+
M(aOrderBy, "p");
|
| 1197 |
+
M(aConstraintUsage, "p");
|
| 1198 |
+
M(idxNum, "i");
|
| 1199 |
+
M(idxStr, "p");
|
| 1200 |
+
M(needToFreeIdxStr, "i");
|
| 1201 |
+
M(orderByConsumed, "i");
|
| 1202 |
+
M(estimatedCost, "d");
|
| 1203 |
+
M(estimatedRows, "j");
|
| 1204 |
+
M(idxFlags, "i");
|
| 1205 |
+
M(colUsed, "j");
|
| 1206 |
+
} _StructBinder;
|
| 1207 |
+
#undef CurrentStruct
|
| 1208 |
+
|
| 1209 |
+
#endif /*SQLITE_WASM_HAS_VTAB*/
|
| 1210 |
+
|
| 1211 |
+
#if SQLITE_WASM_ENABLE_C_TESTS
|
| 1212 |
+
#define CurrentStruct WasmTestStruct
|
| 1213 |
+
StructBinder {
|
| 1214 |
+
M(v4, "i");
|
| 1215 |
+
M(cstr, "s");
|
| 1216 |
+
M(ppV, "p");
|
| 1217 |
+
M(v8, "j");
|
| 1218 |
+
M(xFunc, "v(p)");
|
| 1219 |
+
} _StructBinder;
|
| 1220 |
+
#undef CurrentStruct
|
| 1221 |
+
#endif /*SQLITE_WASM_ENABLE_C_TESTS*/
|
| 1222 |
+
|
| 1223 |
+
} out( "]"/*structs*/);
|
| 1224 |
+
|
| 1225 |
+
out("}"/*top-level object*/);
|
| 1226 |
+
*zPos = 0;
|
| 1227 |
+
aBuffer[0] = '{'/*end of the race-condition workaround*/;
|
| 1228 |
+
return aBuffer;
|
| 1229 |
+
#undef StructBinder
|
| 1230 |
+
#undef StructBinder_
|
| 1231 |
+
#undef StructBinder__
|
| 1232 |
+
#undef M
|
| 1233 |
+
#undef _StructBinder
|
| 1234 |
+
#undef CloseBrace
|
| 1235 |
+
#undef out
|
| 1236 |
+
#undef outf
|
| 1237 |
+
#undef lenCheck
|
| 1238 |
+
}
|
| 1239 |
+
|
| 1240 |
+
/*
|
| 1241 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1242 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1243 |
+
**
|
| 1244 |
+
** This function invokes the xDelete method of the given VFS (or the
|
| 1245 |
+
** default VFS if pVfs is NULL), passing on the given filename. If
|
| 1246 |
+
** zName is NULL, no default VFS is found, or it has no xDelete
|
| 1247 |
+
** method, SQLITE_MISUSE is returned, else the result of the xDelete()
|
| 1248 |
+
** call is returned.
|
| 1249 |
+
*/
|
| 1250 |
+
SQLITE_WASM_EXPORT
|
| 1251 |
+
int sqlite3__wasm_vfs_unlink(sqlite3_vfs *pVfs, const char *zName){
|
| 1252 |
+
int rc = SQLITE_MISUSE /* ??? */;
|
| 1253 |
+
if( 0==pVfs && 0!=zName ) pVfs = sqlite3_vfs_find(0);
|
| 1254 |
+
if( zName && pVfs && pVfs->xDelete ){
|
| 1255 |
+
rc = pVfs->xDelete(pVfs, zName, 1);
|
| 1256 |
+
}
|
| 1257 |
+
return rc;
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
/*
|
| 1261 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1262 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1263 |
+
**
|
| 1264 |
+
** Returns a pointer to the given DB's VFS for the given DB name,
|
| 1265 |
+
** defaulting to "main" if zDbName is 0. Returns 0 if no db with the
|
| 1266 |
+
** given name is open.
|
| 1267 |
+
*/
|
| 1268 |
+
SQLITE_WASM_EXPORT
|
| 1269 |
+
sqlite3_vfs * sqlite3__wasm_db_vfs(sqlite3 *pDb, const char *zDbName){
|
| 1270 |
+
sqlite3_vfs * pVfs = 0;
|
| 1271 |
+
sqlite3_file_control(pDb, zDbName ? zDbName : "main",
|
| 1272 |
+
SQLITE_FCNTL_VFS_POINTER, &pVfs);
|
| 1273 |
+
return pVfs;
|
| 1274 |
+
}
|
| 1275 |
+
|
| 1276 |
+
/*
|
| 1277 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1278 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1279 |
+
**
|
| 1280 |
+
** This function resets the given db pointer's database as described at
|
| 1281 |
+
**
|
| 1282 |
+
** https://sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigresetdatabase
|
| 1283 |
+
**
|
| 1284 |
+
** But beware: virtual tables destroyed that way do not have their
|
| 1285 |
+
** xDestroy() called, so will leak if they require that function for
|
| 1286 |
+
** proper cleanup.
|
| 1287 |
+
**
|
| 1288 |
+
** Returns 0 on success, an SQLITE_xxx code on error. Returns
|
| 1289 |
+
** SQLITE_MISUSE if pDb is NULL.
|
| 1290 |
+
*/
|
| 1291 |
+
SQLITE_WASM_EXPORT
|
| 1292 |
+
int sqlite3__wasm_db_reset(sqlite3 *pDb){
|
| 1293 |
+
int rc = SQLITE_MISUSE;
|
| 1294 |
+
if( pDb ){
|
| 1295 |
+
sqlite3_table_column_metadata(pDb, "main", 0, 0, 0, 0, 0, 0, 0);
|
| 1296 |
+
rc = sqlite3_db_config(pDb, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
|
| 1297 |
+
if( 0==rc ){
|
| 1298 |
+
rc = sqlite3_exec(pDb, "VACUUM", 0, 0, 0);
|
| 1299 |
+
sqlite3_db_config(pDb, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
|
| 1300 |
+
}
|
| 1301 |
+
}
|
| 1302 |
+
return rc;
|
| 1303 |
+
}
|
| 1304 |
+
|
| 1305 |
+
/*
|
| 1306 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1307 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1308 |
+
**
|
| 1309 |
+
** Uses the given database's VFS xRead to stream the db file's
|
| 1310 |
+
** contents out to the given callback. The callback gets a single
|
| 1311 |
+
** chunk of size n (its 2nd argument) on each call and must return 0
|
| 1312 |
+
** on success, non-0 on error. This function returns 0 on success,
|
| 1313 |
+
** SQLITE_NOTFOUND if no db is open, or propagates any other non-0
|
| 1314 |
+
** code from the callback. Note that this is not thread-friendly: it
|
| 1315 |
+
** expects that it will be the only thread reading the db file and
|
| 1316 |
+
** takes no measures to ensure that is the case.
|
| 1317 |
+
**
|
| 1318 |
+
** This implementation appears to work fine, but
|
| 1319 |
+
** sqlite3__wasm_db_serialize() is arguably the better way to achieve
|
| 1320 |
+
** this.
|
| 1321 |
+
*/
|
| 1322 |
+
SQLITE_WASM_EXPORT
|
| 1323 |
+
int sqlite3__wasm_db_export_chunked( sqlite3* pDb,
|
| 1324 |
+
int (*xCallback)(unsigned const char *zOut, int n) ){
|
| 1325 |
+
sqlite3_int64 nSize = 0;
|
| 1326 |
+
sqlite3_int64 nPos = 0;
|
| 1327 |
+
sqlite3_file * pFile = 0;
|
| 1328 |
+
unsigned char buf[1024 * 8];
|
| 1329 |
+
int nBuf = (int)sizeof(buf);
|
| 1330 |
+
int rc = pDb
|
| 1331 |
+
? sqlite3_file_control(pDb, "main",
|
| 1332 |
+
SQLITE_FCNTL_FILE_POINTER, &pFile)
|
| 1333 |
+
: SQLITE_NOTFOUND;
|
| 1334 |
+
if( rc ) return rc;
|
| 1335 |
+
rc = pFile->pMethods->xFileSize(pFile, &nSize);
|
| 1336 |
+
if( rc ) return rc;
|
| 1337 |
+
if(nSize % nBuf){
|
| 1338 |
+
/* DB size is not an even multiple of the buffer size. Reduce
|
| 1339 |
+
** buffer size so that we do not unduly inflate the db size
|
| 1340 |
+
** with zero-padding when exporting. */
|
| 1341 |
+
if(0 == nSize % 4096) nBuf = 4096;
|
| 1342 |
+
else if(0 == nSize % 2048) nBuf = 2048;
|
| 1343 |
+
else if(0 == nSize % 1024) nBuf = 1024;
|
| 1344 |
+
else nBuf = 512;
|
| 1345 |
+
}
|
| 1346 |
+
for( ; 0==rc && nPos<nSize; nPos += nBuf ){
|
| 1347 |
+
rc = pFile->pMethods->xRead(pFile, buf, nBuf, nPos);
|
| 1348 |
+
if( SQLITE_IOERR_SHORT_READ == rc ){
|
| 1349 |
+
rc = (nPos + nBuf) < nSize ? rc : 0/*assume EOF*/;
|
| 1350 |
+
}
|
| 1351 |
+
if( 0==rc ) rc = xCallback(buf, nBuf);
|
| 1352 |
+
}
|
| 1353 |
+
return rc;
|
| 1354 |
+
}
|
| 1355 |
+
|
| 1356 |
+
/*
|
| 1357 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1358 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1359 |
+
**
|
| 1360 |
+
** A proxy for sqlite3_serialize() which serializes the schema zSchema
|
| 1361 |
+
** of pDb, placing the serialized output in pOut and nOut. nOut may be
|
| 1362 |
+
** NULL. If zSchema is NULL then "main" is assumed. If pDb or pOut are
|
| 1363 |
+
** NULL then SQLITE_MISUSE is returned. If allocation of the
|
| 1364 |
+
** serialized copy fails, SQLITE_NOMEM is returned. On success, 0 is
|
| 1365 |
+
** returned and `*pOut` will contain a pointer to the memory unless
|
| 1366 |
+
** mFlags includes SQLITE_SERIALIZE_NOCOPY and the database has no
|
| 1367 |
+
** contiguous memory representation, in which case `*pOut` will be
|
| 1368 |
+
** NULL but 0 will be returned.
|
| 1369 |
+
**
|
| 1370 |
+
** If `*pOut` is not NULL, the caller is responsible for passing it to
|
| 1371 |
+
** sqlite3_free() to free it.
|
| 1372 |
+
*/
|
| 1373 |
+
SQLITE_WASM_EXPORT
|
| 1374 |
+
int sqlite3__wasm_db_serialize( sqlite3 *pDb, const char *zSchema,
|
| 1375 |
+
unsigned char **pOut,
|
| 1376 |
+
sqlite3_int64 *nOut, unsigned int mFlags ){
|
| 1377 |
+
unsigned char * z;
|
| 1378 |
+
if( !pDb || !pOut ) return SQLITE_MISUSE;
|
| 1379 |
+
if( nOut ) *nOut = 0;
|
| 1380 |
+
z = sqlite3_serialize(pDb, zSchema ? zSchema : "main", nOut, mFlags);
|
| 1381 |
+
if( z || (SQLITE_SERIALIZE_NOCOPY & mFlags) ){
|
| 1382 |
+
*pOut = z;
|
| 1383 |
+
return 0;
|
| 1384 |
+
}else{
|
| 1385 |
+
return SQLITE_NOMEM;
|
| 1386 |
+
}
|
| 1387 |
+
}
|
| 1388 |
+
|
| 1389 |
+
/*
|
| 1390 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1391 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1392 |
+
**
|
| 1393 |
+
** ACHTUNG: it was discovered on 2023-08-11 that, with SQLITE_DEBUG,
|
| 1394 |
+
** this function's out-of-scope use of the sqlite3_vfs/file/io_methods
|
| 1395 |
+
** APIs leads to triggering of assertions in the core library. Its use
|
| 1396 |
+
** is now deprecated and VFS-specific APIs for importing files need to
|
| 1397 |
+
** be found to replace it. sqlite3__wasm_posix_create_file() is
|
| 1398 |
+
** suitable for the "unix" family of VFSes.
|
| 1399 |
+
**
|
| 1400 |
+
** Creates a new file using the I/O API of the given VFS, containing
|
| 1401 |
+
** the given number of bytes of the given data. If the file exists, it
|
| 1402 |
+
** is truncated to the given length and populated with the given
|
| 1403 |
+
** data.
|
| 1404 |
+
**
|
| 1405 |
+
** This function exists so that we can implement the equivalent of
|
| 1406 |
+
** Emscripten's FS.createDataFile() in a VFS-agnostic way. This
|
| 1407 |
+
** functionality is intended for use in uploading database files.
|
| 1408 |
+
**
|
| 1409 |
+
** Not all VFSes support this functionality, e.g. the "kvvfs" does
|
| 1410 |
+
** not.
|
| 1411 |
+
**
|
| 1412 |
+
** If pVfs is NULL, sqlite3_vfs_find(0) is used.
|
| 1413 |
+
**
|
| 1414 |
+
** If zFile is NULL, pVfs is NULL (and sqlite3_vfs_find(0) returns
|
| 1415 |
+
** NULL), or nData is negative, SQLITE_MISUSE are returned.
|
| 1416 |
+
**
|
| 1417 |
+
** On success, it creates a new file with the given name, populated
|
| 1418 |
+
** with the fist nData bytes of pData. If pData is NULL, the file is
|
| 1419 |
+
** created and/or truncated to nData bytes.
|
| 1420 |
+
**
|
| 1421 |
+
** Whether or not directory components of zFilename are created
|
| 1422 |
+
** automatically or not is unspecified: that detail is left to the
|
| 1423 |
+
** VFS. The "opfs" VFS, for example, creates them.
|
| 1424 |
+
**
|
| 1425 |
+
** If an error happens while populating or truncating the file, the
|
| 1426 |
+
** target file will be deleted (if needed) if this function created
|
| 1427 |
+
** it. If this function did not create it, it is not deleted but may
|
| 1428 |
+
** be left in an undefined state.
|
| 1429 |
+
**
|
| 1430 |
+
** Returns 0 on success. On error, it returns a code described above
|
| 1431 |
+
** or propagates a code from one of the I/O methods.
|
| 1432 |
+
**
|
| 1433 |
+
** Design note: nData is an integer, instead of int64, for WASM
|
| 1434 |
+
** portability, so that the API can still work in builds where BigInt
|
| 1435 |
+
** support is disabled or unavailable.
|
| 1436 |
+
*/
|
| 1437 |
+
SQLITE_WASM_EXPORT
|
| 1438 |
+
int sqlite3__wasm_vfs_create_file( sqlite3_vfs *pVfs,
|
| 1439 |
+
const char *zFilename,
|
| 1440 |
+
const unsigned char * pData,
|
| 1441 |
+
int nData ){
|
| 1442 |
+
int rc;
|
| 1443 |
+
sqlite3_file *pFile = 0;
|
| 1444 |
+
sqlite3_io_methods const *pIo;
|
| 1445 |
+
const int openFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
|
| 1446 |
+
#if 0 && defined(SQLITE_DEBUG)
|
| 1447 |
+
| SQLITE_OPEN_MAIN_JOURNAL
|
| 1448 |
+
/* ^^^^ This is for testing a horrible workaround to avoid
|
| 1449 |
+
triggering a specific assert() in os_unix.c:unixOpen(). Please
|
| 1450 |
+
do not enable this in real builds. */
|
| 1451 |
+
#endif
|
| 1452 |
+
;
|
| 1453 |
+
int flagsOut = 0;
|
| 1454 |
+
int fileExisted = 0;
|
| 1455 |
+
int doUnlock = 0;
|
| 1456 |
+
const unsigned char *pPos = pData;
|
| 1457 |
+
const int blockSize = 512
|
| 1458 |
+
/* Because we are using pFile->pMethods->xWrite() for writing, and
|
| 1459 |
+
** it may have a buffer limit related to sqlite3's pager size, we
|
| 1460 |
+
** conservatively write in 512-byte blocks (smallest page
|
| 1461 |
+
** size). */;
|
| 1462 |
+
//fprintf(stderr, "pVfs=%p, zFilename=%s, nData=%d\n", pVfs, zFilename, nData);
|
| 1463 |
+
if( !pVfs ) pVfs = sqlite3_vfs_find(0);
|
| 1464 |
+
if( !pVfs || !zFilename || nData<0 ) return SQLITE_MISUSE;
|
| 1465 |
+
pVfs->xAccess(pVfs, zFilename, SQLITE_ACCESS_EXISTS, &fileExisted);
|
| 1466 |
+
rc = sqlite3OsOpenMalloc(pVfs, zFilename, &pFile, openFlags, &flagsOut);
|
| 1467 |
+
#if 0
|
| 1468 |
+
# define RC fprintf(stderr,"create_file(%s,%s) @%d rc=%d\n", \
|
| 1469 |
+
pVfs->zName, zFilename, __LINE__, rc);
|
| 1470 |
+
#else
|
| 1471 |
+
# define RC
|
| 1472 |
+
#endif
|
| 1473 |
+
RC;
|
| 1474 |
+
if(rc) return rc;
|
| 1475 |
+
pIo = pFile->pMethods;
|
| 1476 |
+
if( pIo->xLock ) {
|
| 1477 |
+
/* We need xLock() in order to accommodate the OPFS VFS, as it
|
| 1478 |
+
** obtains a writeable handle via the lock operation and releases
|
| 1479 |
+
** it in xUnlock(). If we don't do those here, we have to add code
|
| 1480 |
+
** to the VFS to account check whether it was locked before
|
| 1481 |
+
** xFileSize(), xTruncate(), and the like, and release the lock
|
| 1482 |
+
** only if it was unlocked when the op was started. */
|
| 1483 |
+
rc = pIo->xLock(pFile, SQLITE_LOCK_EXCLUSIVE);
|
| 1484 |
+
RC;
|
| 1485 |
+
doUnlock = 0==rc;
|
| 1486 |
+
}
|
| 1487 |
+
if( 0==rc ){
|
| 1488 |
+
rc = pIo->xTruncate(pFile, nData);
|
| 1489 |
+
RC;
|
| 1490 |
+
}
|
| 1491 |
+
if( 0==rc && 0!=pData && nData>0 ){
|
| 1492 |
+
while( 0==rc && nData>0 ){
|
| 1493 |
+
const int n = nData>=blockSize ? blockSize : nData;
|
| 1494 |
+
rc = pIo->xWrite(pFile, pPos, n, (sqlite3_int64)(pPos - pData));
|
| 1495 |
+
RC;
|
| 1496 |
+
nData -= n;
|
| 1497 |
+
pPos += n;
|
| 1498 |
+
}
|
| 1499 |
+
if( 0==rc && nData>0 ){
|
| 1500 |
+
assert( nData<blockSize );
|
| 1501 |
+
rc = pIo->xWrite(pFile, pPos, nData,
|
| 1502 |
+
(sqlite3_int64)(pPos - pData));
|
| 1503 |
+
RC;
|
| 1504 |
+
}
|
| 1505 |
+
}
|
| 1506 |
+
if( pIo->xUnlock && doUnlock!=0 ){
|
| 1507 |
+
pIo->xUnlock(pFile, SQLITE_LOCK_NONE);
|
| 1508 |
+
}
|
| 1509 |
+
pIo->xClose(pFile);
|
| 1510 |
+
if( rc!=0 && 0==fileExisted ){
|
| 1511 |
+
pVfs->xDelete(pVfs, zFilename, 1);
|
| 1512 |
+
}
|
| 1513 |
+
RC;
|
| 1514 |
+
#undef RC
|
| 1515 |
+
return rc;
|
| 1516 |
+
}
|
| 1517 |
+
|
| 1518 |
+
/**
|
| 1519 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1520 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1521 |
+
**
|
| 1522 |
+
** Creates or overwrites a file using the POSIX file API,
|
| 1523 |
+
** i.e. Emscripten's virtual filesystem. Creates or truncates
|
| 1524 |
+
** zFilename, appends pData bytes to it, and returns 0 on success or
|
| 1525 |
+
** SQLITE_IOERR on error.
|
| 1526 |
+
*/
|
| 1527 |
+
SQLITE_WASM_EXPORT
|
| 1528 |
+
int sqlite3__wasm_posix_create_file( const char *zFilename,
|
| 1529 |
+
const unsigned char * pData,
|
| 1530 |
+
int nData ){
|
| 1531 |
+
int rc;
|
| 1532 |
+
FILE * pFile = 0;
|
| 1533 |
+
int fileExisted = 0;
|
| 1534 |
+
size_t nWrote = 1;
|
| 1535 |
+
|
| 1536 |
+
if( !zFilename || nData<0 || (pData==0 && nData>0) ) return SQLITE_MISUSE;
|
| 1537 |
+
pFile = fopen(zFilename, "w");
|
| 1538 |
+
if( 0==pFile ) return SQLITE_IOERR;
|
| 1539 |
+
if( nData>0 ){
|
| 1540 |
+
nWrote = fwrite(pData, (size_t)nData, 1, pFile);
|
| 1541 |
+
}
|
| 1542 |
+
fclose(pFile);
|
| 1543 |
+
return 1==nWrote ? 0 : SQLITE_IOERR;
|
| 1544 |
+
}
|
| 1545 |
+
|
| 1546 |
+
/*
|
| 1547 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1548 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1549 |
+
**
|
| 1550 |
+
** Allocates sqlite3KvvfsMethods.nKeySize bytes from
|
| 1551 |
+
** sqlite3__wasm_pstack_alloc() and returns 0 if that allocation fails,
|
| 1552 |
+
** else it passes that string to kvstorageMakeKey() and returns a
|
| 1553 |
+
** NUL-terminated pointer to that string. It is up to the caller to
|
| 1554 |
+
** use sqlite3__wasm_pstack_restore() to free the returned pointer.
|
| 1555 |
+
*/
|
| 1556 |
+
SQLITE_WASM_EXPORT
|
| 1557 |
+
char * sqlite3__wasm_kvvfsMakeKeyOnPstack(const char *zClass,
|
| 1558 |
+
const char *zKeyIn){
|
| 1559 |
+
assert(sqlite3KvvfsMethods.nKeySize>24);
|
| 1560 |
+
char *zKeyOut =
|
| 1561 |
+
(char *)sqlite3__wasm_pstack_alloc(sqlite3KvvfsMethods.nKeySize);
|
| 1562 |
+
if(zKeyOut){
|
| 1563 |
+
kvstorageMakeKey(zClass, zKeyIn, zKeyOut);
|
| 1564 |
+
}
|
| 1565 |
+
return zKeyOut;
|
| 1566 |
+
}
|
| 1567 |
+
|
| 1568 |
+
/*
|
| 1569 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1570 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1571 |
+
**
|
| 1572 |
+
** Returns the pointer to the singleton object which holds the kvvfs
|
| 1573 |
+
** I/O methods and associated state.
|
| 1574 |
+
*/
|
| 1575 |
+
SQLITE_WASM_EXPORT
|
| 1576 |
+
sqlite3_kvvfs_methods * sqlite3__wasm_kvvfs_methods(void){
|
| 1577 |
+
return &sqlite3KvvfsMethods;
|
| 1578 |
+
}
|
| 1579 |
+
|
| 1580 |
+
#if SQLITE_WASM_HAS_VTAB
|
| 1581 |
+
/*
|
| 1582 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1583 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1584 |
+
**
|
| 1585 |
+
** This is a proxy for the variadic sqlite3_vtab_config() which passes
|
| 1586 |
+
** its argument on, or not, to sqlite3_vtab_config(), depending on the
|
| 1587 |
+
** value of its 2nd argument. Returns the result of
|
| 1588 |
+
** sqlite3_vtab_config(), or SQLITE_MISUSE if the 2nd arg is not a
|
| 1589 |
+
** valid value.
|
| 1590 |
+
*/
|
| 1591 |
+
SQLITE_WASM_EXPORT
|
| 1592 |
+
int sqlite3__wasm_vtab_config(sqlite3 *pDb, int op, int arg){
|
| 1593 |
+
switch(op){
|
| 1594 |
+
case SQLITE_VTAB_DIRECTONLY:
|
| 1595 |
+
case SQLITE_VTAB_INNOCUOUS:
|
| 1596 |
+
return sqlite3_vtab_config(pDb, op);
|
| 1597 |
+
case SQLITE_VTAB_CONSTRAINT_SUPPORT:
|
| 1598 |
+
return sqlite3_vtab_config(pDb, op, arg);
|
| 1599 |
+
default:
|
| 1600 |
+
return SQLITE_MISUSE;
|
| 1601 |
+
}
|
| 1602 |
+
}
|
| 1603 |
+
#endif /*SQLITE_WASM_HAS_VTAB*/
|
| 1604 |
+
|
| 1605 |
+
/*
|
| 1606 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1607 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1608 |
+
**
|
| 1609 |
+
** Wrapper for the variants of sqlite3_db_config() which take
|
| 1610 |
+
** (int,int*) variadic args.
|
| 1611 |
+
*/
|
| 1612 |
+
SQLITE_WASM_EXPORT
|
| 1613 |
+
int sqlite3__wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){
|
| 1614 |
+
switch(op){
|
| 1615 |
+
case SQLITE_DBCONFIG_ENABLE_FKEY:
|
| 1616 |
+
case SQLITE_DBCONFIG_ENABLE_TRIGGER:
|
| 1617 |
+
case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:
|
| 1618 |
+
case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:
|
| 1619 |
+
case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:
|
| 1620 |
+
case SQLITE_DBCONFIG_ENABLE_QPSG:
|
| 1621 |
+
case SQLITE_DBCONFIG_TRIGGER_EQP:
|
| 1622 |
+
case SQLITE_DBCONFIG_RESET_DATABASE:
|
| 1623 |
+
case SQLITE_DBCONFIG_DEFENSIVE:
|
| 1624 |
+
case SQLITE_DBCONFIG_WRITABLE_SCHEMA:
|
| 1625 |
+
case SQLITE_DBCONFIG_LEGACY_ALTER_TABLE:
|
| 1626 |
+
case SQLITE_DBCONFIG_DQS_DML:
|
| 1627 |
+
case SQLITE_DBCONFIG_DQS_DDL:
|
| 1628 |
+
case SQLITE_DBCONFIG_ENABLE_VIEW:
|
| 1629 |
+
case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:
|
| 1630 |
+
case SQLITE_DBCONFIG_TRUSTED_SCHEMA:
|
| 1631 |
+
case SQLITE_DBCONFIG_STMT_SCANSTATUS:
|
| 1632 |
+
case SQLITE_DBCONFIG_REVERSE_SCANORDER:
|
| 1633 |
+
return sqlite3_db_config(pDb, op, arg1, pArg2);
|
| 1634 |
+
default: return SQLITE_MISUSE;
|
| 1635 |
+
}
|
| 1636 |
+
}
|
| 1637 |
+
|
| 1638 |
+
/*
|
| 1639 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1640 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1641 |
+
**
|
| 1642 |
+
** Wrapper for the variants of sqlite3_db_config() which take
|
| 1643 |
+
** (void*,int,int) variadic args.
|
| 1644 |
+
*/
|
| 1645 |
+
SQLITE_WASM_EXPORT
|
| 1646 |
+
int sqlite3__wasm_db_config_pii(sqlite3 *pDb, int op, void * pArg1, int arg2, int arg3){
|
| 1647 |
+
switch(op){
|
| 1648 |
+
case SQLITE_DBCONFIG_LOOKASIDE:
|
| 1649 |
+
return sqlite3_db_config(pDb, op, pArg1, arg2, arg3);
|
| 1650 |
+
default: return SQLITE_MISUSE;
|
| 1651 |
+
}
|
| 1652 |
+
}
|
| 1653 |
+
|
| 1654 |
+
/*
|
| 1655 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1656 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1657 |
+
**
|
| 1658 |
+
** Wrapper for the variants of sqlite3_db_config() which take
|
| 1659 |
+
** (const char *) variadic args.
|
| 1660 |
+
*/
|
| 1661 |
+
SQLITE_WASM_EXPORT
|
| 1662 |
+
int sqlite3__wasm_db_config_s(sqlite3 *pDb, int op, const char *zArg){
|
| 1663 |
+
switch(op){
|
| 1664 |
+
case SQLITE_DBCONFIG_MAINDBNAME:
|
| 1665 |
+
return sqlite3_db_config(pDb, op, zArg);
|
| 1666 |
+
default: return SQLITE_MISUSE;
|
| 1667 |
+
}
|
| 1668 |
+
}
|
| 1669 |
+
|
| 1670 |
+
|
| 1671 |
+
/*
|
| 1672 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1673 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1674 |
+
**
|
| 1675 |
+
** Binding for combinations of sqlite3_config() arguments which take
|
| 1676 |
+
** a single integer argument.
|
| 1677 |
+
*/
|
| 1678 |
+
SQLITE_WASM_EXPORT
|
| 1679 |
+
int sqlite3__wasm_config_i(int op, int arg){
|
| 1680 |
+
return sqlite3_config(op, arg);
|
| 1681 |
+
}
|
| 1682 |
+
|
| 1683 |
+
/*
|
| 1684 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1685 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1686 |
+
**
|
| 1687 |
+
** Binding for combinations of sqlite3_config() arguments which take
|
| 1688 |
+
** two int arguments.
|
| 1689 |
+
*/
|
| 1690 |
+
SQLITE_WASM_EXPORT
|
| 1691 |
+
int sqlite3__wasm_config_ii(int op, int arg1, int arg2){
|
| 1692 |
+
return sqlite3_config(op, arg1, arg2);
|
| 1693 |
+
}
|
| 1694 |
+
|
| 1695 |
+
/*
|
| 1696 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1697 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1698 |
+
**
|
| 1699 |
+
** Binding for combinations of sqlite3_config() arguments which take
|
| 1700 |
+
** a single i64 argument.
|
| 1701 |
+
*/
|
| 1702 |
+
SQLITE_WASM_EXPORT
|
| 1703 |
+
int sqlite3__wasm_config_j(int op, sqlite3_int64 arg){
|
| 1704 |
+
return sqlite3_config(op, arg);
|
| 1705 |
+
}
|
| 1706 |
+
|
| 1707 |
+
/*
|
| 1708 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1709 |
+
** for use by the sqlite project's own JS/WASM bindings.
|
| 1710 |
+
**
|
| 1711 |
+
** If z is not NULL, returns the result of passing z to
|
| 1712 |
+
** sqlite3_mprintf()'s %Q modifier (if addQuotes is true) or %q (if
|
| 1713 |
+
** addQuotes is 0). Returns NULL if z is NULL or on OOM.
|
| 1714 |
+
*/
|
| 1715 |
+
SQLITE_WASM_EXPORT
|
| 1716 |
+
char * sqlite3__wasm_qfmt_token(char *z, int addQuotes){
|
| 1717 |
+
char * rc = 0;
|
| 1718 |
+
if( z ){
|
| 1719 |
+
rc = addQuotes
|
| 1720 |
+
? sqlite3_mprintf("%Q", z)
|
| 1721 |
+
: sqlite3_mprintf("%q", z);
|
| 1722 |
+
}
|
| 1723 |
+
return rc;
|
| 1724 |
+
}
|
| 1725 |
+
|
| 1726 |
+
#if defined(__EMSCRIPTEN__) && defined(SQLITE_ENABLE_WASMFS)
|
| 1727 |
+
#include <emscripten/console.h>
|
| 1728 |
+
#include <emscripten/wasmfs.h>
|
| 1729 |
+
|
| 1730 |
+
/*
|
| 1731 |
+
** This function is NOT part of the sqlite3 public API. It is strictly
|
| 1732 |
+
** for use by the sqlite project's own JS/WASM bindings, specifically
|
| 1733 |
+
** only when building with Emscripten's WASMFS support.
|
| 1734 |
+
**
|
| 1735 |
+
** This function should only be called if the JS side detects the
|
| 1736 |
+
** existence of the Origin-Private FileSystem (OPFS) APIs in the
|
| 1737 |
+
** client. The first time it is called, this function instantiates a
|
| 1738 |
+
** WASMFS backend impl for OPFS. On success, subsequent calls are
|
| 1739 |
+
** no-ops.
|
| 1740 |
+
**
|
| 1741 |
+
** This function may be passed a "mount point" name, which must have a
|
| 1742 |
+
** leading "/" and is currently restricted to a single path component,
|
| 1743 |
+
** e.g. "/foo" is legal but "/foo/" and "/foo/bar" are not. If it is
|
| 1744 |
+
** NULL or empty, it defaults to "/opfs".
|
| 1745 |
+
**
|
| 1746 |
+
** Returns 0 on success, SQLITE_NOMEM if instantiation of the backend
|
| 1747 |
+
** object fails, SQLITE_IOERR if mkdir() of the zMountPoint dir in
|
| 1748 |
+
** the virtual FS fails. In builds compiled without SQLITE_ENABLE_WASMFS
|
| 1749 |
+
** defined, SQLITE_NOTFOUND is returned without side effects.
|
| 1750 |
+
*/
|
| 1751 |
+
SQLITE_WASM_EXPORT
|
| 1752 |
+
int sqlite3__wasm_init_wasmfs(const char *zMountPoint){
|
| 1753 |
+
static backend_t pOpfs = 0;
|
| 1754 |
+
if( !zMountPoint || !*zMountPoint ) zMountPoint = "/opfs";
|
| 1755 |
+
if( !pOpfs ){
|
| 1756 |
+
pOpfs = wasmfs_create_opfs_backend();
|
| 1757 |
+
}
|
| 1758 |
+
/** It's not enough to instantiate the backend. We have to create a
|
| 1759 |
+
mountpoint in the VFS and attach the backend to it. */
|
| 1760 |
+
if( pOpfs && 0!=access(zMountPoint, F_OK) ){
|
| 1761 |
+
/* Note that this check and is not robust but it will
|
| 1762 |
+
hypothetically suffice for the transient wasm-based virtual
|
| 1763 |
+
filesystem we're currently running in. */
|
| 1764 |
+
const int rc = wasmfs_create_directory(zMountPoint, 0777, pOpfs);
|
| 1765 |
+
/*emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);*/
|
| 1766 |
+
if(rc) return SQLITE_IOERR;
|
| 1767 |
+
}
|
| 1768 |
+
return pOpfs ? 0 : SQLITE_NOMEM;
|
| 1769 |
+
}
|
| 1770 |
+
#else
|
| 1771 |
+
SQLITE_WASM_EXPORT
|
| 1772 |
+
int sqlite3__wasm_init_wasmfs(const char *zUnused){
|
| 1773 |
+
//emscripten_console_warn("WASMFS OPFS is not compiled in.");
|
| 1774 |
+
if(zUnused){/*unused*/}
|
| 1775 |
+
return SQLITE_NOTFOUND;
|
| 1776 |
+
}
|
| 1777 |
+
#endif /* __EMSCRIPTEN__ && SQLITE_ENABLE_WASMFS */
|
| 1778 |
+
|
| 1779 |
+
#if SQLITE_WASM_ENABLE_C_TESTS
|
| 1780 |
+
|
| 1781 |
+
SQLITE_WASM_EXPORT
|
| 1782 |
+
int sqlite3__wasm_test_intptr(int * p){
|
| 1783 |
+
return *p = *p * 2;
|
| 1784 |
+
}
|
| 1785 |
+
|
| 1786 |
+
SQLITE_WASM_EXPORT
|
| 1787 |
+
void * sqlite3__wasm_test_voidptr(void * p){
|
| 1788 |
+
return p;
|
| 1789 |
+
}
|
| 1790 |
+
|
| 1791 |
+
SQLITE_WASM_EXPORT
|
| 1792 |
+
int64_t sqlite3__wasm_test_int64_max(void){
|
| 1793 |
+
return (int64_t)0x7fffffffffffffff;
|
| 1794 |
+
}
|
| 1795 |
+
|
| 1796 |
+
SQLITE_WASM_EXPORT
|
| 1797 |
+
int64_t sqlite3__wasm_test_int64_min(void){
|
| 1798 |
+
return ~sqlite3__wasm_test_int64_max();
|
| 1799 |
+
}
|
| 1800 |
+
|
| 1801 |
+
SQLITE_WASM_EXPORT
|
| 1802 |
+
int64_t sqlite3__wasm_test_int64_times2(int64_t x){
|
| 1803 |
+
return x * 2;
|
| 1804 |
+
}
|
| 1805 |
+
|
| 1806 |
+
SQLITE_WASM_EXPORT
|
| 1807 |
+
void sqlite3__wasm_test_int64_minmax(int64_t * min, int64_t *max){
|
| 1808 |
+
*max = sqlite3__wasm_test_int64_max();
|
| 1809 |
+
*min = sqlite3__wasm_test_int64_min();
|
| 1810 |
+
/*printf("minmax: min=%lld, max=%lld\n", *min, *max);*/
|
| 1811 |
+
}
|
| 1812 |
+
|
| 1813 |
+
SQLITE_WASM_EXPORT
|
| 1814 |
+
int64_t sqlite3__wasm_test_int64ptr(int64_t * p){
|
| 1815 |
+
/*printf("sqlite3__wasm_test_int64ptr( @%lld = 0x%llx )\n", (int64_t)p, *p);*/
|
| 1816 |
+
return *p = *p * 2;
|
| 1817 |
+
}
|
| 1818 |
+
|
| 1819 |
+
SQLITE_WASM_EXPORT
|
| 1820 |
+
void sqlite3__wasm_test_stack_overflow(int recurse){
|
| 1821 |
+
if(recurse) sqlite3__wasm_test_stack_overflow(recurse);
|
| 1822 |
+
}
|
| 1823 |
+
|
| 1824 |
+
/* For testing the 'string:dealloc' whwasmutil.xWrap() conversion. */
|
| 1825 |
+
SQLITE_WASM_EXPORT
|
| 1826 |
+
char * sqlite3__wasm_test_str_hello(int fail){
|
| 1827 |
+
char * s = fail ? 0 : (char *)sqlite3_malloc(6);
|
| 1828 |
+
if(s){
|
| 1829 |
+
memcpy(s, "hello", 5);
|
| 1830 |
+
s[5] = 0;
|
| 1831 |
+
}
|
| 1832 |
+
return s;
|
| 1833 |
+
}
|
| 1834 |
+
|
| 1835 |
+
/*
|
| 1836 |
+
** For testing using SQLTester scripts.
|
| 1837 |
+
**
|
| 1838 |
+
** Return non-zero if string z matches glob pattern zGlob and zero if the
|
| 1839 |
+
** pattern does not match.
|
| 1840 |
+
**
|
| 1841 |
+
** To repeat:
|
| 1842 |
+
**
|
| 1843 |
+
** zero == no match
|
| 1844 |
+
** non-zero == match
|
| 1845 |
+
**
|
| 1846 |
+
** Globbing rules:
|
| 1847 |
+
**
|
| 1848 |
+
** '*' Matches any sequence of zero or more characters.
|
| 1849 |
+
**
|
| 1850 |
+
** '?' Matches exactly one character.
|
| 1851 |
+
**
|
| 1852 |
+
** [...] Matches one character from the enclosed list of
|
| 1853 |
+
** characters.
|
| 1854 |
+
**
|
| 1855 |
+
** [^...] Matches one character not in the enclosed list.
|
| 1856 |
+
**
|
| 1857 |
+
** '#' Matches any sequence of one or more digits with an
|
| 1858 |
+
** optional + or - sign in front, or a hexadecimal
|
| 1859 |
+
** literal of the form 0x...
|
| 1860 |
+
*/
|
| 1861 |
+
static int sqlite3__wasm_SQLTester_strnotglob(const char *zGlob, const char *z){
|
| 1862 |
+
int c, c2;
|
| 1863 |
+
int invert;
|
| 1864 |
+
int seen;
|
| 1865 |
+
typedef int (*recurse_f)(const char *,const char *);
|
| 1866 |
+
static const recurse_f recurse = sqlite3__wasm_SQLTester_strnotglob;
|
| 1867 |
+
|
| 1868 |
+
while( (c = (*(zGlob++)))!=0 ){
|
| 1869 |
+
if( c=='*' ){
|
| 1870 |
+
while( (c=(*(zGlob++))) == '*' || c=='?' ){
|
| 1871 |
+
if( c=='?' && (*(z++))==0 ) return 0;
|
| 1872 |
+
}
|
| 1873 |
+
if( c==0 ){
|
| 1874 |
+
return 1;
|
| 1875 |
+
}else if( c=='[' ){
|
| 1876 |
+
while( *z && recurse(zGlob-1,z)==0 ){
|
| 1877 |
+
z++;
|
| 1878 |
+
}
|
| 1879 |
+
return (*z)!=0;
|
| 1880 |
+
}
|
| 1881 |
+
while( (c2 = (*(z++)))!=0 ){
|
| 1882 |
+
while( c2!=c ){
|
| 1883 |
+
c2 = *(z++);
|
| 1884 |
+
if( c2==0 ) return 0;
|
| 1885 |
+
}
|
| 1886 |
+
if( recurse(zGlob,z) ) return 1;
|
| 1887 |
+
}
|
| 1888 |
+
return 0;
|
| 1889 |
+
}else if( c=='?' ){
|
| 1890 |
+
if( (*(z++))==0 ) return 0;
|
| 1891 |
+
}else if( c=='[' ){
|
| 1892 |
+
int prior_c = 0;
|
| 1893 |
+
seen = 0;
|
| 1894 |
+
invert = 0;
|
| 1895 |
+
c = *(z++);
|
| 1896 |
+
if( c==0 ) return 0;
|
| 1897 |
+
c2 = *(zGlob++);
|
| 1898 |
+
if( c2=='^' ){
|
| 1899 |
+
invert = 1;
|
| 1900 |
+
c2 = *(zGlob++);
|
| 1901 |
+
}
|
| 1902 |
+
if( c2==']' ){
|
| 1903 |
+
if( c==']' ) seen = 1;
|
| 1904 |
+
c2 = *(zGlob++);
|
| 1905 |
+
}
|
| 1906 |
+
while( c2 && c2!=']' ){
|
| 1907 |
+
if( c2=='-' && zGlob[0]!=']' && zGlob[0]!=0 && prior_c>0 ){
|
| 1908 |
+
c2 = *(zGlob++);
|
| 1909 |
+
if( c>=prior_c && c<=c2 ) seen = 1;
|
| 1910 |
+
prior_c = 0;
|
| 1911 |
+
}else{
|
| 1912 |
+
if( c==c2 ){
|
| 1913 |
+
seen = 1;
|
| 1914 |
+
}
|
| 1915 |
+
prior_c = c2;
|
| 1916 |
+
}
|
| 1917 |
+
c2 = *(zGlob++);
|
| 1918 |
+
}
|
| 1919 |
+
if( c2==0 || (seen ^ invert)==0 ) return 0;
|
| 1920 |
+
}else if( c=='#' ){
|
| 1921 |
+
if( z[0]=='0'
|
| 1922 |
+
&& (z[1]=='x' || z[1]=='X')
|
| 1923 |
+
&& sqlite3Isxdigit(z[2])
|
| 1924 |
+
){
|
| 1925 |
+
z += 3;
|
| 1926 |
+
while( sqlite3Isxdigit(z[0]) ){ z++; }
|
| 1927 |
+
}else{
|
| 1928 |
+
if( (z[0]=='-' || z[0]=='+') && sqlite3Isdigit(z[1]) ) z++;
|
| 1929 |
+
if( !sqlite3Isdigit(z[0]) ) return 0;
|
| 1930 |
+
z++;
|
| 1931 |
+
while( sqlite3Isdigit(z[0]) ){ z++; }
|
| 1932 |
+
}
|
| 1933 |
+
}else{
|
| 1934 |
+
if( c!=(*(z++)) ) return 0;
|
| 1935 |
+
}
|
| 1936 |
+
}
|
| 1937 |
+
return *z==0;
|
| 1938 |
+
}
|
| 1939 |
+
|
| 1940 |
+
SQLITE_WASM_EXPORT
|
| 1941 |
+
int sqlite3__wasm_SQLTester_strglob(const char *zGlob, const char *z){
|
| 1942 |
+
return !sqlite3__wasm_SQLTester_strnotglob(zGlob, z);
|
| 1943 |
+
}
|
| 1944 |
+
|
| 1945 |
+
#endif /* SQLITE_WASM_ENABLE_C_TESTS */
|
| 1946 |
+
|
| 1947 |
+
#undef SQLITE_WASM_EXPORT
|
| 1948 |
+
#undef SQLITE_WASM_HAS_VTAB
|
| 1949 |
+
#undef SQLITE_WASM_BARE_BONES
|
| 1950 |
+
#undef SQLITE_WASM_ENABLE_C_TESTS
|
local-test-sqlite3-delta-03/afc-sqlite3/ext/wasm/sql/001-sudoku.sql
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
WITH RECURSIVE
|
| 2 |
+
input(sud) AS (
|
| 3 |
+
VALUES('53..7....6..195....98....6.8...6...34..8.3..17...2...6.6....28....419..5....8..79')
|
| 4 |
+
),
|
| 5 |
+
digits(z, lp) AS (
|
| 6 |
+
VALUES('1', 1)
|
| 7 |
+
UNION ALL SELECT
|
| 8 |
+
CAST(lp+1 AS TEXT), lp+1 FROM digits WHERE lp<9
|
| 9 |
+
),
|
| 10 |
+
x(s, ind) AS (
|
| 11 |
+
SELECT sud, instr(sud, '.') FROM input
|
| 12 |
+
UNION ALL
|
| 13 |
+
SELECT
|
| 14 |
+
substr(s, 1, ind-1) || z || substr(s, ind+1),
|
| 15 |
+
instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )
|
| 16 |
+
FROM x, digits AS z
|
| 17 |
+
WHERE ind>0
|
| 18 |
+
AND NOT EXISTS (
|
| 19 |
+
SELECT 1
|
| 20 |
+
FROM digits AS lp
|
| 21 |
+
WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)
|
| 22 |
+
OR z.z = substr(s, ((ind-1)%9) + (lp-1)*9 + 1, 1)
|
| 23 |
+
OR z.z = substr(s, (((ind-1)/3) % 3) * 3
|
| 24 |
+
+ ((ind-1)/27) * 27 + lp
|
| 25 |
+
+ ((lp-1) / 3) * 6, 1)
|
| 26 |
+
)
|
| 27 |
+
)
|
| 28 |
+
SELECT s FROM x WHERE ind=0;
|