Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
b4ee45b7
Commit
b4ee45b7
authored
Jun 24, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing intarray C file.
parent
651ec17e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
262 additions
and
0 deletions
+262
-0
intarray.c
intarray.c
+262
-0
No files found.
intarray.c
0 → 100644
View file @
b4ee45b7
/*
** 2009 November 10
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file implements a read-only VIRTUAL TABLE that contains the
** content of a C-language array of integer values. See the corresponding
** header file for full details.
*/
#include <sqlite3.h>
#include <string.h>
#include <assert.h>
/*
** An sqlite3_intarray is an abstract type to stores an instance of
** an integer array.
*/
typedef
struct
sqlite3_intarray
sqlite3_intarray
;
/*
** Definition of the sqlite3_intarray object.
**
** The internal representation of an intarray object is subject
** to change, is not externally visible, and should be used by
** the implementation of intarray only. This object is opaque
** to users.
*/
struct
sqlite3_intarray
{
int
n
;
/* Number of elements in the array */
sqlite3_int64
*
a
;
/* Contents of the array */
void
(
*
xFree
)(
void
*
);
/* Function used to free a[] */
};
/* Objects used internally by the virtual table implementation */
typedef
struct
intarray_vtab
intarray_vtab
;
typedef
struct
intarray_cursor
intarray_cursor
;
/* A intarray table object */
struct
intarray_vtab
{
sqlite3_vtab
base
;
/* Base class */
sqlite3_intarray
*
pContent
;
/* Content of the integer array */
};
/* A intarray cursor object */
struct
intarray_cursor
{
sqlite3_vtab_cursor
base
;
/* Base class */
int
i
;
/* Current cursor position */
};
/*
** Free an sqlite3_intarray object.
*/
static
void
intarrayFree
(
sqlite3_intarray
*
p
){
if
(
p
->
xFree
){
p
->
xFree
(
p
->
a
);
}
sqlite3_free
(
p
);
}
/*
** Table destructor for the intarray module.
*/
static
int
intarrayDestroy
(
sqlite3_vtab
*
p
){
intarray_vtab
*
pVtab
=
(
intarray_vtab
*
)
p
;
sqlite3_free
(
pVtab
);
return
0
;
}
/*
** Table constructor for the intarray module.
*/
static
int
intarrayCreate
(
sqlite3
*
db
,
/* Database where module is created */
void
*
pAux
,
/* clientdata for the module */
int
argc
,
/* Number of arguments */
const
char
*
const
*
argv
,
/* Value for all arguments */
sqlite3_vtab
**
ppVtab
,
/* Write the new virtual table object here */
char
**
pzErr
/* Put error message text here */
){
int
rc
=
SQLITE_NOMEM
;
intarray_vtab
*
pVtab
=
sqlite3_malloc
(
sizeof
(
intarray_vtab
));
if
(
pVtab
){
memset
(
pVtab
,
0
,
sizeof
(
intarray_vtab
));
pVtab
->
pContent
=
(
sqlite3_intarray
*
)
pAux
;
rc
=
sqlite3_declare_vtab
(
db
,
"CREATE TABLE x(value INTEGER PRIMARY KEY)"
);
}
*
ppVtab
=
(
sqlite3_vtab
*
)
pVtab
;
return
rc
;
}
/*
** Open a new cursor on the intarray table.
*/
static
int
intarrayOpen
(
sqlite3_vtab
*
pVTab
,
sqlite3_vtab_cursor
**
ppCursor
){
int
rc
=
SQLITE_NOMEM
;
intarray_cursor
*
pCur
;
pCur
=
sqlite3_malloc
(
sizeof
(
intarray_cursor
));
if
(
pCur
){
memset
(
pCur
,
0
,
sizeof
(
intarray_cursor
));
*
ppCursor
=
(
sqlite3_vtab_cursor
*
)
pCur
;
rc
=
SQLITE_OK
;
}
return
rc
;
}
/*
** Close a intarray table cursor.
*/
static
int
intarrayClose
(
sqlite3_vtab_cursor
*
cur
){
intarray_cursor
*
pCur
=
(
intarray_cursor
*
)
cur
;
sqlite3_free
(
pCur
);
return
SQLITE_OK
;
}
/*
** Retrieve a column of data.
*/
static
int
intarrayColumn
(
sqlite3_vtab_cursor
*
cur
,
sqlite3_context
*
ctx
,
int
i
){
intarray_cursor
*
pCur
=
(
intarray_cursor
*
)
cur
;
intarray_vtab
*
pVtab
=
(
intarray_vtab
*
)
cur
->
pVtab
;
if
(
pCur
->
i
>=
0
&&
pCur
->
i
<
pVtab
->
pContent
->
n
){
sqlite3_result_int64
(
ctx
,
pVtab
->
pContent
->
a
[
pCur
->
i
]);
}
return
SQLITE_OK
;
}
/*
** Retrieve the current rowid.
*/
static
int
intarrayRowid
(
sqlite3_vtab_cursor
*
cur
,
sqlite_int64
*
pRowid
){
intarray_cursor
*
pCur
=
(
intarray_cursor
*
)
cur
;
*
pRowid
=
pCur
->
i
;
return
SQLITE_OK
;
}
static
int
intarrayEof
(
sqlite3_vtab_cursor
*
cur
){
intarray_cursor
*
pCur
=
(
intarray_cursor
*
)
cur
;
intarray_vtab
*
pVtab
=
(
intarray_vtab
*
)
cur
->
pVtab
;
return
pCur
->
i
>=
pVtab
->
pContent
->
n
;
}
/*
** Advance the cursor to the next row.
*/
static
int
intarrayNext
(
sqlite3_vtab_cursor
*
cur
){
intarray_cursor
*
pCur
=
(
intarray_cursor
*
)
cur
;
pCur
->
i
++
;
return
SQLITE_OK
;
}
/*
** Reset a intarray table cursor.
*/
static
int
intarrayFilter
(
sqlite3_vtab_cursor
*
pVtabCursor
,
int
idxNum
,
const
char
*
idxStr
,
int
argc
,
sqlite3_value
**
argv
){
intarray_cursor
*
pCur
=
(
intarray_cursor
*
)
pVtabCursor
;
pCur
->
i
=
0
;
return
SQLITE_OK
;
}
/*
** Analyse the WHERE condition.
*/
static
int
intarrayBestIndex
(
sqlite3_vtab
*
tab
,
sqlite3_index_info
*
pIdxInfo
){
return
SQLITE_OK
;
}
/*
** A virtual table module that merely echos method calls into TCL
** variables.
*/
static
sqlite3_module
intarrayModule
=
{
0
,
/* iVersion */
intarrayCreate
,
/* xCreate - create a new virtual table */
intarrayCreate
,
/* xConnect - connect to an existing vtab */
intarrayBestIndex
,
/* xBestIndex - find the best query index */
intarrayDestroy
,
/* xDisconnect - disconnect a vtab */
intarrayDestroy
,
/* xDestroy - destroy a vtab */
intarrayOpen
,
/* xOpen - open a cursor */
intarrayClose
,
/* xClose - close a cursor */
intarrayFilter
,
/* xFilter - configure scan constraints */
intarrayNext
,
/* xNext - advance a cursor */
intarrayEof
,
/* xEof */
intarrayColumn
,
/* xColumn - read data */
intarrayRowid
,
/* xRowid - read data */
0
,
/* xUpdate */
0
,
/* xBegin */
0
,
/* xSync */
0
,
/* xCommit */
0
,
/* xRollback */
0
,
/* xFindMethod */
0
,
/* xRename */
};
/*
** Invoke this routine to create a specific instance of an intarray object.
** The new intarray object is returned by the 3rd parameter.
**
** Each intarray object corresponds to a virtual table in the TEMP table
** with a name of zName.
**
** Destroy the intarray object by dropping the virtual table. If not done
** explicitly by the application, the virtual table will be dropped implicitly
** by the system when the database connection is closed.
*/
int
sqlite3_intarray_create
(
sqlite3
*
db
,
const
char
*
zName
,
sqlite3_intarray
**
ppReturn
){
int
rc
=
SQLITE_OK
;
sqlite3_intarray
*
p
;
*
ppReturn
=
p
=
sqlite3_malloc
(
sizeof
(
*
p
)
);
if
(
p
==
0
){
return
SQLITE_NOMEM
;
}
memset
(
p
,
0
,
sizeof
(
*
p
));
rc
=
sqlite3_create_module_v2
(
db
,
zName
,
&
intarrayModule
,
p
,
(
void
(
*
)(
void
*
))
intarrayFree
);
if
(
rc
==
SQLITE_OK
){
char
*
zSql
;
zSql
=
sqlite3_mprintf
(
"CREATE VIRTUAL TABLE temp.%Q USING %Q"
,
zName
,
zName
);
rc
=
sqlite3_exec
(
db
,
zSql
,
0
,
0
,
0
);
sqlite3_free
(
zSql
);
}
return
rc
;
}
/*
** Bind a new array array of integers to a specific intarray object.
**
** The array of integers bound must be unchanged for the duration of
** any query against the corresponding virtual table. If the integer
** array does change or is deallocated undefined behavior will result.
*/
int
sqlite3_intarray_bind
(
sqlite3_intarray
*
pIntArray
,
/* The intarray object to bind to */
int
nElements
,
/* Number of elements in the intarray */
sqlite3_int64
*
aElements
,
/* Content of the intarray */
void
(
*
xFree
)(
void
*
)
/* How to dispose of the intarray when done */
){
if
(
pIntArray
->
xFree
){
pIntArray
->
xFree
(
pIntArray
->
a
);
}
pIntArray
->
n
=
nElements
;
pIntArray
->
a
=
aElements
;
pIntArray
->
xFree
=
xFree
;
return
SQLITE_OK
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment