Fix the ".lint fkey-indexes" shell command so that it works with WITHOUT ROWID
[sqlite.git] / ext / lsm1 / lsm-test / lsmtest_datasource.c
blob0b0fd94e8b3c3fc60debf8a2948819cf80d97b47
3 #include "lsmtest.h"
5 struct Datasource {
6 int eType;
8 int nMinKey;
9 int nMaxKey;
10 int nMinVal;
11 int nMaxVal;
13 char *aKey;
14 char *aVal;
17 void testDatasourceEntry(
18 Datasource *p,
19 int iData,
20 void **ppKey, int *pnKey,
21 void **ppVal, int *pnVal
23 assert( (ppKey==0)==(pnKey==0) );
24 assert( (ppVal==0)==(pnVal==0) );
26 if( ppKey ){
27 int nKey = 0;
28 switch( p->eType ){
29 case TEST_DATASOURCE_RANDOM: {
30 int nRange = (1 + p->nMaxKey - p->nMinKey);
31 nKey = (int)( testPrngValue((u32)iData) % nRange ) + p->nMinKey;
32 testPrngString((u32)iData, p->aKey, nKey);
33 break;
35 case TEST_DATASOURCE_SEQUENCE:
36 nKey = sprintf(p->aKey, "%012d", iData);
37 break;
39 *ppKey = p->aKey;
40 *pnKey = nKey;
42 if( ppVal ){
43 u32 nVal = testPrngValue((u32)iData)%(1+p->nMaxVal-p->nMinVal)+p->nMinVal;
44 testPrngString((u32)~iData, p->aVal, (int)nVal);
45 *ppVal = p->aVal;
46 *pnVal = (int)nVal;
50 void testDatasourceFree(Datasource *p){
51 testFree(p);
55 ** Return a pointer to a nul-terminated string that corresponds to the
56 ** contents of the datasource-definition passed as the first argument.
57 ** The caller should eventually free the returned pointer using testFree().
59 char *testDatasourceName(const DatasourceDefn *p){
60 char *zRet;
61 zRet = testMallocPrintf("%s.(%d-%d).(%d-%d)",
62 (p->eType==TEST_DATASOURCE_SEQUENCE ? "seq" : "rnd"),
63 p->nMinKey, p->nMaxKey,
64 p->nMinVal, p->nMaxVal
66 return zRet;
69 Datasource *testDatasourceNew(const DatasourceDefn *pDefn){
70 Datasource *p;
71 int nMinKey;
72 int nMaxKey;
73 int nMinVal;
74 int nMaxVal;
76 if( pDefn->eType==TEST_DATASOURCE_SEQUENCE ){
77 nMinKey = 128;
78 nMaxKey = 128;
79 }else{
80 nMinKey = MAX(0, pDefn->nMinKey);
81 nMaxKey = MAX(nMinKey, pDefn->nMaxKey);
83 nMinVal = MAX(0, pDefn->nMinVal);
84 nMaxVal = MAX(nMinVal, pDefn->nMaxVal);
86 p = (Datasource *)testMalloc(sizeof(Datasource) + nMaxKey + nMaxVal + 1);
87 p->eType = pDefn->eType;
88 p->nMinKey = nMinKey;
89 p->nMinVal = nMinVal;
90 p->nMaxKey = nMaxKey;
91 p->nMaxVal = nMaxVal;
93 p->aKey = (char *)&p[1];
94 p->aVal = &p->aKey[nMaxKey];
95 return p;