mirror of
https://github.com/holub/mame
synced 2025-04-21 07:52:35 +03:00
removed not used libraries, and commented portaudio that will be used but no need for now (nw)
This commit is contained in:
parent
773febd6c0
commit
d04f921034
6
3rdparty/README.md
vendored
6
3rdparty/README.md
vendored
@ -20,16 +20,12 @@ glm - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
|
||||
googletest - [The BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)
|
||||
|
||||
http-parser - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
|
||||
libflac - [The BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)
|
||||
|
||||
libjpeg - [Custom BSD-like](https://github.com/numenta/nupic/blob/master/external/licenses/LICENSE.libjpeg-6b.txt)
|
||||
|
||||
libuv - [Node License (BSD-like)](https://github.com/mamedev/mame/blob/master/3rdparty/libuv/LICENSE)
|
||||
|
||||
lsqlite3 - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
|
||||
lua - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
|
||||
lua-zlib - [The MIT License (MIT)](http://opensource.org/licenses/MIT)
|
||||
@ -52,8 +48,6 @@ sdl2 - [zlib license](http://opensource.org/licenses/Zlib)
|
||||
|
||||
softfloat - [U.C. Berkeley open-source license](https://github.com/mamedev/mame/blob/master/3rdparty/softfloat/README.txt) MIT compatible
|
||||
|
||||
sqlite3 - Public Domain
|
||||
|
||||
winpcap - [The BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)
|
||||
|
||||
zlib - [zlib license](http://opensource.org/licenses/Zlib)
|
||||
|
28
3rdparty/http-parser/.gitignore
vendored
28
3rdparty/http-parser/.gitignore
vendored
@ -1,28 +0,0 @@
|
||||
/out/
|
||||
core
|
||||
tags
|
||||
*.o
|
||||
test
|
||||
test_g
|
||||
test_fast
|
||||
bench
|
||||
url_parser
|
||||
parsertrace
|
||||
parsertrace_g
|
||||
*.mk
|
||||
*.Makefile
|
||||
*.so.*
|
||||
*.a
|
||||
|
||||
|
||||
# Visual Studio uglies
|
||||
*.suo
|
||||
*.sln
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
*.vcxproj.user
|
||||
*.opensdf
|
||||
*.ncrunchsolution*
|
||||
*.sdf
|
||||
*.vsp
|
||||
*.psess
|
8
3rdparty/http-parser/.mailmap
vendored
8
3rdparty/http-parser/.mailmap
vendored
@ -1,8 +0,0 @@
|
||||
# update AUTHORS with:
|
||||
# git log --all --reverse --format='%aN <%aE>' | perl -ne 'BEGIN{print "# Authors ordered by first contribution.\n"} print unless $h{$_}; $h{$_} = 1' > AUTHORS
|
||||
Ryan Dahl <ry@tinyclouds.org>
|
||||
Salman Haq <salman.haq@asti-usa.com>
|
||||
Simon Zimmermann <simonz05@gmail.com>
|
||||
Thomas LE ROUX <thomas@november-eleven.fr> LE ROUX Thomas <thomas@procheo.fr>
|
||||
Thomas LE ROUX <thomas@november-eleven.fr> Thomas LE ROUX <thomas@procheo.fr>
|
||||
Fedor Indutny <fedor@indutny.com>
|
13
3rdparty/http-parser/.travis.yml
vendored
13
3rdparty/http-parser/.travis.yml
vendored
@ -1,13 +0,0 @@
|
||||
language: c
|
||||
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
|
||||
script:
|
||||
- "make"
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
irc:
|
||||
- "irc.freenode.net#node-ci"
|
67
3rdparty/http-parser/AUTHORS
vendored
67
3rdparty/http-parser/AUTHORS
vendored
@ -1,67 +0,0 @@
|
||||
# Authors ordered by first contribution.
|
||||
Ryan Dahl <ry@tinyclouds.org>
|
||||
Jeremy Hinegardner <jeremy@hinegardner.org>
|
||||
Sergey Shepelev <temotor@gmail.com>
|
||||
Joe Damato <ice799@gmail.com>
|
||||
tomika <tomika_nospam@freemail.hu>
|
||||
Phoenix Sol <phoenix@burninglabs.com>
|
||||
Cliff Frey <cliff@meraki.com>
|
||||
Ewen Cheslack-Postava <ewencp@cs.stanford.edu>
|
||||
Santiago Gala <sgala@apache.org>
|
||||
Tim Becker <tim.becker@syngenio.de>
|
||||
Jeff Terrace <jterrace@gmail.com>
|
||||
Ben Noordhuis <info@bnoordhuis.nl>
|
||||
Nathan Rajlich <nathan@tootallnate.net>
|
||||
Mark Nottingham <mnot@mnot.net>
|
||||
Aman Gupta <aman@tmm1.net>
|
||||
Tim Becker <tim.becker@kuriositaet.de>
|
||||
Sean Cunningham <sean.cunningham@mandiant.com>
|
||||
Peter Griess <pg@std.in>
|
||||
Salman Haq <salman.haq@asti-usa.com>
|
||||
Cliff Frey <clifffrey@gmail.com>
|
||||
Jon Kolb <jon@b0g.us>
|
||||
Fouad Mardini <f.mardini@gmail.com>
|
||||
Paul Querna <pquerna@apache.org>
|
||||
Felix Geisendörfer <felix@debuggable.com>
|
||||
koichik <koichik@improvement.jp>
|
||||
Andre Caron <andre.l.caron@gmail.com>
|
||||
Ivo Raisr <ivosh@ivosh.net>
|
||||
James McLaughlin <jamie@lacewing-project.org>
|
||||
David Gwynne <loki@animata.net>
|
||||
Thomas LE ROUX <thomas@november-eleven.fr>
|
||||
Randy Rizun <rrizun@ortivawireless.com>
|
||||
Andre Louis Caron <andre.louis.caron@usherbrooke.ca>
|
||||
Simon Zimmermann <simonz05@gmail.com>
|
||||
Erik Dubbelboer <erik@dubbelboer.com>
|
||||
Martell Malone <martellmalone@gmail.com>
|
||||
Bertrand Paquet <bpaquet@octo.com>
|
||||
BogDan Vatra <bogdan@kde.org>
|
||||
Peter Faiman <peter@thepicard.org>
|
||||
Corey Richardson <corey@octayn.net>
|
||||
Tóth Tamás <tomika_nospam@freemail.hu>
|
||||
Cam Swords <cam.swords@gmail.com>
|
||||
Chris Dickinson <christopher.s.dickinson@gmail.com>
|
||||
Uli Köhler <ukoehler@btronik.de>
|
||||
Charlie Somerville <charlie@charliesomerville.com>
|
||||
Patrik Stutz <patrik.stutz@gmail.com>
|
||||
Fedor Indutny <fedor.indutny@gmail.com>
|
||||
runner <runner.mei@gmail.com>
|
||||
Alexis Campailla <alexis@janeasystems.com>
|
||||
David Wragg <david@wragg.org>
|
||||
Vinnie Falco <vinnie.falco@gmail.com>
|
||||
Alex Butum <alexbutum@linux.com>
|
||||
Rex Feng <rexfeng@gmail.com>
|
||||
Alex Kocharin <alex@kocharin.ru>
|
||||
Mark Koopman <markmontymark@yahoo.com>
|
||||
Helge Heß <me@helgehess.eu>
|
||||
Alexis La Goutte <alexis.lagoutte@gmail.com>
|
||||
George Miroshnykov <george.miroshnykov@gmail.com>
|
||||
Maciej Małecki <me@mmalecki.com>
|
||||
Marc O'Morain <github.com@marcomorain.com>
|
||||
Jeff Pinner <jpinner@twitter.com>
|
||||
Timothy J Fontaine <tjfontaine@gmail.com>
|
||||
Akagi201 <akagi201@gmail.com>
|
||||
Romain Giraud <giraud.romain@gmail.com>
|
||||
Jay Satiro <raysatiro@yahoo.com>
|
||||
Arne Steen <Arne.Steen@gmx.de>
|
||||
Kjell Schubert <kjell.schubert@gmail.com>
|
23
3rdparty/http-parser/LICENSE-MIT
vendored
23
3rdparty/http-parser/LICENSE-MIT
vendored
@ -1,23 +0,0 @@
|
||||
http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright
|
||||
Igor Sysoev.
|
||||
|
||||
Additional changes are licensed under the same terms as NGINX and
|
||||
copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
136
3rdparty/http-parser/Makefile
vendored
136
3rdparty/http-parser/Makefile
vendored
@ -1,136 +0,0 @@
|
||||
# Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
|
||||
SONAME ?= libhttp_parser.so.2.5.0
|
||||
|
||||
CC?=gcc
|
||||
AR?=ar
|
||||
|
||||
CPPFLAGS ?=
|
||||
LDFLAGS ?=
|
||||
|
||||
CPPFLAGS += -I.
|
||||
CPPFLAGS_DEBUG = $(CPPFLAGS) -DHTTP_PARSER_STRICT=1
|
||||
CPPFLAGS_DEBUG += $(CPPFLAGS_DEBUG_EXTRA)
|
||||
CPPFLAGS_FAST = $(CPPFLAGS) -DHTTP_PARSER_STRICT=0
|
||||
CPPFLAGS_FAST += $(CPPFLAGS_FAST_EXTRA)
|
||||
CPPFLAGS_BENCH = $(CPPFLAGS_FAST)
|
||||
|
||||
CFLAGS += -Wall -Wextra -Werror
|
||||
CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
|
||||
CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)
|
||||
CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter
|
||||
CFLAGS_LIB = $(CFLAGS_FAST) -fPIC
|
||||
|
||||
LDFLAGS_LIB = $(LDFLAGS) -shared
|
||||
|
||||
INSTALL ?= install
|
||||
PREFIX ?= $(DESTDIR)/usr/local
|
||||
LIBDIR = $(PREFIX)/lib
|
||||
INCLUDEDIR = $(PREFIX)/include
|
||||
|
||||
ifneq (darwin,$(PLATFORM))
|
||||
# TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname...
|
||||
LDFLAGS_LIB += -Wl,-soname=$(SONAME)
|
||||
endif
|
||||
|
||||
test: test_g test_fast
|
||||
./test_g
|
||||
./test_fast
|
||||
|
||||
test_g: http_parser_g.o test_g.o
|
||||
$(CC) $(CFLAGS_DEBUG) $(LDFLAGS) http_parser_g.o test_g.o -o $@
|
||||
|
||||
test_g.o: test.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c test.c -o $@
|
||||
|
||||
http_parser_g.o: http_parser.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) -c http_parser.c -o $@
|
||||
|
||||
test_fast: http_parser.o test.o http_parser.h
|
||||
$(CC) $(CFLAGS_FAST) $(LDFLAGS) http_parser.o test.o -o $@
|
||||
|
||||
test.o: test.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c test.c -o $@
|
||||
|
||||
bench: http_parser.o bench.o
|
||||
$(CC) $(CFLAGS_BENCH) $(LDFLAGS) http_parser.o bench.o -o $@
|
||||
|
||||
bench.o: bench.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_BENCH) $(CFLAGS_BENCH) -c bench.c -o $@
|
||||
|
||||
http_parser.o: http_parser.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) -c http_parser.c
|
||||
|
||||
test-run-timed: test_fast
|
||||
while(true) do time ./test_fast > /dev/null; done
|
||||
|
||||
test-valgrind: test_g
|
||||
valgrind ./test_g
|
||||
|
||||
libhttp_parser.o: http_parser.c http_parser.h Makefile
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o
|
||||
|
||||
library: libhttp_parser.o
|
||||
$(CC) $(LDFLAGS_LIB) -o $(SONAME) $<
|
||||
|
||||
package: http_parser.o
|
||||
$(AR) rcs libhttp_parser.a http_parser.o
|
||||
|
||||
url_parser: http_parser.o contrib/url_parser.c
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o $@
|
||||
|
||||
url_parser_g: http_parser_g.o contrib/url_parser.c
|
||||
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o $@
|
||||
|
||||
parsertrace: http_parser.o contrib/parsertrace.c
|
||||
$(CC) $(CPPFLAGS_FAST) $(CFLAGS_FAST) $^ -o parsertrace
|
||||
|
||||
parsertrace_g: http_parser_g.o contrib/parsertrace.c
|
||||
$(CC) $(CPPFLAGS_DEBUG) $(CFLAGS_DEBUG) $^ -o parsertrace_g
|
||||
|
||||
tags: http_parser.c http_parser.h test.c
|
||||
ctags $^
|
||||
|
||||
install: library
|
||||
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
|
||||
$(INSTALL) -D $(SONAME) $(LIBDIR)/$(SONAME)
|
||||
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
|
||||
|
||||
install-strip: library
|
||||
$(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h
|
||||
$(INSTALL) -D -s $(SONAME) $(LIBDIR)/$(SONAME)
|
||||
ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.so
|
||||
|
||||
uninstall:
|
||||
rm $(INCLUDEDIR)/http_parser.h
|
||||
rm $(LIBDIR)/$(SONAME)
|
||||
rm $(LIBDIR)/libhttp_parser.so
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a tags test test_fast test_g \
|
||||
http_parser.tar libhttp_parser.so.* \
|
||||
url_parser url_parser_g parsertrace parsertrace_g
|
||||
|
||||
contrib/url_parser.c: http_parser.h
|
||||
contrib/parsertrace.c: http_parser.h
|
||||
|
||||
.PHONY: clean package test-run test-run-timed test-valgrind install install-strip uninstall
|
183
3rdparty/http-parser/README.md
vendored
183
3rdparty/http-parser/README.md
vendored
@ -1,183 +0,0 @@
|
||||
HTTP Parser
|
||||
===========
|
||||
|
||||
[](https://travis-ci.org/joyent/http-parser)
|
||||
|
||||
This is a parser for HTTP messages written in C. It parses both requests and
|
||||
responses. The parser is designed to be used in performance HTTP
|
||||
applications. It does not make any syscalls nor allocations, it does not
|
||||
buffer data, it can be interrupted at anytime. Depending on your
|
||||
architecture, it only requires about 40 bytes of data per message
|
||||
stream (in a web server that is per connection).
|
||||
|
||||
Features:
|
||||
|
||||
* No dependencies
|
||||
* Handles persistent streams (keep-alive).
|
||||
* Decodes chunked encoding.
|
||||
* Upgrade support
|
||||
* Defends against buffer overflow attacks.
|
||||
|
||||
The parser extracts the following information from HTTP messages:
|
||||
|
||||
* Header fields and values
|
||||
* Content-Length
|
||||
* Request method
|
||||
* Response status code
|
||||
* Transfer-Encoding
|
||||
* HTTP version
|
||||
* Request URL
|
||||
* Message body
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
One `http_parser` object is used per TCP connection. Initialize the struct
|
||||
using `http_parser_init()` and set the callbacks. That might look something
|
||||
like this for a request parser:
|
||||
```c
|
||||
http_parser_settings settings;
|
||||
settings.on_url = my_url_callback;
|
||||
settings.on_header_field = my_header_field_callback;
|
||||
/* ... */
|
||||
|
||||
http_parser *parser = malloc(sizeof(http_parser));
|
||||
http_parser_init(parser, HTTP_REQUEST);
|
||||
parser->data = my_socket;
|
||||
```
|
||||
|
||||
When data is received on the socket execute the parser and check for errors.
|
||||
|
||||
```c
|
||||
size_t len = 80*1024, nparsed;
|
||||
char buf[len];
|
||||
ssize_t recved;
|
||||
|
||||
recved = recv(fd, buf, len, 0);
|
||||
|
||||
if (recved < 0) {
|
||||
/* Handle error. */
|
||||
}
|
||||
|
||||
/* Start up / continue the parser.
|
||||
* Note we pass recved==0 to signal that EOF has been received.
|
||||
*/
|
||||
nparsed = http_parser_execute(parser, &settings, buf, recved);
|
||||
|
||||
if (parser->upgrade) {
|
||||
/* handle new protocol */
|
||||
} else if (nparsed != recved) {
|
||||
/* Handle error. Usually just close the connection. */
|
||||
}
|
||||
```
|
||||
|
||||
HTTP needs to know where the end of the stream is. For example, sometimes
|
||||
servers send responses without Content-Length and expect the client to
|
||||
consume input (for the body) until EOF. To tell http_parser about EOF, give
|
||||
`0` as the fourth parameter to `http_parser_execute()`. Callbacks and errors
|
||||
can still be encountered during an EOF, so one must still be prepared
|
||||
to receive them.
|
||||
|
||||
Scalar valued message information such as `status_code`, `method`, and the
|
||||
HTTP version are stored in the parser structure. This data is only
|
||||
temporally stored in `http_parser` and gets reset on each new message. If
|
||||
this information is needed later, copy it out of the structure during the
|
||||
`headers_complete` callback.
|
||||
|
||||
The parser decodes the transfer-encoding for both requests and responses
|
||||
transparently. That is, a chunked encoding is decoded before being sent to
|
||||
the on_body callback.
|
||||
|
||||
|
||||
The Special Problem of Upgrade
|
||||
------------------------------
|
||||
|
||||
HTTP supports upgrading the connection to a different protocol. An
|
||||
increasingly common example of this is the Web Socket protocol which sends
|
||||
a request like
|
||||
|
||||
GET /demo HTTP/1.1
|
||||
Upgrade: WebSocket
|
||||
Connection: Upgrade
|
||||
Host: example.com
|
||||
Origin: http://example.com
|
||||
WebSocket-Protocol: sample
|
||||
|
||||
followed by non-HTTP data.
|
||||
|
||||
(See http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 for more
|
||||
information the Web Socket protocol.)
|
||||
|
||||
To support this, the parser will treat this as a normal HTTP message without a
|
||||
body, issuing both on_headers_complete and on_message_complete callbacks. However
|
||||
http_parser_execute() will stop parsing at the end of the headers and return.
|
||||
|
||||
The user is expected to check if `parser->upgrade` has been set to 1 after
|
||||
`http_parser_execute()` returns. Non-HTTP data begins at the buffer supplied
|
||||
offset by the return value of `http_parser_execute()`.
|
||||
|
||||
|
||||
Callbacks
|
||||
---------
|
||||
|
||||
During the `http_parser_execute()` call, the callbacks set in
|
||||
`http_parser_settings` will be executed. The parser maintains state and
|
||||
never looks behind, so buffering the data is not necessary. If you need to
|
||||
save certain data for later usage, you can do that from the callbacks.
|
||||
|
||||
There are two types of callbacks:
|
||||
|
||||
* notification `typedef int (*http_cb) (http_parser*);`
|
||||
Callbacks: on_message_begin, on_headers_complete, on_message_complete.
|
||||
* data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);`
|
||||
Callbacks: (requests only) on_url,
|
||||
(common) on_header_field, on_header_value, on_body;
|
||||
|
||||
Callbacks must return 0 on success. Returning a non-zero value indicates
|
||||
error to the parser, making it exit immediately.
|
||||
|
||||
In case you parse HTTP message in chunks (i.e. `read()` request line
|
||||
from socket, parse, read half headers, parse, etc) your data callbacks
|
||||
may be called more than once. Http-parser guarantees that data pointer is only
|
||||
valid for the lifetime of callback. You can also `read()` into a heap allocated
|
||||
buffer to avoid copying memory around if this fits your application.
|
||||
|
||||
Reading headers may be a tricky task if you read/parse headers partially.
|
||||
Basically, you need to remember whether last header callback was field or value
|
||||
and apply the following logic:
|
||||
|
||||
(on_header_field and on_header_value shortened to on_h_*)
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| State (prev. callback) | Callback | Description/action |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| nothing (first call) | on_h_field | Allocate new buffer and copy callback data |
|
||||
| | | into it |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| value | on_h_field | New header started. |
|
||||
| | | Copy current name,value buffers to headers |
|
||||
| | | list and allocate new buffer for new name |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| field | on_h_field | Previous name continues. Reallocate name |
|
||||
| | | buffer and append callback data to it |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| field | on_h_value | Value for current header started. Allocate |
|
||||
| | | new buffer and copy callback data to it |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
| value | on_h_value | Value continues. Reallocate value buffer |
|
||||
| | | and append callback data to it |
|
||||
------------------------ ------------ --------------------------------------------
|
||||
|
||||
|
||||
Parsing URLs
|
||||
------------
|
||||
|
||||
A simplistic zero-copy URL parser is provided as `http_parser_parse_url()`.
|
||||
Users of this library may wish to use it to parse URLs constructed from
|
||||
consecutive `on_url` callbacks.
|
||||
|
||||
See examples of reading in headers:
|
||||
|
||||
* [partial example](http://gist.github.com/155877) in C
|
||||
* [from http-parser tests](http://github.com/joyent/http-parser/blob/37a0ff8/test.c#L403) in C
|
||||
* [from Node library](http://github.com/joyent/node/blob/842eaf4/src/http.js#L284) in Javascript
|
111
3rdparty/http-parser/bench.c
vendored
111
3rdparty/http-parser/bench.c
vendored
@ -1,111 +0,0 @@
|
||||
/* Copyright Fedor Indutny. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
#include "http_parser.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static const char data[] =
|
||||
"POST /joyent/http-parser HTTP/1.1\r\n"
|
||||
"Host: github.com\r\n"
|
||||
"DNT: 1\r\n"
|
||||
"Accept-Encoding: gzip, deflate, sdch\r\n"
|
||||
"Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4\r\n"
|
||||
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/39.0.2171.65 Safari/537.36\r\n"
|
||||
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,"
|
||||
"image/webp,*/*;q=0.8\r\n"
|
||||
"Referer: https://github.com/joyent/http-parser\r\n"
|
||||
"Connection: keep-alive\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n\r\n";
|
||||
static const size_t data_len = sizeof(data) - 1;
|
||||
|
||||
static int on_info(http_parser* p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int on_data(http_parser* p, const char *at, size_t length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static http_parser_settings settings = {
|
||||
.on_message_begin = on_info,
|
||||
.on_headers_complete = on_info,
|
||||
.on_message_complete = on_info,
|
||||
.on_header_field = on_data,
|
||||
.on_header_value = on_data,
|
||||
.on_url = on_data,
|
||||
.on_status = on_data,
|
||||
.on_body = on_data
|
||||
};
|
||||
|
||||
int bench(int iter_count, int silent) {
|
||||
struct http_parser parser;
|
||||
int i;
|
||||
int err;
|
||||
struct timeval start;
|
||||
struct timeval end;
|
||||
float rps;
|
||||
|
||||
if (!silent) {
|
||||
err = gettimeofday(&start, NULL);
|
||||
assert(err == 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < iter_count; i++) {
|
||||
size_t parsed;
|
||||
http_parser_init(&parser, HTTP_REQUEST);
|
||||
|
||||
parsed = http_parser_execute(&parser, &settings, data, data_len);
|
||||
assert(parsed == data_len);
|
||||
}
|
||||
|
||||
if (!silent) {
|
||||
err = gettimeofday(&end, NULL);
|
||||
assert(err == 0);
|
||||
|
||||
fprintf(stdout, "Benchmark result:\n");
|
||||
|
||||
rps = (float) (end.tv_sec - start.tv_sec) +
|
||||
(end.tv_usec - start.tv_usec) * 1e-6f;
|
||||
fprintf(stdout, "Took %f seconds to run\n", rps);
|
||||
|
||||
rps = (float) iter_count / rps;
|
||||
fprintf(stdout, "%f req/sec\n", rps);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc == 2 && strcmp(argv[1], "infinite") == 0) {
|
||||
for (;;)
|
||||
bench(5000000, 1);
|
||||
return 0;
|
||||
} else {
|
||||
return bench(5000000, 0);
|
||||
}
|
||||
}
|
160
3rdparty/http-parser/contrib/parsertrace.c
vendored
160
3rdparty/http-parser/contrib/parsertrace.c
vendored
@ -1,160 +0,0 @@
|
||||
/* Based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev
|
||||
*
|
||||
* Additional changes are licensed under the same terms as NGINX and
|
||||
* copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* Dump what the parser finds to stdout as it happen */
|
||||
|
||||
#include "http_parser.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int on_message_begin(http_parser* _) {
|
||||
(void)_;
|
||||
printf("\n***MESSAGE BEGIN***\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_headers_complete(http_parser* _) {
|
||||
(void)_;
|
||||
printf("\n***HEADERS COMPLETE***\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_message_complete(http_parser* _) {
|
||||
(void)_;
|
||||
printf("\n***MESSAGE COMPLETE***\n\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_url(http_parser* _, const char* at, size_t length) {
|
||||
(void)_;
|
||||
printf("Url: %.*s\n", (int)length, at);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_header_field(http_parser* _, const char* at, size_t length) {
|
||||
(void)_;
|
||||
printf("Header field: %.*s\n", (int)length, at);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_header_value(http_parser* _, const char* at, size_t length) {
|
||||
(void)_;
|
||||
printf("Header value: %.*s\n", (int)length, at);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int on_body(http_parser* _, const char* at, size_t length) {
|
||||
(void)_;
|
||||
printf("Body: %.*s\n", (int)length, at);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usage(const char* name) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s $type $filename\n"
|
||||
" type: -x, where x is one of {r,b,q}\n"
|
||||
" parses file as a Response, reQuest, or Both\n",
|
||||
name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
enum http_parser_type file_type;
|
||||
|
||||
if (argc != 3) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
char* type = argv[1];
|
||||
if (type[0] != '-') {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
switch (type[1]) {
|
||||
/* in the case of "-", type[1] will be NUL */
|
||||
case 'r':
|
||||
file_type = HTTP_RESPONSE;
|
||||
break;
|
||||
case 'q':
|
||||
file_type = HTTP_REQUEST;
|
||||
break;
|
||||
case 'b':
|
||||
file_type = HTTP_BOTH;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
char* filename = argv[2];
|
||||
FILE* file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
perror("fopen");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
long file_length = ftell(file);
|
||||
if (file_length == -1) {
|
||||
perror("ftell");
|
||||
goto fail;
|
||||
}
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
char* data = malloc(file_length);
|
||||
if (fread(data, 1, file_length, file) != (size_t)file_length) {
|
||||
fprintf(stderr, "couldn't read entire file\n");
|
||||
free(data);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
http_parser_settings settings;
|
||||
memset(&settings, 0, sizeof(settings));
|
||||
settings.on_message_begin = on_message_begin;
|
||||
settings.on_url = on_url;
|
||||
settings.on_header_field = on_header_field;
|
||||
settings.on_header_value = on_header_value;
|
||||
settings.on_headers_complete = on_headers_complete;
|
||||
settings.on_body = on_body;
|
||||
settings.on_message_complete = on_message_complete;
|
||||
|
||||
http_parser parser;
|
||||
http_parser_init(&parser, file_type);
|
||||
size_t nparsed = http_parser_execute(&parser, &settings, data, file_length);
|
||||
free(data);
|
||||
|
||||
if (nparsed != (size_t)file_length) {
|
||||
fprintf(stderr,
|
||||
"Error: %s (%s)\n",
|
||||
http_errno_description(HTTP_PARSER_ERRNO(&parser)),
|
||||
http_errno_name(HTTP_PARSER_ERRNO(&parser)));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
fail:
|
||||
fclose(file);
|
||||
return EXIT_FAILURE;
|
||||
}
|
46
3rdparty/http-parser/contrib/url_parser.c
vendored
46
3rdparty/http-parser/contrib/url_parser.c
vendored
@ -1,46 +0,0 @@
|
||||
#include "http_parser.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
dump_url (const char *url, const struct http_parser_url *u)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
printf("\tfield_set: 0x%x, port: %u\n", u->field_set, u->port);
|
||||
for (i = 0; i < UF_MAX; i++) {
|
||||
if ((u->field_set & (1 << i)) == 0) {
|
||||
printf("\tfield_data[%u]: unset\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("\tfield_data[%u]: off: %u, len: %u, part: %.*s\n",
|
||||
i,
|
||||
u->field_data[i].off,
|
||||
u->field_data[i].len,
|
||||
u->field_data[i].len,
|
||||
url + u->field_data[i].off);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
struct http_parser_url u;
|
||||
int len, connect, result;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Syntax : %s connect|get url\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
len = strlen(argv[2]);
|
||||
connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
|
||||
printf("Parsing %s, connect %d\n", argv[2], connect);
|
||||
|
||||
result = http_parser_parse_url(argv[2], len, connect, &u);
|
||||
if (result != 0) {
|
||||
printf("Parse error : %d\n", result);
|
||||
return result;
|
||||
}
|
||||
printf("Parse ok, result : \n");
|
||||
dump_url(argv[2], &u);
|
||||
return 0;
|
||||
}
|
2429
3rdparty/http-parser/http_parser.c
vendored
2429
3rdparty/http-parser/http_parser.c
vendored
File diff suppressed because it is too large
Load Diff
111
3rdparty/http-parser/http_parser.gyp
vendored
111
3rdparty/http-parser/http_parser.gyp
vendored
@ -1,111 +0,0 @@
|
||||
# This file is used with the GYP meta build system.
|
||||
# http://code.google.com/p/gyp/
|
||||
# To build try this:
|
||||
# svn co http://gyp.googlecode.com/svn/trunk gyp
|
||||
# ./gyp/gyp -f make --depth=`pwd` http_parser.gyp
|
||||
# ./out/Debug/test
|
||||
{
|
||||
'target_defaults': {
|
||||
'default_configuration': 'Debug',
|
||||
'configurations': {
|
||||
# TODO: hoist these out and put them somewhere common, because
|
||||
# RuntimeLibrary MUST MATCH across the entire project
|
||||
'Debug': {
|
||||
'defines': [ 'DEBUG', '_DEBUG' ],
|
||||
'cflags': [ '-Wall', '-Wextra', '-O0', '-g', '-ftrapv' ],
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
'RuntimeLibrary': 1, # static debug
|
||||
},
|
||||
},
|
||||
},
|
||||
'Release': {
|
||||
'defines': [ 'NDEBUG' ],
|
||||
'cflags': [ '-Wall', '-Wextra', '-O3' ],
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
'RuntimeLibrary': 0, # static release
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
},
|
||||
'VCLibrarianTool': {
|
||||
},
|
||||
'VCLinkerTool': {
|
||||
'GenerateDebugInformation': 'true',
|
||||
},
|
||||
},
|
||||
'conditions': [
|
||||
['OS == "win"', {
|
||||
'defines': [
|
||||
'WIN32'
|
||||
],
|
||||
}]
|
||||
],
|
||||
},
|
||||
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'http_parser',
|
||||
'type': 'static_library',
|
||||
'include_dirs': [ '.' ],
|
||||
'direct_dependent_settings': {
|
||||
'defines': [ 'HTTP_PARSER_STRICT=0' ],
|
||||
'include_dirs': [ '.' ],
|
||||
},
|
||||
'defines': [ 'HTTP_PARSER_STRICT=0' ],
|
||||
'sources': [ './http_parser.c', ],
|
||||
'conditions': [
|
||||
['OS=="win"', {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
# Compile as C++. http_parser.c is actually C99, but C++ is
|
||||
# close enough in this case.
|
||||
'CompileAs': 2,
|
||||
},
|
||||
},
|
||||
}]
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
'target_name': 'http_parser_strict',
|
||||
'type': 'static_library',
|
||||
'include_dirs': [ '.' ],
|
||||
'direct_dependent_settings': {
|
||||
'defines': [ 'HTTP_PARSER_STRICT=1' ],
|
||||
'include_dirs': [ '.' ],
|
||||
},
|
||||
'defines': [ 'HTTP_PARSER_STRICT=1' ],
|
||||
'sources': [ './http_parser.c', ],
|
||||
'conditions': [
|
||||
['OS=="win"', {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
# Compile as C++. http_parser.c is actually C99, but C++ is
|
||||
# close enough in this case.
|
||||
'CompileAs': 2,
|
||||
},
|
||||
},
|
||||
}]
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
'target_name': 'test-nonstrict',
|
||||
'type': 'executable',
|
||||
'dependencies': [ 'http_parser' ],
|
||||
'sources': [ 'test.c' ]
|
||||
},
|
||||
|
||||
{
|
||||
'target_name': 'test-strict',
|
||||
'type': 'executable',
|
||||
'dependencies': [ 'http_parser_strict' ],
|
||||
'sources': [ 'test.c' ]
|
||||
}
|
||||
]
|
||||
}
|
342
3rdparty/http-parser/http_parser.h
vendored
342
3rdparty/http-parser/http_parser.h
vendored
@ -1,342 +0,0 @@
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef http_parser_h
|
||||
#define http_parser_h
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Also update SONAME in the Makefile whenever you change these. */
|
||||
#define HTTP_PARSER_VERSION_MAJOR 2
|
||||
#define HTTP_PARSER_VERSION_MINOR 5
|
||||
#define HTTP_PARSER_VERSION_PATCH 0
|
||||
|
||||
#include <sys/types.h>
|
||||
#if defined(_WIN32) && !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER<1600)
|
||||
#include <BaseTsd.h>
|
||||
#include <stddef.h>
|
||||
typedef __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run
|
||||
* faster
|
||||
*/
|
||||
#ifndef HTTP_PARSER_STRICT
|
||||
# define HTTP_PARSER_STRICT 1
|
||||
#endif
|
||||
|
||||
/* Maximium header size allowed. If the macro is not defined
|
||||
* before including this header then the default is used. To
|
||||
* change the maximum header size, define the macro in the build
|
||||
* environment (e.g. -DHTTP_MAX_HEADER_SIZE=<value>). To remove
|
||||
* the effective limit on the size of the header, define the macro
|
||||
* to a very large number (e.g. -DHTTP_MAX_HEADER_SIZE=0x7fffffff)
|
||||
*/
|
||||
#ifndef HTTP_MAX_HEADER_SIZE
|
||||
# define HTTP_MAX_HEADER_SIZE (80*1024)
|
||||
#endif
|
||||
|
||||
typedef struct http_parser http_parser;
|
||||
typedef struct http_parser_settings http_parser_settings;
|
||||
|
||||
|
||||
/* Callbacks should return non-zero to indicate an error. The parser will
|
||||
* then halt execution.
|
||||
*
|
||||
* The one exception is on_headers_complete. In a HTTP_RESPONSE parser
|
||||
* returning '1' from on_headers_complete will tell the parser that it
|
||||
* should not expect a body. This is used when receiving a response to a
|
||||
* HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
|
||||
* chunked' headers that indicate the presence of a body.
|
||||
*
|
||||
* http_data_cb does not return data chunks. It will be called arbitrarily
|
||||
* many times for each string. E.G. you might get 10 callbacks for "on_url"
|
||||
* each providing just a few characters more data.
|
||||
*/
|
||||
typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
|
||||
typedef int (*http_cb) (http_parser*);
|
||||
|
||||
|
||||
/* Request Methods */
|
||||
#define HTTP_METHOD_MAP(XX) \
|
||||
XX(0, DELETE, DELETE) \
|
||||
XX(1, GET, GET) \
|
||||
XX(2, HEAD, HEAD) \
|
||||
XX(3, POST, POST) \
|
||||
XX(4, PUT, PUT) \
|
||||
/* pathological */ \
|
||||
XX(5, CONNECT, CONNECT) \
|
||||
XX(6, OPTIONS, OPTIONS) \
|
||||
XX(7, TRACE, TRACE) \
|
||||
/* webdav */ \
|
||||
XX(8, COPY, COPY) \
|
||||
XX(9, LOCK, LOCK) \
|
||||
XX(10, MKCOL, MKCOL) \
|
||||
XX(11, MOVE, MOVE) \
|
||||
XX(12, PROPFIND, PROPFIND) \
|
||||
XX(13, PROPPATCH, PROPPATCH) \
|
||||
XX(14, SEARCH, SEARCH) \
|
||||
XX(15, UNLOCK, UNLOCK) \
|
||||
/* subversion */ \
|
||||
XX(16, REPORT, REPORT) \
|
||||
XX(17, MKACTIVITY, MKACTIVITY) \
|
||||
XX(18, CHECKOUT, CHECKOUT) \
|
||||
XX(19, MERGE, MERGE) \
|
||||
/* upnp */ \
|
||||
XX(20, MSEARCH, M-SEARCH) \
|
||||
XX(21, NOTIFY, NOTIFY) \
|
||||
XX(22, SUBSCRIBE, SUBSCRIBE) \
|
||||
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
|
||||
/* RFC-5789 */ \
|
||||
XX(24, PATCH, PATCH) \
|
||||
XX(25, PURGE, PURGE) \
|
||||
/* CalDAV */ \
|
||||
XX(26, MKCALENDAR, MKCALENDAR) \
|
||||
|
||||
enum http_method
|
||||
{
|
||||
#define XX(num, name, string) HTTP_##name = num,
|
||||
HTTP_METHOD_MAP(XX)
|
||||
#undef XX
|
||||
};
|
||||
|
||||
|
||||
enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
|
||||
|
||||
|
||||
/* Flag values for http_parser.flags field */
|
||||
enum flags
|
||||
{ F_CHUNKED = 1 << 0
|
||||
, F_CONNECTION_KEEP_ALIVE = 1 << 1
|
||||
, F_CONNECTION_CLOSE = 1 << 2
|
||||
, F_CONNECTION_UPGRADE = 1 << 3
|
||||
, F_TRAILING = 1 << 4
|
||||
, F_UPGRADE = 1 << 5
|
||||
, F_SKIPBODY = 1 << 6
|
||||
};
|
||||
|
||||
|
||||
/* Map for errno-related constants
|
||||
*
|
||||
* The provided argument should be a macro that takes 2 arguments.
|
||||
*/
|
||||
#define HTTP_ERRNO_MAP(XX) \
|
||||
/* No error */ \
|
||||
XX(OK, "success") \
|
||||
\
|
||||
/* Callback-related errors */ \
|
||||
XX(CB_message_begin, "the on_message_begin callback failed") \
|
||||
XX(CB_url, "the on_url callback failed") \
|
||||
XX(CB_header_field, "the on_header_field callback failed") \
|
||||
XX(CB_header_value, "the on_header_value callback failed") \
|
||||
XX(CB_headers_complete, "the on_headers_complete callback failed") \
|
||||
XX(CB_body, "the on_body callback failed") \
|
||||
XX(CB_message_complete, "the on_message_complete callback failed") \
|
||||
XX(CB_status, "the on_status callback failed") \
|
||||
XX(CB_chunk_header, "the on_chunk_header callback failed") \
|
||||
XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
|
||||
\
|
||||
/* Parsing-related errors */ \
|
||||
XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
|
||||
XX(HEADER_OVERFLOW, \
|
||||
"too many header bytes seen; overflow detected") \
|
||||
XX(CLOSED_CONNECTION, \
|
||||
"data received after completed connection: close message") \
|
||||
XX(INVALID_VERSION, "invalid HTTP version") \
|
||||
XX(INVALID_STATUS, "invalid HTTP status code") \
|
||||
XX(INVALID_METHOD, "invalid HTTP method") \
|
||||
XX(INVALID_URL, "invalid URL") \
|
||||
XX(INVALID_HOST, "invalid host") \
|
||||
XX(INVALID_PORT, "invalid port") \
|
||||
XX(INVALID_PATH, "invalid path") \
|
||||
XX(INVALID_QUERY_STRING, "invalid query string") \
|
||||
XX(INVALID_FRAGMENT, "invalid fragment") \
|
||||
XX(LF_EXPECTED, "LF character expected") \
|
||||
XX(INVALID_HEADER_TOKEN, "invalid character in header") \
|
||||
XX(INVALID_CONTENT_LENGTH, \
|
||||
"invalid character in content-length header") \
|
||||
XX(INVALID_CHUNK_SIZE, \
|
||||
"invalid character in chunk size header") \
|
||||
XX(INVALID_CONSTANT, "invalid constant string") \
|
||||
XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
|
||||
XX(STRICT, "strict mode assertion failed") \
|
||||
XX(PAUSED, "parser is paused") \
|
||||
XX(UNKNOWN, "an unknown error occurred")
|
||||
|
||||
|
||||
/* Define HPE_* values for each errno value above */
|
||||
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
|
||||
enum http_errno {
|
||||
HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
|
||||
};
|
||||
#undef HTTP_ERRNO_GEN
|
||||
|
||||
|
||||
/* Get an http_errno value from an http_parser */
|
||||
#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
|
||||
|
||||
|
||||
struct http_parser {
|
||||
/** PRIVATE **/
|
||||
unsigned int type : 2; /* enum http_parser_type */
|
||||
unsigned int flags : 7; /* F_* values from 'flags' enum; semi-public */
|
||||
unsigned int state : 7; /* enum state from http_parser.c */
|
||||
unsigned int header_state : 8; /* enum header_state from http_parser.c */
|
||||
unsigned int index : 8; /* index into current matcher */
|
||||
|
||||
uint32_t nread; /* # bytes read in various scenarios */
|
||||
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
|
||||
|
||||
/** READ-ONLY **/
|
||||
unsigned short http_major;
|
||||
unsigned short http_minor;
|
||||
unsigned int status_code : 16; /* responses only */
|
||||
unsigned int method : 8; /* requests only */
|
||||
unsigned int http_errno : 7;
|
||||
|
||||
/* 1 = Upgrade header was present and the parser has exited because of that.
|
||||
* 0 = No upgrade header present.
|
||||
* Should be checked when http_parser_execute() returns in addition to
|
||||
* error checking.
|
||||
*/
|
||||
unsigned int upgrade : 1;
|
||||
|
||||
/** PUBLIC **/
|
||||
void *data; /* A pointer to get hook to the "connection" or "socket" object */
|
||||
};
|
||||
|
||||
|
||||
struct http_parser_settings {
|
||||
http_cb on_message_begin;
|
||||
http_data_cb on_url;
|
||||
http_data_cb on_status;
|
||||
http_data_cb on_header_field;
|
||||
http_data_cb on_header_value;
|
||||
http_cb on_headers_complete;
|
||||
http_data_cb on_body;
|
||||
http_cb on_message_complete;
|
||||
/* When on_chunk_header is called, the current chunk length is stored
|
||||
* in parser->content_length.
|
||||
*/
|
||||
http_cb on_chunk_header;
|
||||
http_cb on_chunk_complete;
|
||||
};
|
||||
|
||||
|
||||
enum http_parser_url_fields
|
||||
{ UF_SCHEMA = 0
|
||||
, UF_HOST = 1
|
||||
, UF_PORT = 2
|
||||
, UF_PATH = 3
|
||||
, UF_QUERY = 4
|
||||
, UF_FRAGMENT = 5
|
||||
, UF_USERINFO = 6
|
||||
, UF_MAX = 7
|
||||
};
|
||||
|
||||
|
||||
/* Result structure for http_parser_parse_url().
|
||||
*
|
||||
* Callers should index into field_data[] with UF_* values iff field_set
|
||||
* has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
|
||||
* because we probably have padding left over), we convert any port to
|
||||
* a uint16_t.
|
||||
*/
|
||||
struct http_parser_url {
|
||||
uint16_t field_set; /* Bitmask of (1 << UF_*) values */
|
||||
uint16_t port; /* Converted UF_PORT string */
|
||||
|
||||
struct {
|
||||
uint16_t off; /* Offset into buffer in which field starts */
|
||||
uint16_t len; /* Length of run in buffer */
|
||||
} field_data[UF_MAX];
|
||||
};
|
||||
|
||||
|
||||
/* Returns the library version. Bits 16-23 contain the major version number,
|
||||
* bits 8-15 the minor version number and bits 0-7 the patch level.
|
||||
* Usage example:
|
||||
*
|
||||
* unsigned long version = http_parser_version();
|
||||
* unsigned major = (version >> 16) & 255;
|
||||
* unsigned minor = (version >> 8) & 255;
|
||||
* unsigned patch = version & 255;
|
||||
* printf("http_parser v%u.%u.%u\n", major, minor, patch);
|
||||
*/
|
||||
unsigned long http_parser_version(void);
|
||||
|
||||
void http_parser_init(http_parser *parser, enum http_parser_type type);
|
||||
|
||||
|
||||
/* Initialize http_parser_settings members to 0
|
||||
*/
|
||||
void http_parser_settings_init(http_parser_settings *settings);
|
||||
|
||||
|
||||
/* Executes the parser. Returns number of parsed bytes. Sets
|
||||
* `parser->http_errno` on error. */
|
||||
size_t http_parser_execute(http_parser *parser,
|
||||
const http_parser_settings *settings,
|
||||
const char *data,
|
||||
size_t len);
|
||||
|
||||
|
||||
/* If http_should_keep_alive() in the on_headers_complete or
|
||||
* on_message_complete callback returns 0, then this should be
|
||||
* the last message on the connection.
|
||||
* If you are the server, respond with the "Connection: close" header.
|
||||
* If you are the client, close the connection.
|
||||
*/
|
||||
int http_should_keep_alive(const http_parser *parser);
|
||||
|
||||
/* Returns a string version of the HTTP method. */
|
||||
const char *http_method_str(enum http_method m);
|
||||
|
||||
/* Return a string name of the given error */
|
||||
const char *http_errno_name(enum http_errno err);
|
||||
|
||||
/* Return a string description of the given error */
|
||||
const char *http_errno_description(enum http_errno err);
|
||||
|
||||
/* Parse a URL; return nonzero on failure */
|
||||
int http_parser_parse_url(const char *buf, size_t buflen,
|
||||
int is_connect,
|
||||
struct http_parser_url *u);
|
||||
|
||||
/* Pause or un-pause the parser; a nonzero value pauses */
|
||||
void http_parser_pause(http_parser *parser, int paused);
|
||||
|
||||
/* Checks if this is the final chunk of the body. */
|
||||
int http_body_is_final(const http_parser *parser);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
3852
3rdparty/http-parser/test.c
vendored
3852
3rdparty/http-parser/test.c
vendored
File diff suppressed because it is too large
Load Diff
51
3rdparty/lsqlite3/.travis.yml
vendored
51
3rdparty/lsqlite3/.travis.yml
vendored
@ -1,51 +0,0 @@
|
||||
#
|
||||
# LuaDist Travis-CI Hook
|
||||
#
|
||||
|
||||
# We assume C build environments
|
||||
language: C
|
||||
|
||||
# Try using multiple Lua Implementations
|
||||
env:
|
||||
- TOOL="gcc" # Use native compiler (GCC usually)
|
||||
- TOOL="clang" # Use clang
|
||||
- TOOL="i686-w64-mingw32" # 32bit MinGW
|
||||
- TOOL="x86_64-w64-mingw32" # 64bit MinGW
|
||||
- TOOL="arm-linux-gnueabihf" # ARM hard-float (hf), linux
|
||||
|
||||
# Crosscompile builds may fail
|
||||
matrix:
|
||||
allow_failures:
|
||||
- env: TOOL="i686-w64-mingw32"
|
||||
- env: TOOL="x86_64-w64-mingw32"
|
||||
- env: TOOL="arm-linux-gnueabihf"
|
||||
|
||||
# Install dependencies
|
||||
install:
|
||||
- git clone git://github.com/LuaDist/Tools.git ~/_tools
|
||||
- ~/_tools/travis/travis install
|
||||
|
||||
# Bootstap
|
||||
before_script:
|
||||
- ~/_tools/travis/travis bootstrap
|
||||
|
||||
# Build the module
|
||||
script:
|
||||
- ~/_tools/travis/travis build
|
||||
|
||||
# Execute additional tests or commands
|
||||
after_script:
|
||||
- ~/_tools/travis/travis test
|
||||
|
||||
# Only watch the master branch
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
# Notify the LuaDist Dev group if needed
|
||||
notifications:
|
||||
recipients:
|
||||
- luadist-dev@googlegroups.com
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: always
|
21
3rdparty/lsqlite3/CMakeLists.txt
vendored
21
3rdparty/lsqlite3/CMakeLists.txt
vendored
@ -1,21 +0,0 @@
|
||||
# Copyright (C) 2007-2012 LuaDist.
|
||||
# Created by Peter Kapec
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the COPYRIGHT file distributed with LuaDist.
|
||||
# Please note that the package source code is licensed under its own license.
|
||||
|
||||
project ( lsqlite3 C )
|
||||
cmake_minimum_required ( VERSION 2.8 )
|
||||
include ( cmake/dist.cmake )
|
||||
include ( lua )
|
||||
|
||||
# Find SQLite3
|
||||
find_package ( SQLite3 REQUIRED )
|
||||
include_directories ( ${SQLITE3_INCLUDE_DIRS} )
|
||||
|
||||
# Create lsqlite module
|
||||
install_lua_module ( lsqlite3 lsqlite3.c lsqlite3.def LINK ${SQLITE3_LIBRARIES} )
|
||||
install_data ( HISTORY README )
|
||||
install_doc( doc/ )
|
||||
install_test ( lunit.lua test.lua tests-sqlite3.lua )
|
||||
install_example ( examples/ )
|
133
3rdparty/lsqlite3/HISTORY
vendored
133
3rdparty/lsqlite3/HISTORY
vendored
@ -1,133 +0,0 @@
|
||||
2007-August-15 e
|
||||
|
||||
Version "0.6-devel"
|
||||
|
||||
Since the "0.5-devel" release of this Lua library...
|
||||
|
||||
Tested with SQLite 3.4.2
|
||||
|
||||
Added some documentation.
|
||||
|
||||
Thanks to Thomas Lauer...
|
||||
|
||||
Moved line 525 ("luaL_checktype(L, 2, LUA_TTABLE);")
|
||||
below the declarations to eliminate non-gcc compiler errors.
|
||||
|
||||
Added create-collation, and associated test case.
|
||||
|
||||
-=-
|
||||
|
||||
2006-October-02 e
|
||||
|
||||
Since the "0.1-devel" release of this Lua library...
|
||||
- updated for Lua 5.1
|
||||
- provide automatic re-preparation of queries after schema changes
|
||||
- made prepared statements with bindings work with for-loops
|
||||
- added some compatibility names
|
||||
- added many test cases, and ported Mike Roth's tests and examples
|
||||
|
||||
-=-
|
||||
|
||||
Below is a header comment from the 2004 "0.1" version of the library...
|
||||
|
||||
/************************************************************************
|
||||
$Id: lsqlite3.c,v 1.3 2004/09/05 17:50:32 tngd Exp $
|
||||
|
||||
To consider:
|
||||
------------
|
||||
|
||||
EXPERIMENTAL APIs
|
||||
|
||||
* sqlite3_progress_handler (implemented)
|
||||
* sqlite3_commit_hook
|
||||
|
||||
TODO?
|
||||
|
||||
* sqlite3_create_collation
|
||||
|
||||
Changes:
|
||||
04-09-2004
|
||||
----------
|
||||
* changed second return value of db:compile to be the rest of the
|
||||
sql statement that was not processed instead of the number of
|
||||
characters of sql not processed (situation in case of success).
|
||||
* progress callback register function parameter order changed.
|
||||
number of opcodes is given before the callback now.
|
||||
|
||||
29-08-2004 e
|
||||
------------
|
||||
* added version() (now supported in sqlite 3.0.5)
|
||||
* added db:errmsg db:errcode db:total_changes
|
||||
* rename vm:get_column to vm:get_value
|
||||
* merge in Tiago's v1.11 change in dbvm_tostring
|
||||
|
||||
23-06-2004 e
|
||||
------------
|
||||
* heavily revised for SQLite3 C API
|
||||
* row values now returned as native type (not always text)
|
||||
* added db:nrows (named rows)
|
||||
* added vm:bind_blob
|
||||
* added vm:get_column
|
||||
* removed encode_binary decode_binary (no longer needed or supported)
|
||||
* removed version encoding error_string (unsupported in v 3.0.1 -- soon?)
|
||||
|
||||
09-04-2004
|
||||
----------
|
||||
* renamed db:rows to db:urows
|
||||
* renamed db:prows to db:rows
|
||||
|
||||
* added vm:get_unames()
|
||||
* added vm:get_utypes()
|
||||
* added vm:get_uvalues()
|
||||
|
||||
08-04-2004
|
||||
----------
|
||||
* changed db:encoding() and db:version() to use sqlite_libencoding() and
|
||||
sqlite_libversion()
|
||||
|
||||
* added vm:columns()
|
||||
* added vm:get_named_types()
|
||||
* added vm:get_named_values()
|
||||
|
||||
* added db:prows - like db:rows but returns a table with the column values
|
||||
instead of returning multiple columns seperatly on each iteration
|
||||
|
||||
* added compatibility functions idata,iname,itype,data,type
|
||||
|
||||
* added luaopen_sqlite_module. allow the library to be loaded without
|
||||
setting a global variable. does the same as luaopen_sqlite, but does not
|
||||
set the global name "sqlite".
|
||||
|
||||
* vm:bind now also returns an error string in case of error
|
||||
|
||||
31-03-2004 - 01-04-2004
|
||||
-----------------------
|
||||
* changed most of the internals. now using references (luaL_ref) in
|
||||
most of the places
|
||||
|
||||
* make the virtual machine interface seperate from the database
|
||||
handle. db:compile now returns a vm handle
|
||||
|
||||
* added db:rows [for ... in db:rows(...) do ... end]
|
||||
|
||||
* added db:close_vm
|
||||
|
||||
* added sqlite.encode_binary and sqlite.decode_binary
|
||||
|
||||
* attempt to do a strict checking on the return type of the user
|
||||
defined functions returned values
|
||||
|
||||
18-01-2004
|
||||
----------
|
||||
* add check on sql function callback to ensure there is enough stack
|
||||
space to pass column values as parameters
|
||||
|
||||
03-12-2003
|
||||
----------
|
||||
* callback functions now have to return boolean values to abort or
|
||||
continue operation instead of a zero or non-zero value
|
||||
|
||||
06-12-2003
|
||||
----------
|
||||
* make version member of sqlite table a function instead of a string
|
||||
************************************************************************/
|
106
3rdparty/lsqlite3/Makefile
vendored
106
3rdparty/lsqlite3/Makefile
vendored
@ -1,106 +0,0 @@
|
||||
# makefile for lsqlite3 library for Lua
|
||||
|
||||
ifneq "$(shell pkg-config --version)" ""
|
||||
# automagic setup (OS X fink, Linux apt-get, ..)
|
||||
#
|
||||
LUAINC= $(shell pkg-config --cflags lua)
|
||||
LUALIB= $(shell pkg-config --libs lua)
|
||||
LUAEXE= lua
|
||||
# Now, we actually want to _not_ push in stuff to the distro Lua CMOD directory,
|
||||
# way better to play within /usr/local/lib/lua/5.1/
|
||||
#LUACMOD= $(shell pkg-config --variable=INSTALL_CMOD lua)
|
||||
LUACMOD= /usr/local/lib/lua/5.1/
|
||||
#
|
||||
SQLITE3INC= $(shell pkg-config --cflags sqlite3)
|
||||
SQLITE3LIB= $(shell pkg-config --libs sqlite3)
|
||||
else
|
||||
# manual setup (change these to reflect your Lua installation)
|
||||
#
|
||||
BASE= /usr/local
|
||||
LUAINC= -I$(BASE)/include
|
||||
LUAEXE= $(BASE)/bin/lua.exe
|
||||
# LUALIB= -L$(BASE)/lib -llua51
|
||||
# LUACMOD= $(BASE)/lib/lua/5.1/
|
||||
# Windows' LUA_CDIR and LUALIB are both the same as the Lua executable's directory...
|
||||
LUALIB= -L$(BASE)/bin -llua51
|
||||
LUACMOD= $(BASE)/bin
|
||||
#
|
||||
SQLITE3INC= -I$(BASE)/include
|
||||
SQLITE3LIB= -L$(BASE)/bin -lsqlite3
|
||||
#
|
||||
POD2HTML= perl -x -S doc/pod2html.pl
|
||||
endif
|
||||
|
||||
TMP=./tmp
|
||||
DISTDIR=./archive
|
||||
|
||||
# OS detection
|
||||
#
|
||||
SHFLAGS=-shared
|
||||
UNAME= $(shell uname)
|
||||
ifeq "$(UNAME)" "Linux"
|
||||
_SO=so
|
||||
SHFLAGS= -fPIC
|
||||
endif
|
||||
ifneq "" "$(findstring BSD,$(UNAME))"
|
||||
_SO=so
|
||||
endif
|
||||
ifeq "$(UNAME)" "Darwin"
|
||||
_SO=bundle
|
||||
SHFLAGS= -bundle
|
||||
endif
|
||||
ifneq "" "$(findstring msys,$(OSTYPE))" # 'msys'
|
||||
_SO=dll
|
||||
endif
|
||||
|
||||
ifndef _SO
|
||||
$(error $(UNAME))
|
||||
$(error Unknown OS)
|
||||
endif
|
||||
|
||||
# no need to change anything below here - HAH!
|
||||
CFLAGS= $(INCS) $(DEFS) $(WARN) -O2 $(SHFLAGS)
|
||||
WARN= -Wall #-ansi -pedantic -Wall
|
||||
INCS= $(LUAINC) $(SQLITE3INC)
|
||||
LIBS= $(LUALIB) $(SQLITE3LIB)
|
||||
|
||||
MYNAME= sqlite3
|
||||
MYLIB= l$(MYNAME)
|
||||
|
||||
VER=$(shell svnversion -c . | sed 's/.*://')
|
||||
TARFILE = $(DISTDIR)/$(MYLIB)-$(VER).tar.gz
|
||||
|
||||
OBJS= $(MYLIB).o
|
||||
T= $(MYLIB).$(_SO)
|
||||
|
||||
all: $T
|
||||
|
||||
test: $T
|
||||
$(LUAEXE) test.lua
|
||||
$(LUAEXE) tests-sqlite3.lua
|
||||
|
||||
$T: $(OBJS)
|
||||
$(CC) $(SHFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||
|
||||
install:
|
||||
cp $T $(LUACMOD)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $T core core.* a.out test.db
|
||||
|
||||
html:
|
||||
$(POD2HTML) --title="LuaSQLite 3" --infile=doc/lsqlite3.pod --outfile=doc/lsqlite3.html
|
||||
|
||||
dist: html
|
||||
echo 'Exporting...'
|
||||
mkdir -p $(TMP)
|
||||
mkdir -p $(DISTDIR)
|
||||
svn export -r HEAD . $(TMP)/$(MYLIB)-$(VER)
|
||||
mkdir -p $(TMP)/$(MYLIB)-$(VER)/doc
|
||||
cp -p doc/lsqlite3.html $(TMP)/$(MYLIB)-$(VER)/doc
|
||||
echo 'Compressing...'
|
||||
tar -zcf $(TARFILE) -C $(TMP) $(MYLIB)-$(VER)
|
||||
rm -fr $(TMP)/$(MYLIB)-$(VER)
|
||||
echo 'Done.'
|
||||
|
||||
.PHONY: all test clean dist install
|
8
3rdparty/lsqlite3/README
vendored
8
3rdparty/lsqlite3/README
vendored
@ -1,8 +0,0 @@
|
||||
|
||||
LuaSQLite 3 provides a means to manipulate SQLite3
|
||||
databases directly from lua using Lua 5.
|
||||
|
||||
To use this library you need SQLite3 library.
|
||||
You can get it from http://www.sqlite.org/
|
||||
|
||||
Lua 5 is available from http://www.lua.org/
|
118
3rdparty/lsqlite3/cmake/FindLua.cmake
vendored
118
3rdparty/lsqlite3/cmake/FindLua.cmake
vendored
@ -1,118 +0,0 @@
|
||||
# Locate Lua library
|
||||
# This module defines
|
||||
# LUA_EXECUTABLE, if found
|
||||
# LUA_FOUND, if false, do not try to link to Lua
|
||||
# LUA_LIBRARIES
|
||||
# LUA_INCLUDE_DIR, where to find lua.h
|
||||
# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
|
||||
#
|
||||
# Note that the expected include convention is
|
||||
# #include "lua.h"
|
||||
# and not
|
||||
# #include <lua/lua.h>
|
||||
# This is because, the lua location is not standardized and may exist
|
||||
# in locations other than lua/
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2007-2009 Kitware, Inc.
|
||||
# Modified to support Lua 5.2 by LuaDist 2012
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
#
|
||||
# The required version of Lua can be specified using the
|
||||
# standard syntax, e.g. FIND_PACKAGE(Lua 5.1)
|
||||
# Otherwise the module will search for any available Lua implementation
|
||||
|
||||
# Always search for non-versioned lua first (recommended)
|
||||
SET(_POSSIBLE_LUA_INCLUDE include include/lua)
|
||||
SET(_POSSIBLE_LUA_EXECUTABLE lua)
|
||||
SET(_POSSIBLE_LUA_LIBRARY lua)
|
||||
|
||||
# Determine possible naming suffixes (there is no standard for this)
|
||||
IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
|
||||
SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}")
|
||||
ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
|
||||
SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1")
|
||||
ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
|
||||
|
||||
# Set up possible search names and locations
|
||||
FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES})
|
||||
LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}")
|
||||
LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}")
|
||||
LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}")
|
||||
ENDFOREACH(_SUFFIX)
|
||||
|
||||
# Find the lua executable
|
||||
FIND_PROGRAM(LUA_EXECUTABLE
|
||||
NAMES ${_POSSIBLE_LUA_EXECUTABLE}
|
||||
)
|
||||
|
||||
# Find the lua header
|
||||
FIND_PATH(LUA_INCLUDE_DIR lua.h
|
||||
HINTS
|
||||
$ENV{LUA_DIR}
|
||||
PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE}
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
|
||||
# Find the lua library
|
||||
FIND_LIBRARY(LUA_LIBRARY
|
||||
NAMES ${_POSSIBLE_LUA_LIBRARY}
|
||||
HINTS
|
||||
$ENV{LUA_DIR}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt
|
||||
)
|
||||
|
||||
IF(LUA_LIBRARY)
|
||||
# include the math library for Unix
|
||||
IF(UNIX AND NOT APPLE)
|
||||
FIND_LIBRARY(LUA_MATH_LIBRARY m)
|
||||
SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
|
||||
# For Windows and Mac, don't need to explicitly include the math library
|
||||
ELSE(UNIX AND NOT APPLE)
|
||||
SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
|
||||
ENDIF(UNIX AND NOT APPLE)
|
||||
ENDIF(LUA_LIBRARY)
|
||||
|
||||
# Determine Lua version
|
||||
IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
|
||||
FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
|
||||
|
||||
STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
|
||||
UNSET(lua_version_str)
|
||||
ENDIF()
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
|
||||
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
|
||||
VERSION_VAR LUA_VERSION_STRING)
|
||||
|
||||
MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE)
|
||||
|
37
3rdparty/lsqlite3/cmake/FindSQLite3.cmake
vendored
37
3rdparty/lsqlite3/cmake/FindSQLite3.cmake
vendored
@ -1,37 +0,0 @@
|
||||
# Copyright (C) 2007-2009 LuaDist.
|
||||
# Created by Peter Kapec <kapecp@gmail.com>
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the COPYRIGHT file distributed with LuaDist.
|
||||
# Note:
|
||||
# Searching headers and libraries is very simple and is NOT as powerful as scripts
|
||||
# distributed with CMake, because LuaDist defines directories to search for.
|
||||
# Everyone is encouraged to contact the author with improvements. Maybe this file
|
||||
# becomes part of CMake distribution sometimes.
|
||||
|
||||
# - Find sqlite3
|
||||
# Find the native SQLITE3 headers and libraries.
|
||||
#
|
||||
# SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc.
|
||||
# SQLITE3_LIBRARIES - List of libraries when using sqlite.
|
||||
# SQLITE3_FOUND - True if sqlite found.
|
||||
|
||||
# Look for the header file.
|
||||
FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
|
||||
|
||||
# Look for the library.
|
||||
FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3 libsqlite3 sqlite libsqlite)
|
||||
|
||||
# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE.
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)
|
||||
|
||||
# Copy the results to the output variables.
|
||||
IF(SQLITE3_FOUND)
|
||||
SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
|
||||
SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
|
||||
ELSE(SQLITE3_FOUND)
|
||||
SET(SQLITE3_LIBRARIES)
|
||||
SET(SQLITE3_INCLUDE_DIRS)
|
||||
ENDIF(SQLITE3_FOUND)
|
||||
|
||||
MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
|
321
3rdparty/lsqlite3/cmake/dist.cmake
vendored
321
3rdparty/lsqlite3/cmake/dist.cmake
vendored
@ -1,321 +0,0 @@
|
||||
# LuaDist CMake utility library.
|
||||
# Provides sane project defaults and macros common to LuaDist CMake builds.
|
||||
#
|
||||
# Copyright (C) 2007-2012 LuaDist.
|
||||
# by David Manura, Peter Drahoš
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the COPYRIGHT file distributed with LuaDist.
|
||||
# Please note that the package source code is licensed under its own license.
|
||||
|
||||
## Extract information from dist.info
|
||||
if ( NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dist.info )
|
||||
message ( FATAL_ERROR
|
||||
"Missing dist.info file (${CMAKE_CURRENT_SOURCE_DIR}/dist.info)." )
|
||||
endif ()
|
||||
file ( READ ${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO )
|
||||
if ( "${DIST_INFO}" STREQUAL "" )
|
||||
message ( FATAL_ERROR "Failed to load dist.info." )
|
||||
endif ()
|
||||
# Reads field `name` from dist.info string `DIST_INFO` into variable `var`.
|
||||
macro ( _parse_dist_field name var )
|
||||
string ( REGEX REPLACE ".*${name}[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
|
||||
${var} "${DIST_INFO}" )
|
||||
if ( ${var} STREQUAL DIST_INFO )
|
||||
message ( FATAL_ERROR "Failed to extract \"${var}\" from dist.info" )
|
||||
endif ()
|
||||
endmacro ()
|
||||
#
|
||||
_parse_dist_field ( name DIST_NAME )
|
||||
_parse_dist_field ( version DIST_VERSION )
|
||||
_parse_dist_field ( license DIST_LICENSE )
|
||||
_parse_dist_field ( author DIST_AUTHOR )
|
||||
_parse_dist_field ( maintainer DIST_MAINTAINER )
|
||||
_parse_dist_field ( url DIST_URL )
|
||||
_parse_dist_field ( desc DIST_DESC )
|
||||
message ( "DIST_NAME: ${DIST_NAME}")
|
||||
message ( "DIST_VERSION: ${DIST_VERSION}")
|
||||
message ( "DIST_LICENSE: ${DIST_LICENSE}")
|
||||
message ( "DIST_AUTHOR: ${DIST_AUTHOR}")
|
||||
message ( "DIST_MAINTAINER: ${DIST_MAINTAINER}")
|
||||
message ( "DIST_URL: ${DIST_URL}")
|
||||
message ( "DIST_DESC: ${DIST_DESC}")
|
||||
string ( REGEX REPLACE ".*depends[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
|
||||
DIST_DEPENDS ${DIST_INFO} )
|
||||
if ( DIST_DEPENDS STREQUAL DIST_INFO )
|
||||
set ( DIST_DEPENDS "" )
|
||||
endif ()
|
||||
message ( "DIST_DEPENDS: ${DIST_DEPENDS}")
|
||||
## 2DO: Parse DIST_DEPENDS and try to install Dependencies with automatically using externalproject_add
|
||||
|
||||
|
||||
## INSTALL DEFAULTS (Relative to CMAKE_INSTALL_PREFIX)
|
||||
# Primary paths
|
||||
set ( INSTALL_BIN bin CACHE PATH "Where to install binaries to." )
|
||||
set ( INSTALL_LIB lib CACHE PATH "Where to install libraries to." )
|
||||
set ( INSTALL_INC include CACHE PATH "Where to install headers to." )
|
||||
set ( INSTALL_ETC etc CACHE PATH "Where to store configuration files" )
|
||||
set ( INSTALL_SHARE share CACHE PATH "Directory for shared data." )
|
||||
|
||||
# Secondary paths
|
||||
option ( INSTALL_VERSION
|
||||
"Install runtime libraries and executables with version information." OFF)
|
||||
set ( INSTALL_DATA ${INSTALL_SHARE}/${DIST_NAME} CACHE PATH
|
||||
"Directory the package can store documentation, tests or other data in.")
|
||||
set ( INSTALL_DOC ${INSTALL_DATA}/doc CACHE PATH
|
||||
"Recommended directory to install documentation into.")
|
||||
set ( INSTALL_EXAMPLE ${INSTALL_DATA}/example CACHE PATH
|
||||
"Recommended directory to install examples into.")
|
||||
set ( INSTALL_TEST ${INSTALL_DATA}/test CACHE PATH
|
||||
"Recommended directory to install tests into.")
|
||||
set ( INSTALL_FOO ${INSTALL_DATA}/etc CACHE PATH
|
||||
"Where to install additional files")
|
||||
|
||||
# Tweaks and other defaults
|
||||
# Setting CMAKE to use loose block and search for find modules in source directory
|
||||
set ( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )
|
||||
set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH} )
|
||||
option ( BUILD_SHARED_LIBS "Build shared libraries" ON )
|
||||
|
||||
# In MSVC, prevent warnings that can occur when using standard libraries.
|
||||
if ( MSVC )
|
||||
add_definitions ( -D_CRT_SECURE_NO_WARNINGS )
|
||||
endif ()
|
||||
|
||||
# RPath and relative linking
|
||||
option ( USE_RPATH "Use relative linking." ON)
|
||||
if ( USE_RPATH )
|
||||
string ( REGEX REPLACE "[^!/]+" ".." UP_DIR ${INSTALL_BIN} )
|
||||
set ( CMAKE_SKIP_BUILD_RPATH FALSE CACHE STRING "" FORCE )
|
||||
set ( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE STRING "" FORCE )
|
||||
set ( CMAKE_INSTALL_RPATH $ORIGIN/${UP_DIR}/${INSTALL_LIB}
|
||||
CACHE STRING "" FORCE )
|
||||
set ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE STRING "" FORCE )
|
||||
set ( CMAKE_INSTALL_NAME_DIR @executable_path/${UP_DIR}/${INSTALL_LIB}
|
||||
CACHE STRING "" FORCE )
|
||||
endif ()
|
||||
|
||||
## MACROS
|
||||
# Parser macro
|
||||
macro ( parse_arguments prefix arg_names option_names)
|
||||
set ( DEFAULT_ARGS )
|
||||
foreach ( arg_name ${arg_names} )
|
||||
set ( ${prefix}_${arg_name} )
|
||||
endforeach ()
|
||||
foreach ( option ${option_names} )
|
||||
set ( ${prefix}_${option} FALSE )
|
||||
endforeach ()
|
||||
|
||||
set ( current_arg_name DEFAULT_ARGS )
|
||||
set ( current_arg_list )
|
||||
foreach ( arg ${ARGN} )
|
||||
set ( larg_names ${arg_names} )
|
||||
list ( FIND larg_names "${arg}" is_arg_name )
|
||||
if ( is_arg_name GREATER -1 )
|
||||
set ( ${prefix}_${current_arg_name} ${current_arg_list} )
|
||||
set ( current_arg_name ${arg} )
|
||||
set ( current_arg_list )
|
||||
else ()
|
||||
set ( loption_names ${option_names} )
|
||||
list ( FIND loption_names "${arg}" is_option )
|
||||
if ( is_option GREATER -1 )
|
||||
set ( ${prefix}_${arg} TRUE )
|
||||
else ()
|
||||
set ( current_arg_list ${current_arg_list} ${arg} )
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
set ( ${prefix}_${current_arg_name} ${current_arg_list} )
|
||||
endmacro ()
|
||||
|
||||
|
||||
# install_executable ( executable_targets )
|
||||
# Installs any executables generated using "add_executable".
|
||||
# USE: install_executable ( lua )
|
||||
# NOTE: subdirectories are NOT supported
|
||||
set ( CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "${DIST_NAME} Runtime" )
|
||||
set ( CPACK_COMPONENT_RUNTIME_DESCRIPTION
|
||||
"Executables and runtime libraries. Installed into ${INSTALL_BIN}." )
|
||||
macro ( install_executable )
|
||||
foreach ( _file ${ARGN} )
|
||||
if ( INSTALL_VERSION )
|
||||
set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}
|
||||
SOVERSION ${DIST_VERSION} )
|
||||
endif ()
|
||||
install ( TARGETS ${_file} RUNTIME DESTINATION ${INSTALL_BIN}
|
||||
COMPONENT Runtime )
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_library ( library_targets )
|
||||
# Installs any libraries generated using "add_library" into apropriate places.
|
||||
# USE: install_library ( libexpat )
|
||||
# NOTE: subdirectories are NOT supported
|
||||
set ( CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "${DIST_NAME} Development Libraries" )
|
||||
set ( CPACK_COMPONENT_LIBRARY_DESCRIPTION
|
||||
"Static and import libraries needed for development. Installed into ${INSTALL_LIB} or ${INSTALL_BIN}." )
|
||||
macro ( install_library )
|
||||
foreach ( _file ${ARGN} )
|
||||
if ( INSTALL_VERSION )
|
||||
set_target_properties ( ${_file} PROPERTIES VERSION ${DIST_VERSION}
|
||||
SOVERSION ${DIST_VERSION} )
|
||||
endif ()
|
||||
install ( TARGETS ${_file}
|
||||
RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT Runtime
|
||||
LIBRARY DESTINATION ${INSTALL_LIB} COMPONENT Runtime
|
||||
ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT Library )
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# helper function for various install_* functions, for PATTERN/REGEX args.
|
||||
macro ( _complete_install_args )
|
||||
if ( NOT("${_ARG_PATTERN}" STREQUAL "") )
|
||||
set ( _ARG_PATTERN PATTERN ${_ARG_PATTERN} )
|
||||
endif ()
|
||||
if ( NOT("${_ARG_REGEX}" STREQUAL "") )
|
||||
set ( _ARG_REGEX REGEX ${_ARG_REGEX} )
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# install_header ( files/directories [INTO destination] )
|
||||
# Install a directories or files into header destination.
|
||||
# USE: install_header ( lua.h luaconf.h ) or install_header ( GL )
|
||||
# USE: install_header ( mylib.h INTO mylib )
|
||||
# For directories, supports optional PATTERN/REGEX arguments like install().
|
||||
set ( CPACK_COMPONENT_HEADER_DISPLAY_NAME "${DIST_NAME} Development Headers" )
|
||||
set ( CPACK_COMPONENT_HEADER_DESCRIPTION
|
||||
"Headers needed for development. Installed into ${INSTALL_INC}." )
|
||||
macro ( install_header )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}
|
||||
COMPONENT Header ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_INC}/${_ARG_INTO}
|
||||
COMPONENT Header )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_data ( files/directories [INTO destination] )
|
||||
# This installs additional data files or directories.
|
||||
# USE: install_data ( extra data.dat )
|
||||
# USE: install_data ( image1.png image2.png INTO images )
|
||||
# For directories, supports optional PATTERN/REGEX arguments like install().
|
||||
set ( CPACK_COMPONENT_DATA_DISPLAY_NAME "${DIST_NAME} Data" )
|
||||
set ( CPACK_COMPONENT_DATA_DESCRIPTION
|
||||
"Application data. Installed into ${INSTALL_DATA}." )
|
||||
macro ( install_data )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file}
|
||||
DESTINATION ${INSTALL_DATA}/${_ARG_INTO}
|
||||
COMPONENT Data ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_DATA}/${_ARG_INTO}
|
||||
COMPONENT Data )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# INSTALL_DOC ( files/directories [INTO destination] )
|
||||
# This installs documentation content
|
||||
# USE: install_doc ( doc/ doc.pdf )
|
||||
# USE: install_doc ( index.html INTO html )
|
||||
# For directories, supports optional PATTERN/REGEX arguments like install().
|
||||
set ( CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "${DIST_NAME} Documentation" )
|
||||
set ( CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION
|
||||
"Application documentation. Installed into ${INSTALL_DOC}." )
|
||||
macro ( install_doc )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}
|
||||
COMPONENT Documentation ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_DOC}/${_ARG_INTO}
|
||||
COMPONENT Documentation )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_example ( files/directories [INTO destination] )
|
||||
# This installs additional examples
|
||||
# USE: install_example ( examples/ exampleA )
|
||||
# USE: install_example ( super_example super_data INTO super)
|
||||
# For directories, supports optional PATTERN/REGEX argument like install().
|
||||
set ( CPACK_COMPONENT_EXAMPLE_DISPLAY_NAME "${DIST_NAME} Examples" )
|
||||
set ( CPACK_COMPONENT_EXAMPLE_DESCRIPTION
|
||||
"Examples and their associated data. Installed into ${INSTALL_EXAMPLE}." )
|
||||
macro ( install_example )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}
|
||||
COMPONENT Example ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_EXAMPLE}/${_ARG_INTO}
|
||||
COMPONENT Example )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_test ( files/directories [INTO destination] )
|
||||
# This installs tests and test files, DOES NOT EXECUTE TESTS
|
||||
# USE: install_test ( my_test data.sql )
|
||||
# USE: install_test ( feature_x_test INTO x )
|
||||
# For directories, supports optional PATTERN/REGEX argument like install().
|
||||
set ( CPACK_COMPONENT_TEST_DISPLAY_NAME "${DIST_NAME} Tests" )
|
||||
set ( CPACK_COMPONENT_TEST_DESCRIPTION
|
||||
"Tests and associated data. Installed into ${INSTALL_TEST}." )
|
||||
macro ( install_test )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}
|
||||
COMPONENT Test ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_TEST}/${_ARG_INTO}
|
||||
COMPONENT Test )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
# install_foo ( files/directories [INTO destination] )
|
||||
# This installs optional or otherwise unneeded content
|
||||
# USE: install_foo ( etc/ example.doc )
|
||||
# USE: install_foo ( icon.png logo.png INTO icons)
|
||||
# For directories, supports optional PATTERN/REGEX argument like install().
|
||||
set ( CPACK_COMPONENT_OTHER_DISPLAY_NAME "${DIST_NAME} Unspecified Content" )
|
||||
set ( CPACK_COMPONENT_OTHER_DESCRIPTION
|
||||
"Other unspecified content. Installed into ${INSTALL_FOO}." )
|
||||
macro ( install_foo )
|
||||
parse_arguments ( _ARG "INTO;PATTERN;REGEX" "" ${ARGN} )
|
||||
_complete_install_args()
|
||||
foreach ( _file ${_ARG_DEFAULT_ARGS} )
|
||||
if ( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${_file}" )
|
||||
install ( DIRECTORY ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}
|
||||
COMPONENT Other ${_ARG_PATTERN} ${_ARG_REGEX} )
|
||||
else ()
|
||||
install ( FILES ${_file} DESTINATION ${INSTALL_FOO}/${_ARG_INTO}
|
||||
COMPONENT Other )
|
||||
endif ()
|
||||
endforeach()
|
||||
endmacro ()
|
||||
|
||||
## CTest defaults
|
||||
|
||||
## CPack defaults
|
||||
set ( CPACK_GENERATOR "ZIP" )
|
||||
set ( CPACK_STRIP_FILES TRUE )
|
||||
set ( CPACK_PACKAGE_NAME "${DIST_NAME}" )
|
||||
set ( CPACK_PACKAGE_VERSION "${DIST_VERSION}")
|
||||
set ( CPACK_PACKAGE_VENDOR "LuaDist" )
|
||||
set ( CPACK_COMPONENTS_ALL Runtime Library Header Data Documentation Example Other )
|
||||
include ( CPack )
|
293
3rdparty/lsqlite3/cmake/lua.cmake
vendored
293
3rdparty/lsqlite3/cmake/lua.cmake
vendored
@ -1,293 +0,0 @@
|
||||
# LuaDist CMake utility library for Lua.
|
||||
#
|
||||
# Copyright (C) 2007-2012 LuaDist.
|
||||
# by David Manura, Peter Drahos
|
||||
# Redistribution and use of this file is allowed according to the terms of the MIT license.
|
||||
# For details see the COPYRIGHT file distributed with LuaDist.
|
||||
# Please note that the package source code is licensed under its own license.
|
||||
|
||||
set ( INSTALL_LMOD ${INSTALL_LIB}/lua
|
||||
CACHE PATH "Directory to install Lua modules." )
|
||||
set ( INSTALL_CMOD ${INSTALL_LIB}/lua
|
||||
CACHE PATH "Directory to install Lua binary modules." )
|
||||
|
||||
option ( SKIP_LUA_WRAPPER
|
||||
"Do not build and install Lua executable wrappers." OFF)
|
||||
|
||||
# List of (Lua module name, file path) pairs.
|
||||
# Used internally by add_lua_test. Built by add_lua_module.
|
||||
set ( _lua_modules )
|
||||
|
||||
# utility function: appends path `path` to path `basepath`, properly
|
||||
# handling cases when `path` may be relative or absolute.
|
||||
macro ( _append_path basepath path result )
|
||||
if ( IS_ABSOLUTE "${path}" )
|
||||
set ( ${result} "${path}" )
|
||||
else ()
|
||||
set ( ${result} "${basepath}/${path}" )
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# install_lua_executable ( target source )
|
||||
# Automatically generate a binary if srlua package is available
|
||||
# The application or its source will be placed into /bin
|
||||
# If the application source did not have .lua suffix then it will be added
|
||||
# USE: lua_executable ( sputnik src/sputnik.lua )
|
||||
macro ( install_lua_executable _name _source )
|
||||
get_filename_component ( _source_name ${_source} NAME_WE )
|
||||
# Find srlua and glue
|
||||
find_program( SRLUA_EXECUTABLE NAMES srlua )
|
||||
find_program( GLUE_EXECUTABLE NAMES glue )
|
||||
# Executable output
|
||||
set ( _exe ${CMAKE_CURRENT_BINARY_DIR}/${_name}${CMAKE_EXECUTABLE_SUFFIX} )
|
||||
if ( NOT SKIP_LUA_WRAPPER AND SRLUA_EXECUTABLE AND GLUE_EXECUTABLE )
|
||||
# Generate binary gluing the lua code to srlua, this is a robuust approach for most systems
|
||||
add_custom_command(
|
||||
OUTPUT ${_exe}
|
||||
COMMAND ${GLUE_EXECUTABLE}
|
||||
ARGS ${SRLUA_EXECUTABLE} ${_source} ${_exe}
|
||||
DEPENDS ${_source}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
# Make sure we have a target associated with the binary
|
||||
add_custom_target(${_name} ALL
|
||||
DEPENDS ${_exe}
|
||||
)
|
||||
# Install with run permissions
|
||||
install ( PROGRAMS ${_exe} DESTINATION ${INSTALL_BIN} COMPONENT Runtime)
|
||||
# Also install source as optional resurce
|
||||
install ( FILES ${_source} DESTINATION ${INSTALL_FOO} COMPONENT Other )
|
||||
else()
|
||||
# Install into bin as is but without the lua suffix, we assume the executable uses UNIX shebang/hash-bang magic
|
||||
install ( PROGRAMS ${_source} DESTINATION ${INSTALL_BIN}
|
||||
RENAME ${_source_name}
|
||||
COMPONENT Runtime
|
||||
)
|
||||
endif()
|
||||
endmacro ()
|
||||
|
||||
macro ( _lua_module_helper is_install _name )
|
||||
parse_arguments ( _MODULE "LINK;ALL_IN_ONE" "" ${ARGN} )
|
||||
# _target is CMake-compatible target name for module (e.g. socket_core).
|
||||
# _module is relative path of target (e.g. socket/core),
|
||||
# without extension (e.g. .lua/.so/.dll).
|
||||
# _MODULE_SRC is list of module source files (e.g. .lua and .c files).
|
||||
# _MODULE_NAMES is list of module names (e.g. socket.core).
|
||||
if ( _MODULE_ALL_IN_ONE )
|
||||
string ( REGEX REPLACE "\\..*" "" _target "${_name}" )
|
||||
string ( REGEX REPLACE "\\..*" "" _module "${_name}" )
|
||||
set ( _target "${_target}_all_in_one")
|
||||
set ( _MODULE_SRC ${_MODULE_ALL_IN_ONE} )
|
||||
set ( _MODULE_NAMES ${_name} ${_MODULE_DEFAULT_ARGS} )
|
||||
else ()
|
||||
string ( REPLACE "." "_" _target "${_name}" )
|
||||
string ( REPLACE "." "/" _module "${_name}" )
|
||||
set ( _MODULE_SRC ${_MODULE_DEFAULT_ARGS} )
|
||||
set ( _MODULE_NAMES ${_name} )
|
||||
endif ()
|
||||
if ( NOT _MODULE_SRC )
|
||||
message ( FATAL_ERROR "no module sources specified" )
|
||||
endif ()
|
||||
list ( GET _MODULE_SRC 0 _first_source )
|
||||
|
||||
get_filename_component ( _ext ${_first_source} EXT )
|
||||
if ( _ext STREQUAL ".lua" ) # Lua source module
|
||||
list ( LENGTH _MODULE_SRC _len )
|
||||
if ( _len GREATER 1 )
|
||||
message ( FATAL_ERROR "more than one source file specified" )
|
||||
endif ()
|
||||
|
||||
set ( _module "${_module}.lua" )
|
||||
|
||||
get_filename_component ( _module_dir ${_module} PATH )
|
||||
get_filename_component ( _module_filename ${_module} NAME )
|
||||
_append_path ( "${CMAKE_CURRENT_SOURCE_DIR}" "${_first_source}" _module_path )
|
||||
list ( APPEND _lua_modules "${_name}" "${_module_path}" )
|
||||
|
||||
if ( ${is_install} )
|
||||
install ( FILES ${_first_source} DESTINATION ${INSTALL_LMOD}/${_module_dir}
|
||||
RENAME ${_module_filename}
|
||||
COMPONENT Runtime
|
||||
)
|
||||
endif ()
|
||||
else () # Lua C binary module
|
||||
enable_language ( C )
|
||||
find_package ( Lua REQUIRED )
|
||||
include_directories ( ${LUA_INCLUDE_DIR} )
|
||||
|
||||
set ( _module "${_module}${CMAKE_SHARED_MODULE_SUFFIX}" )
|
||||
|
||||
get_filename_component ( _module_dir ${_module} PATH )
|
||||
get_filename_component ( _module_filenamebase ${_module} NAME_WE )
|
||||
foreach ( _thisname ${_MODULE_NAMES} )
|
||||
list ( APPEND _lua_modules "${_thisname}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_CFG_INTDIR}/${_module}" )
|
||||
endforeach ()
|
||||
|
||||
add_library( ${_target} MODULE ${_MODULE_SRC})
|
||||
target_link_libraries ( ${_target} ${LUA_LIBRARY} ${_MODULE_LINK} )
|
||||
set_target_properties ( ${_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
||||
"${_module_dir}" PREFIX "" OUTPUT_NAME "${_module_filenamebase}" )
|
||||
if ( ${is_install} )
|
||||
install ( TARGETS ${_target} DESTINATION ${INSTALL_CMOD}/${_module_dir} COMPONENT Runtime)
|
||||
endif ()
|
||||
endif ()
|
||||
endmacro ()
|
||||
|
||||
# add_lua_module
|
||||
# Builds a Lua source module into a destination locatable by Lua
|
||||
# require syntax.
|
||||
# Binary modules are also supported where this function takes sources and
|
||||
# libraries to compile separated by LINK keyword.
|
||||
# USE: add_lua_module ( socket.http src/http.lua )
|
||||
# USE2: add_lua_module ( mime.core src/mime.c )
|
||||
# USE3: add_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )
|
||||
# USE4: add_lua_module ( ssl.context ssl.core ALL_IN_ONE src/context.c src/ssl.c )
|
||||
# This form builds an "all-in-one" module (e.g. ssl.so or ssl.dll containing
|
||||
# both modules ssl.context and ssl.core). The CMake target name will be
|
||||
# ssl_all_in_one.
|
||||
# Also sets variable _module_path (relative path where module typically
|
||||
# would be installed).
|
||||
macro ( add_lua_module )
|
||||
_lua_module_helper ( 0 ${ARGN} )
|
||||
endmacro ()
|
||||
|
||||
|
||||
# install_lua_module
|
||||
# This is the same as `add_lua_module` but also installs the module.
|
||||
# USE: install_lua_module ( socket.http src/http.lua )
|
||||
# USE2: install_lua_module ( mime.core src/mime.c )
|
||||
# USE3: install_lua_module ( socket.core ${SRC_SOCKET} LINK ${LIB_SOCKET} )
|
||||
macro ( install_lua_module )
|
||||
_lua_module_helper ( 1 ${ARGN} )
|
||||
endmacro ()
|
||||
|
||||
# Builds string representing Lua table mapping Lua modules names to file
|
||||
# paths. Used internally.
|
||||
macro ( _make_module_table _outvar )
|
||||
set ( ${_outvar} )
|
||||
list ( LENGTH _lua_modules _n )
|
||||
if ( ${_n} GREATER 0 ) # avoids cmake complaint
|
||||
foreach ( _i RANGE 1 ${_n} 2 )
|
||||
list ( GET _lua_modules ${_i} _path )
|
||||
math ( EXPR _ii ${_i}-1 )
|
||||
list ( GET _lua_modules ${_ii} _name )
|
||||
set ( ${_outvar} "${_table} ['${_name}'] = '${_path}'\;\n")
|
||||
endforeach ()
|
||||
endif ()
|
||||
set ( ${_outvar}
|
||||
"local modules = {
|
||||
${_table}}" )
|
||||
endmacro ()
|
||||
|
||||
# add_lua_test ( _testfile [ WORKING_DIRECTORY _working_dir ] )
|
||||
# Runs Lua script `_testfile` under CTest tester.
|
||||
# Optional named argument `WORKING_DIRECTORY` is current working directory to
|
||||
# run test under (defaults to ${CMAKE_CURRENT_BINARY_DIR}).
|
||||
# Both paths, if relative, are relative to ${CMAKE_CURRENT_SOURCE_DIR}.
|
||||
# Any modules previously defined with install_lua_module are automatically
|
||||
# preloaded (via package.preload) prior to running the test script.
|
||||
# Under LuaDist, set test=true in config.lua to enable testing.
|
||||
# USE: add_lua_test ( test/test1.lua [args...] [WORKING_DIRECTORY dir])
|
||||
macro ( add_lua_test _testfile )
|
||||
if ( NOT SKIP_TESTING )
|
||||
parse_arguments ( _ARG "WORKING_DIRECTORY" "" ${ARGN} )
|
||||
include ( CTest )
|
||||
find_program ( LUA NAMES lua lua.bat )
|
||||
get_filename_component ( TESTFILEABS ${_testfile} ABSOLUTE )
|
||||
get_filename_component ( TESTFILENAME ${_testfile} NAME )
|
||||
get_filename_component ( TESTFILEBASE ${_testfile} NAME_WE )
|
||||
|
||||
# Write wrapper script.
|
||||
# Note: One simple way to allow the script to find modules is
|
||||
# to just put them in package.preload.
|
||||
set ( TESTWRAPPER ${CMAKE_CURRENT_BINARY_DIR}/${TESTFILENAME} )
|
||||
_make_module_table ( _table )
|
||||
set ( TESTWRAPPERSOURCE
|
||||
"local CMAKE_CFG_INTDIR = ... or '.'
|
||||
${_table}
|
||||
local function preload_modules(modules)
|
||||
for name, path in pairs(modules) do
|
||||
if path:match'%.lua' then
|
||||
package.preload[name] = assert(loadfile(path))
|
||||
else
|
||||
local name = name:gsub('.*%-', '') -- remove any hyphen prefix
|
||||
local symbol = 'luaopen_' .. name:gsub('%.', '_')
|
||||
--improve: generalize to support all-in-one loader?
|
||||
local path = path:gsub('%$%{CMAKE_CFG_INTDIR%}', CMAKE_CFG_INTDIR)
|
||||
package.preload[name] = assert(package.loadlib(path, symbol))
|
||||
end
|
||||
end
|
||||
end
|
||||
preload_modules(modules)
|
||||
arg[0] = '${TESTFILEABS}'
|
||||
table.remove(arg, 1)
|
||||
return assert(loadfile '${TESTFILEABS}')(unpack(arg))
|
||||
" )
|
||||
if ( _ARG_WORKING_DIRECTORY )
|
||||
get_filename_component (
|
||||
TESTCURRENTDIRABS ${_ARG_WORKING_DIRECTORY} ABSOLUTE )
|
||||
# note: CMake 2.6 (unlike 2.8) lacks WORKING_DIRECTORY parameter.
|
||||
set ( _pre ${CMAKE_COMMAND} -E chdir "${TESTCURRENTDIRABS}" )
|
||||
endif ()
|
||||
file ( WRITE ${TESTWRAPPER} ${TESTWRAPPERSOURCE})
|
||||
add_test ( NAME ${TESTFILEBASE} COMMAND ${_pre} ${LUA}
|
||||
${TESTWRAPPER} "${CMAKE_CFG_INTDIR}"
|
||||
${_ARG_DEFAULT_ARGS} )
|
||||
endif ()
|
||||
# see also http://gdcm.svn.sourceforge.net/viewvc/gdcm/Sandbox/CMakeModules/UsePythonTest.cmake
|
||||
# Note: ${CMAKE_CFG_INTDIR} is a command-line argument to allow proper
|
||||
# expansion by the native build tool.
|
||||
endmacro ()
|
||||
|
||||
|
||||
# Converts Lua source file `_source` to binary string embedded in C source
|
||||
# file `_target`. Optionally compiles Lua source to byte code (not available
|
||||
# under LuaJIT2, which doesn't have a bytecode loader). Additionally, Lua
|
||||
# versions of bin2c [1] and luac [2] may be passed respectively as additional
|
||||
# arguments.
|
||||
#
|
||||
# [1] http://lua-users.org/wiki/BinToCee
|
||||
# [2] http://lua-users.org/wiki/LuaCompilerInLua
|
||||
function ( add_lua_bin2c _target _source )
|
||||
find_program ( LUA NAMES lua lua.bat )
|
||||
execute_process ( COMMAND ${LUA} -e "string.dump(function()end)"
|
||||
RESULT_VARIABLE _LUA_DUMP_RESULT ERROR_QUIET )
|
||||
if ( NOT ${_LUA_DUMP_RESULT} )
|
||||
SET ( HAVE_LUA_DUMP true )
|
||||
endif ()
|
||||
message ( "-- string.dump=${HAVE_LUA_DUMP}" )
|
||||
|
||||
if ( ARGV2 )
|
||||
get_filename_component ( BIN2C ${ARGV2} ABSOLUTE )
|
||||
set ( BIN2C ${LUA} ${BIN2C} )
|
||||
else ()
|
||||
find_program ( BIN2C NAMES bin2c bin2c.bat )
|
||||
endif ()
|
||||
if ( HAVE_LUA_DUMP )
|
||||
if ( ARGV3 )
|
||||
get_filename_component ( LUAC ${ARGV3} ABSOLUTE )
|
||||
set ( LUAC ${LUA} ${LUAC} )
|
||||
else ()
|
||||
find_program ( LUAC NAMES luac luac.bat )
|
||||
endif ()
|
||||
endif ( HAVE_LUA_DUMP )
|
||||
message ( "-- bin2c=${BIN2C}" )
|
||||
message ( "-- luac=${LUAC}" )
|
||||
|
||||
get_filename_component ( SOURCEABS ${_source} ABSOLUTE )
|
||||
if ( HAVE_LUA_DUMP )
|
||||
get_filename_component ( SOURCEBASE ${_source} NAME_WE )
|
||||
add_custom_command (
|
||||
OUTPUT ${_target} DEPENDS ${_source}
|
||||
COMMAND ${LUAC} -o ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo
|
||||
${SOURCEABS}
|
||||
COMMAND ${BIN2C} ${CMAKE_CURRENT_BINARY_DIR}/${SOURCEBASE}.lo
|
||||
">${_target}" )
|
||||
else ()
|
||||
add_custom_command (
|
||||
OUTPUT ${_target} DEPENDS ${SOURCEABS}
|
||||
COMMAND ${BIN2C} ${_source} ">${_target}" )
|
||||
endif ()
|
||||
endfunction()
|
15
3rdparty/lsqlite3/dist.info
vendored
15
3rdparty/lsqlite3/dist.info
vendored
@ -1,15 +0,0 @@
|
||||
--- This dist file is part of LuaDist project
|
||||
|
||||
name = "lsqlite3"
|
||||
version = "0.6devel"
|
||||
|
||||
desc = "LuaSQLite 3 is a thin wrapper around the public domain SQLite3 database engine."
|
||||
author = "Tiago Dionizio, Doug Currie"
|
||||
license = "MIT"
|
||||
url = "http://luaforge.net/projects/luasqlite/"
|
||||
maintainer = "Peter Kapec"
|
||||
|
||||
depends = {
|
||||
"lua ~> 5.1",
|
||||
"libsqlite3 >=3.5"
|
||||
}
|
893
3rdparty/lsqlite3/doc/lsqlite3.html
vendored
893
3rdparty/lsqlite3/doc/lsqlite3.html
vendored
@ -1,893 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>LuaSQLite 3</TITLE>
|
||||
<LINK REV="made" HREF="mailto:unknown@du216771.users">
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
|
||||
<A NAME="__index__"></A>
|
||||
<!-- INDEX BEGIN -->
|
||||
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#name">NAME</A></LI>
|
||||
<LI><A HREF="#overview">OVERVIEW</A></LI>
|
||||
<LI><A HREF="#download">DOWNLOAD</A></LI>
|
||||
<LI><A HREF="#installation">INSTALLATION</A></LI>
|
||||
<LI><A HREF="#examples">EXAMPLES</A></LI>
|
||||
<LI><A HREF="#verification tests">VERIFICATION TESTS</A></LI>
|
||||
<LI><A HREF="#reference">REFERENCE</A></LI>
|
||||
<LI><A HREF="#sqlite3 functions">SQLite3 functions</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#sqlite3.complete">sqlite3.complete</A></LI>
|
||||
<LI><A HREF="#sqlite3.open">sqlite3.open</A></LI>
|
||||
<LI><A HREF="#sqlite3.open_memory">sqlite3.open_memory</A></LI>
|
||||
<LI><A HREF="#sqlite3.temp_directory">sqlite3.temp_directory</A></LI>
|
||||
<LI><A HREF="#sqlite3.version">sqlite3.version</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#database methods">Database methods</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#db:busy_handler">db:busy_handler</A></LI>
|
||||
<LI><A HREF="#db:busy_timeout">db:busy_timeout</A></LI>
|
||||
<LI><A HREF="#db:changes">db:changes</A></LI>
|
||||
<LI><A HREF="#db:close">db:close</A></LI>
|
||||
<LI><A HREF="#db:close_vm">db:close_vm</A></LI>
|
||||
<LI><A HREF="#db:create_aggregate">db:create_aggregate</A></LI>
|
||||
<LI><A HREF="#db:create_collation">db:create_collation</A></LI>
|
||||
<LI><A HREF="#db:create_function">db:create_function</A></LI>
|
||||
<LI><A HREF="#db:errcode">db:errcode</A></LI>
|
||||
<LI><A HREF="#db:errmsg">db:errmsg</A></LI>
|
||||
<LI><A HREF="#db:exec">db:exec</A></LI>
|
||||
<LI><A HREF="#db:interrupt">db:interrupt</A></LI>
|
||||
<LI><A HREF="#db:isopen">db:isopen</A></LI>
|
||||
<LI><A HREF="#db:last_insert_rowid">db:last_insert_rowid</A></LI>
|
||||
<LI><A HREF="#db:nrows">db:nrows</A></LI>
|
||||
<LI><A HREF="#db:prepare">db:prepare</A></LI>
|
||||
<LI><A HREF="#db:progress_handler">db:progress_handler</A></LI>
|
||||
<LI><A HREF="#db:rows">db:rows</A></LI>
|
||||
<LI><A HREF="#db:total_changes">db:total_changes</A></LI>
|
||||
<LI><A HREF="#db:trace">db:trace</A></LI>
|
||||
<LI><A HREF="#db:urows">db:urows</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#methods for prepared statements">Methods for prepared statements</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#stmt:bind">stmt:bind</A></LI>
|
||||
<LI><A HREF="#stmt:bind_blob">stmt:bind_blob</A></LI>
|
||||
<LI><A HREF="#stmt:bind_names">stmt:bind_names</A></LI>
|
||||
<LI><A HREF="#stmt:bind_parameter_count">stmt:bind_parameter_count</A></LI>
|
||||
<LI><A HREF="#stmt:bind_parameter_name">stmt:bind_parameter_name</A></LI>
|
||||
<LI><A HREF="#stmt:bind_values">stmt:bind_values</A></LI>
|
||||
<LI><A HREF="#stmt:columns">stmt:columns</A></LI>
|
||||
<LI><A HREF="#stmt:finalize">stmt:finalize</A></LI>
|
||||
<LI><A HREF="#stmt:get_name">stmt:get_name</A></LI>
|
||||
<LI><A HREF="#stmt:get_named_types">stmt:get_named_types</A></LI>
|
||||
<LI><A HREF="#stmt:get_named_values">stmt:get_named_values</A></LI>
|
||||
<LI><A HREF="#stmt:get_names">stmt:get_names</A></LI>
|
||||
<LI><A HREF="#stmt:get_type">stmt:get_type</A></LI>
|
||||
<LI><A HREF="#stmt:get_types">stmt:get_types</A></LI>
|
||||
<LI><A HREF="#stmt:get_unames">stmt:get_unames</A></LI>
|
||||
<LI><A HREF="#stmt:get_utypes">stmt:get_utypes</A></LI>
|
||||
<LI><A HREF="#stmt:get_uvalues">stmt:get_uvalues</A></LI>
|
||||
<LI><A HREF="#stmt:get_value">stmt:get_value</A></LI>
|
||||
<LI><A HREF="#stmt:get_values">stmt:get_values</A></LI>
|
||||
<LI><A HREF="#stmt:isopen">stmt:isopen</A></LI>
|
||||
<LI><A HREF="#stmt:nrows">stmt:nrows</A></LI>
|
||||
<LI><A HREF="#stmt:reset">stmt:reset</A></LI>
|
||||
<LI><A HREF="#stmt:rows">stmt:rows</A></LI>
|
||||
<LI><A HREF="#stmt:step">stmt:step</A></LI>
|
||||
<LI><A HREF="#stmt:urows">stmt:urows</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#methods for callback contexts">Methods for callback contexts</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#context:aggregate_count">context:aggregate_count</A></LI>
|
||||
<LI><A HREF="#context:get_aggregate_data">context:get_aggregate_data</A></LI>
|
||||
<LI><A HREF="#context:set_aggregate_data">context:set_aggregate_data</A></LI>
|
||||
<LI><A HREF="#context:result">context:result</A></LI>
|
||||
<LI><A HREF="#context:result_null">context:result_null</A></LI>
|
||||
<LI><A HREF="#context:result_number">context:result_number</A></LI>
|
||||
<LI><A HREF="#context:result_int">context:result_int</A></LI>
|
||||
<LI><A HREF="#context:result_text">context:result_text</A></LI>
|
||||
<LI><A HREF="#context:result_blob">context:result_blob</A></LI>
|
||||
<LI><A HREF="#context:result_error">context:result_error</A></LI>
|
||||
<LI><A HREF="#context:user_data">context:user_data</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#numerical error and result codes">Numerical error and result codes</A></LI>
|
||||
<LI><A HREF="#version">VERSION</A></LI>
|
||||
<LI><A HREF="#credits">CREDITS</A></LI>
|
||||
<LI><A HREF="#license">LICENSE</A></LI>
|
||||
</UL>
|
||||
<!-- INDEX END -->
|
||||
|
||||
<HR>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="name">NAME</A></H1>
|
||||
<P><STRONG>LuaSQLite 3</STRONG> - a Lua 5.1 wrapper for the SQLite3 library</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="overview">OVERVIEW</A></H1>
|
||||
<P><STRONG>LuaSQLite 3</STRONG> is a thin wrapper around the public domain SQLite3
|
||||
database engine.</P>
|
||||
<P>The <CODE>lsqlite3</CODE> module supports the creation and manipulation of
|
||||
SQLite3 databases. After a <CODE>require('lsqlite3')</CODE> the exported
|
||||
functions are called with prefix <CODE>sqlite3</CODE>. However, most sqlite3
|
||||
functions are called via an object-oriented interface to either
|
||||
database or SQL statement objects; see below for details.</P>
|
||||
<P>This documentation does not attempt to describe how SQLite3 itself
|
||||
works, it just describes the Lua binding and the available functions.
|
||||
For more information about the SQL features supported by SQLite3 and
|
||||
details about the syntax of SQL statements and queries, please see the
|
||||
<STRONG>SQLite3 documentation</STRONG> <A HREF="http://www.sqlite.org/">http://www.sqlite.org/</A>. Using some of the
|
||||
advanced features (how to use callbacks, for instance) will require
|
||||
some familiarity with the SQLite3 API.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="download">DOWNLOAD</A></H1>
|
||||
<P><STRONG>LuaSQLite 3</STRONG> source code can be downloaded from its
|
||||
LuaForge (<A HREF="http://luaforge.net/projects/luasqlite/">http://luaforge.net/projects/luasqlite/</A>) page.</P>
|
||||
<P>You will also need to build or obtain an SQLite3 loadable library
|
||||
(DLL or .so). See <A HREF="http://www.sqlite.org/">http://www.sqlite.org/</A> for obtaining SQLite3
|
||||
source code or downloading a binary SQLite3 library.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="installation">INSTALLATION</A></H1>
|
||||
<P>A <EM>Makefile</EM> is provided; it assumes an SQLite3 library is already
|
||||
installed.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="examples">EXAMPLES</A></H1>
|
||||
<P>The distribution contains an <EM>examples</EM> directory. The unit tests
|
||||
also show some example use.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="verification tests">VERIFICATION TESTS</A></H1>
|
||||
<P>The distribution contains some units tests using Michael Roth's
|
||||
<CODE>lunit</CODE> (which is also included). Some of the tests were also derived
|
||||
from Michael's <STRONG>lua-sqlite3</STRONG> module, and more unit tests added by
|
||||
Doug Currie.</P>
|
||||
<P>The distribution also contains some functional tests by Tiago.</P>
|
||||
<P>This version of <CODE>lsqlite3</CODE> was tested with SQLite 3.4.2.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="reference">REFERENCE</A></H1>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="sqlite3 functions">SQLite3 functions</A></H1>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.complete">sqlite3.complete</A></H2>
|
||||
<PRE>
|
||||
sqlite3.complete(sql)</PRE>
|
||||
<P>Returns true if the string <CODE>sql</CODE> comprises one or more complete SQL
|
||||
statements and false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.open">sqlite3.open</A></H2>
|
||||
<PRE>
|
||||
sqlite3.open(filename)</PRE>
|
||||
<P>Opens (or creates if it does not exist) an SQLite database with name
|
||||
<CODE>filename</CODE> and returns its handle as userdata (the returned object
|
||||
should be used for all further method calls in connection with this
|
||||
specific database, see <A HREF="#database methods">Database methods</A>). Example:</P>
|
||||
<PRE>
|
||||
myDB=sqlite3.open('MyDatabase.sqlite3') -- open
|
||||
-- do some database calls...
|
||||
myDB:close() -- close</PRE>
|
||||
<P>In case of an error, the function returns nil, an error code and an
|
||||
error message.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.open_memory">sqlite3.open_memory</A></H2>
|
||||
<PRE>
|
||||
sqlite3.open_memory()</PRE>
|
||||
<P>Opens an SQLite database <STRONG>in memory</STRONG> and returns its handle as
|
||||
userdata. In case of an error, the function returns nil, an error code
|
||||
and an error message. (In-memory databases are volatile as they are
|
||||
never stored on disk.)</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.temp_directory">sqlite3.temp_directory</A></H2>
|
||||
<PRE>
|
||||
sqlite3.temp_directory([temp])</PRE>
|
||||
<P>Sets or queries the directory used by SQLite for temporary files. If
|
||||
string <CODE>temp</CODE> is a directory name or nil, the temporary directory is
|
||||
set accordingly and the old value is returned. If <CODE>temp</CODE> is missing,
|
||||
the function simply returns the current temporary directory.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.version">sqlite3.version</A></H2>
|
||||
<PRE>
|
||||
sqlite3.version()</PRE>
|
||||
<P>Returns a string with SQLite version information, in the form 'x.y[.z]'.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="database methods">Database methods</A></H1>
|
||||
<P>After opening a database with <A HREF="#sqlite3.open"><CODE>sqlite3.open()</CODE></A> or
|
||||
<A HREF="#sqlite3.open_memory"><CODE>sqlite3.open_memory()</CODE></A>
|
||||
the returned database object should be used for all further method calls
|
||||
in connection with that database. An open database object supports the
|
||||
following methods.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:busy_handler">db:busy_handler</A></H2>
|
||||
<PRE>
|
||||
db:busy_handler([func[,udata]])</PRE>
|
||||
<P>Sets or removes a busy handler for a database. <CODE>func</CODE> is either a Lua
|
||||
function that implements the busy handler or nil to remove a previously
|
||||
set handler. This function returns nothing.</P>
|
||||
<P>The handler function is called with two parameters: <CODE>udata</CODE> and the
|
||||
number of (re-)tries for a pending transaction. It should return nil,
|
||||
false or 0 if the transaction is to be aborted. All other values will
|
||||
result in another attempt to perform the transaction. (See the SQLite
|
||||
documentation for important hints about writing busy handlers.)</P>
|
||||
<P>
|
||||
<H2><A NAME="db:busy_timeout">db:busy_timeout</A></H2>
|
||||
<PRE>
|
||||
db:busy_timeout(t)</PRE>
|
||||
<P>Sets a busy handler that waits for <CODE>t</CODE> milliseconds if a transaction
|
||||
cannot proceed. Calling this function will remove any busy handler set
|
||||
by <A HREF="#db:busy_handler"><CODE>db:busy_handler()</CODE></A>; calling it with an argument
|
||||
less than or equal to 0 will turn off all busy handlers.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:changes">db:changes</A></H2>
|
||||
<PRE>
|
||||
db:changes()</PRE>
|
||||
<P>This function returns the number of database rows that were changed (or
|
||||
inserted or deleted) by the most recent SQL statement. Only changes that
|
||||
are directly specified by INSERT, UPDATE, or DELETE statements are
|
||||
counted. Auxiliary changes caused by triggers are not counted. Use
|
||||
<A HREF="#db:total_changes"><CODE>db:total_changes()</CODE></A> to find the total number of
|
||||
changes.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:close">db:close</A></H2>
|
||||
<PRE>
|
||||
db:close()</PRE>
|
||||
<P>Closes a database. All SQL statements prepared using
|
||||
<A HREF="#db:prepare"><CODE>db:prepare()</CODE></A> should
|
||||
have been finalized before this function is called. The function returns
|
||||
<CODE>sqlite3.OK</CODE> on success or else a numerical error code (see the list of
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="db:close_vm">db:close_vm</A></H2>
|
||||
<PRE>
|
||||
db:close_vm(temponly)</PRE>
|
||||
<P>Finalizes all statements that have not been explicitly finalized. If
|
||||
<CODE>temponly</CODE> is true, only internal, temporary statements are finalized.
|
||||
This function returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:create_aggregate">db:create_aggregate</A></H2>
|
||||
<PRE>
|
||||
db:create_aggregate(name,nargs,step,final)</PRE>
|
||||
<P>This function creates an aggregate callback function. Aggregates perform
|
||||
an operation over all rows in a query. <CODE>name</CODE> is a string with the name
|
||||
of the aggregate function as given in an SQL statement; <CODE>nargs</CODE> is the
|
||||
number of arguments this call will provide. <CODE>step</CODE> is the actual Lua
|
||||
function that gets called once for every row; it should accept a function
|
||||
context (see <A HREF="#methods for callback contexts">Methods for callback contexts</A>) plus the same number of
|
||||
parameters as given in <CODE>nargs</CODE>. <CODE>final</CODE> is a function that is called
|
||||
once after all rows have been processed; it receives one argument, the
|
||||
function context.</P>
|
||||
<P>The function context can be used inside the two callback functions to
|
||||
communicate with SQLite3. Here is a simple example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
local num_sum=0
|
||||
local function oneRow(context,num) -- add one column in all rows
|
||||
num_sum=num_sum+num
|
||||
end
|
||||
local function afterLast(context) -- return sum after last row has been processed
|
||||
context:result_number(num_sum)
|
||||
num_sum=0
|
||||
end
|
||||
db:create_aggregate("do_the_sums",1,oneRow,afterLast)
|
||||
for sum in db:urows('SELECT do_the_sums(num1) FROM numbers') do print("Sum of col 1:",sum) end
|
||||
for sum in db:urows('SELECT do_the_sums(num2) FROM numbers') do print("Sum of col 2:",sum) end</PRE>
|
||||
<P>This prints:</P>
|
||||
<PRE>
|
||||
Sum of col 1: 6
|
||||
Sum of col 2: 66</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:create_collation">db:create_collation</A></H2>
|
||||
<PRE>
|
||||
db:create_collation(name,func)</PRE>
|
||||
<P>This creates a collation callback. A collation callback is used to
|
||||
establish a collation order, mostly for string comparisons and sorting
|
||||
purposes. <CODE>name</CODE> is a string with the name of the collation to be created;
|
||||
<CODE>func</CODE> is a function that accepts two string arguments, compares them
|
||||
and returns 0 if both strings are identical, -1 if the first argument is
|
||||
lower in the collation order than the second and 1 if the first argument
|
||||
is higher in the collation order than the second. A simple example:</P>
|
||||
<PRE>
|
||||
local function collate(s1,s2)
|
||||
s1=s1:lower()
|
||||
s2=s2:lower()
|
||||
if s1==s2 then return 0
|
||||
elseif s1<s2 then return -1
|
||||
else return 1 end
|
||||
end
|
||||
db:exec[=[
|
||||
CREATE TABLE test(id INTEGER PRIMARY KEY,content COLLATE CINSENS);
|
||||
INSERT INTO test VALUES(NULL,'hello world');
|
||||
INSERT INTO test VALUES(NULL,'Buenos dias');
|
||||
INSERT INTO test VALUES(NULL,'HELLO WORLD');
|
||||
]=]
|
||||
db:create_collation('CINSENS',collate)
|
||||
for row in db:nrows('SELECT * FROM test') do print(row.id,row.content) end</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:create_function">db:create_function</A></H2>
|
||||
<PRE>
|
||||
db:create_function(name,nargs,func)</PRE>
|
||||
<P>This function creates a callback function. Callback function are called
|
||||
by SQLite3 once for every row in a query. <CODE>name</CODE> is a string with the
|
||||
name of the callback function as given in an SQL statement; <CODE>nargs</CODE> is
|
||||
the number of arguments this call will provide. <CODE>func</CODE> is the actual Lua
|
||||
function that gets called once for every row; it should accept a
|
||||
function context (see <A HREF="#methods for callback contexts">Methods for callback contexts</A>) plus the same
|
||||
number of parameters as given in nargs. Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec'CREATE TABLE test(col1,col2,col3)'
|
||||
db:exec'INSERT INTO test VALUES(1,2,4)'
|
||||
db:exec'INSERT INTO test VALUES(2,4,9)'
|
||||
db:exec'INSERT INTO test VALUES(3,6,16)'
|
||||
db:create_function('sum_cols',3,function(ctx,a,b,c)
|
||||
ctx:result_number(a+b+c)
|
||||
end))
|
||||
for col1,col2,col3,sum in db:urows('SELECT *,sum_cols(col1,col2,col3) FROM test') do
|
||||
util.printf('%2i+%2i+%2i=%2i\n',col1,col2,col3,sum)
|
||||
end</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:errcode">db:errcode</A></H2>
|
||||
<PRE>
|
||||
db:errcode()
|
||||
db:error_code()</PRE>
|
||||
<P>Returns the numerical result code (or extended result code) for the most
|
||||
recent failed call associated with database db. See
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A> for details.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:errmsg">db:errmsg</A></H2>
|
||||
<PRE>
|
||||
db:errmsg()
|
||||
db:error_message()</PRE>
|
||||
<P>Returns a string that contains an error message for the most recent
|
||||
failed call associated with database db.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:exec">db:exec</A></H2>
|
||||
<PRE>
|
||||
db:exec(sql[,func[,udata]])
|
||||
db:execute(sql[,func[,udata]])</PRE>
|
||||
<P>Compiles and executes the SQL <CODE>statement(s)</CODE> given in string <CODE>sql</CODE>. The
|
||||
statements are simply executed one after the other and not stored. The
|
||||
function returns <CODE>sqlite3.OK</CODE> on success or else a numerical error code
|
||||
(see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>If one or more of the SQL statements are queries, then the callback
|
||||
function specified in <CODE>func</CODE> is invoked once for each row of the query
|
||||
result (if <CODE>func</CODE> is nil, no callback is invoked). The callback receives
|
||||
four arguments: <CODE>udata</CODE> (the third parameter of the <CODE>db:exec()</CODE> call),
|
||||
the number of columns in the row, a table with the column values and
|
||||
another table with the column names. The callback function should return
|
||||
0. If the callback returns a non-zero value then the query is aborted,
|
||||
all subsequent SQL statements are skipped and <CODE>db:exec()</CODE> returns
|
||||
<CODE>sqlite3.ABORT</CODE>. Here is a simple example:</P>
|
||||
<PRE>
|
||||
sql=[=[
|
||||
CREATE TABLE numbers(num1,num2,str);
|
||||
INSERT INTO numbers VALUES(1,11,"ABC");
|
||||
INSERT INTO numbers VALUES(2,22,"DEF");
|
||||
INSERT INTO numbers VALUES(3,33,"UVW");
|
||||
INSERT INTO numbers VALUES(4,44,"XYZ");
|
||||
SELECT * FROM numbers;
|
||||
]=]
|
||||
function showrow(udata,cols,values,names)
|
||||
assert(udata=='test_udata')
|
||||
print('exec:')
|
||||
for i=1,cols do print('',names[i],values[i]) end
|
||||
return 0
|
||||
end
|
||||
db:exec(sql,showrow,'test_udata')</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:interrupt">db:interrupt</A></H2>
|
||||
<PRE>
|
||||
db:interrupt()</PRE>
|
||||
<P>This function causes any pending database operation to abort and return
|
||||
at the next opportunity. This function returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:isopen">db:isopen</A></H2>
|
||||
<PRE>
|
||||
db:isopen()</PRE>
|
||||
<P>Returns true if database db is open, false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:last_insert_rowid">db:last_insert_rowid</A></H2>
|
||||
<PRE>
|
||||
db:last_insert_rowid()</PRE>
|
||||
<P>This function returns the rowid of the most recent INSERT into the
|
||||
database. If no inserts have ever occurred, 0 is returned. (Each row in
|
||||
an SQLite table has a unique 64-bit signed integer key called the
|
||||
'rowid'. This id is always available as an undeclared column named
|
||||
ROWID, OID, or _ROWID_. If the table has a column of type INTEGER
|
||||
PRIMARY KEY then that column is another alias for the rowid.)</P>
|
||||
<P>If an INSERT occurs within a trigger, then the rowid of the inserted row
|
||||
is returned as long as the trigger is running. Once the trigger
|
||||
terminates, the value returned reverts to the last value inserted before
|
||||
the trigger fired.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:nrows">db:nrows</A></H2>
|
||||
<PRE>
|
||||
db:nrows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns a
|
||||
table in which the named fields correspond to the columns in the database.
|
||||
Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:nrows('SELECT * FROM numbers') do table.print(a) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
num2: 11
|
||||
num1: 1
|
||||
num2: 22
|
||||
num1: 2
|
||||
num2: 33
|
||||
num1: 3</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:prepare">db:prepare</A></H2>
|
||||
<PRE>
|
||||
db:prepare(sql)</PRE>
|
||||
<P>This function compiles the SQL statement in string <CODE>sql</CODE> into an internal
|
||||
representation and returns this as userdata. The returned object should
|
||||
be used for all further method calls in connection with this specific
|
||||
SQL statement (see <A HREF="#methods for prepared statements">Methods for prepared statements</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="db:progress_handler">db:progress_handler</A></H2>
|
||||
<PRE>
|
||||
db:progress_handler(n,func,udata)</PRE>
|
||||
<P>This function installs a callback function <CODE>func</CODE> that is invoked
|
||||
periodically during long-running calls to <A HREF="#db:exec"><CODE>db:exec()</CODE></A>
|
||||
or <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A>. The
|
||||
progress callback is invoked once for every <CODE>n</CODE> internal operations,
|
||||
where <CODE>n</CODE> is the first argument to this function. <CODE>udata</CODE> is passed to
|
||||
the progress callback function each time it is invoked. If a call to
|
||||
<CODE>db:exec()</CODE> or <CODE>stmt:step()</CODE> results in fewer than <CODE>n</CODE> operations
|
||||
being executed, then the progress callback is never invoked. Only a
|
||||
single progress callback function may be registered for each opened
|
||||
database and a call to this function will overwrite any previously set
|
||||
callback function. To remove the progress callback altogether, pass nil
|
||||
as the second argument.</P>
|
||||
<P>If the progress callback returns a result other than 0, then the current
|
||||
query is immediately terminated, any database changes are rolled back
|
||||
and the containing <CODE>db:exec()</CODE> or <CODE>stmt:step()</CODE> call returns
|
||||
<CODE>sqlite3.INTERRUPT</CODE>. This feature can be used to cancel long-running
|
||||
queries.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:rows">db:rows</A></H2>
|
||||
<PRE>
|
||||
db:rows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns a table
|
||||
in which the numerical indices 1 to n correspond to the selected columns
|
||||
1 to n in the database. Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:rows('SELECT * FROM numbers') do table.print(a) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
1: 1
|
||||
2: 11
|
||||
1: 2
|
||||
2: 22
|
||||
1: 3
|
||||
2: 33</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:total_changes">db:total_changes</A></H2>
|
||||
<PRE>
|
||||
db:total_changes()</PRE>
|
||||
<P>This function returns the number of database rows that have been
|
||||
modified by INSERT, UPDATE or DELETE statements since the database was
|
||||
opened. This includes UPDATE, INSERT and DELETE statements executed as
|
||||
part of trigger programs. All changes are counted as soon as the
|
||||
statement that produces them is completed by calling either
|
||||
<A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A> or <A HREF="#stmt:finalize"><CODE>stmt:finalize()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:trace">db:trace</A></H2>
|
||||
<PRE>
|
||||
db:trace(func,udata)</PRE>
|
||||
<P>This function installs a trace callback handler. <CODE>func</CODE> is a Lua
|
||||
function that is called by SQLite3 just before the evaluation of an SQL
|
||||
statement. This callback receives two arguments: the first is the
|
||||
<CODE>udata</CODE> argument used when the callback was installed; the second is a
|
||||
string with the SQL statement about to be executed.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:urows">db:urows</A></H2>
|
||||
<PRE>
|
||||
db:urows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns the
|
||||
values that correspond to the columns in the currently selected row.
|
||||
Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for num1,num2 in db:urows('SELECT * FROM numbers') do print(num1,num2) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
1 11
|
||||
2 22
|
||||
3 33</PRE>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="methods for prepared statements">Methods for prepared statements</A></H1>
|
||||
<P>After creating a prepared statement with <A HREF="#db:prepare"><CODE>db:prepare()</CODE></A>
|
||||
the returned statement object should be used for all further calls in
|
||||
connection with that statement. Statement objects support the following
|
||||
methods.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind">stmt:bind</A></H2>
|
||||
<PRE>
|
||||
stmt:bind(n[,value])</PRE>
|
||||
<P>Binds value to statement parameter <CODE>n</CODE>. If the type of value is string
|
||||
or number, it is bound as text or double, respectively. If <CODE>value</CODE> is a
|
||||
boolean or nil or missing, any previous binding is removed. The function
|
||||
returns <CODE>sqlite3.OK</CODE> on success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_blob">stmt:bind_blob</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_blob(n,blob)</PRE>
|
||||
<P>Binds string <CODE>blob</CODE> (which can be a binary string) as a blob to
|
||||
statement parameter <CODE>n</CODE>. The function returns <CODE>sqlite3.OK</CODE> on success
|
||||
or else a numerical error code (see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_names">stmt:bind_names</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_names(nametable)</PRE>
|
||||
<P>Binds the values in <CODE>nametable</CODE> to statement parameters. If the
|
||||
statement parameters are named (i.e., of the form ``:AAA'' or ``$AAA'')
|
||||
then this function looks for appropriately named fields in <CODE>nametable</CODE>;
|
||||
if the statement parameters are
|
||||
not named, it looks for numerical fields 1 to the number of statement
|
||||
parameters. The function returns <CODE>sqlite3.OK</CODE> on success or else a
|
||||
numerical error code (see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_parameter_count">stmt:bind_parameter_count</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_parameter_count()</PRE>
|
||||
<P>Returns the largest statement parameter index in prepared statement
|
||||
<CODE>stmt</CODE>. When the statement parameters are of the forms ``:AAA'' or ``?'',
|
||||
then they are assigned sequentially increasing numbers beginning with
|
||||
one, so the value returned is the number of parameters. However if the
|
||||
same statement parameter name is used multiple times, each occurrence
|
||||
is given the same number, so the value returned is the number of unique
|
||||
statement parameter names.</P>
|
||||
<P>If statement parameters of the form ``?NNN'' are used (where NNN is an
|
||||
integer) then there might be gaps in the numbering and the value
|
||||
returned by this interface is the index of the statement parameter with
|
||||
the largest index value.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_parameter_name">stmt:bind_parameter_name</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_parameter_name(n)</PRE>
|
||||
<P>Returns the name of the <CODE>n</CODE>-th parameter in prepared statement <CODE>stmt</CODE>.
|
||||
Statement parameters of the form ``:AAA'' or ``@AAA'' or ``$VVV'' have a name
|
||||
which is the string ``:AAA'' or ``@AAA'' or ``$VVV''. In other words, the
|
||||
initial ``:'' or ``$'' or ``@'' is included as part of the name. Parameters
|
||||
of the form ``?'' or ``?NNN'' have no name. The first bound parameter has
|
||||
an index of 1.
|
||||
If the value <CODE>n</CODE> is out of range or if the <CODE>n</CODE>-th parameter is
|
||||
nameless, then nil is returned. The function returns <CODE>sqlite3.OK</CODE> on
|
||||
success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_values">stmt:bind_values</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_values(value1,value2,...,valueN)</PRE>
|
||||
<P>Binds the given values to statement parameters. The function returns
|
||||
<CODE>sqlite3.OK</CODE> on success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:columns">stmt:columns</A></H2>
|
||||
<PRE>
|
||||
stmt:columns()</PRE>
|
||||
<P>Returns the number of columns in the result set returned by statement
|
||||
stmt or 0 if the statement does not return data (for example an UPDATE).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:finalize">stmt:finalize</A></H2>
|
||||
<PRE>
|
||||
stmt:finalize()</PRE>
|
||||
<P>This function frees prepared statement stmt. If the statement was
|
||||
executed successfully, or not executed at all, then <CODE>sqlite3.OK</CODE> is
|
||||
returned. If execution of the statement failed then an error code is
|
||||
returned.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_name">stmt:get_name</A></H2>
|
||||
<PRE>
|
||||
stmt:get_name(n)</PRE>
|
||||
<P>Returns the name of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_named_types">stmt:get_named_types</A></H2>
|
||||
<PRE>
|
||||
stmt:get_named_types()</PRE>
|
||||
<P>Returns a table with the names and types of all columns in the result
|
||||
set of statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_named_values">stmt:get_named_values</A></H2>
|
||||
<PRE>
|
||||
stmt:get_named_values()</PRE>
|
||||
<P>This function returns a table with names and values of all columns in
|
||||
the current result row of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_names">stmt:get_names</A></H2>
|
||||
<PRE>
|
||||
stmt:get_names()</PRE>
|
||||
<P>This function returns an array with the names of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_type">stmt:get_type</A></H2>
|
||||
<PRE>
|
||||
stmt:get_type(n)</PRE>
|
||||
<P>Returns the type of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_types">stmt:get_types</A></H2>
|
||||
<PRE>
|
||||
stmt:get_types()</PRE>
|
||||
<P>This function returns an array with the types of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_unames">stmt:get_unames</A></H2>
|
||||
<PRE>
|
||||
stmt:get_unames()</PRE>
|
||||
<P>This function returns a list with the names of all columns in the result
|
||||
set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_utypes">stmt:get_utypes</A></H2>
|
||||
<PRE>
|
||||
stmt:get_utypes()</PRE>
|
||||
<P>This function returns a list with the types of all columns in the result
|
||||
set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_uvalues">stmt:get_uvalues</A></H2>
|
||||
<PRE>
|
||||
stmt:get_uvalues()</PRE>
|
||||
<P>This function returns a list with the values of all columns in the
|
||||
current result row of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_value">stmt:get_value</A></H2>
|
||||
<PRE>
|
||||
stmt:get_value(n)</PRE>
|
||||
<P>Returns the value of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_values">stmt:get_values</A></H2>
|
||||
<PRE>
|
||||
stmt:get_values()</PRE>
|
||||
<P>This function returns an array with the values of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:isopen">stmt:isopen</A></H2>
|
||||
<PRE>
|
||||
stmt:isopen()</PRE>
|
||||
<P>Returns true if stmt has not yet been finalized, false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:nrows">stmt:nrows</A></H2>
|
||||
<PRE>
|
||||
stmt:nrows()</PRE>
|
||||
<P>Returns an function that iterates over the names and values of the
|
||||
result set of statement <CODE>stmt</CODE>. Each iteration returns a table with the
|
||||
names and values for the current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:nrows"><CODE>db:nrows()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:reset">stmt:reset</A></H2>
|
||||
<PRE>
|
||||
stmt:reset()</PRE>
|
||||
<P>This function resets SQL statement <CODE>stmt</CODE>, so that it is ready to be
|
||||
re-executed. Any statement variables that had values bound to them using
|
||||
the <CODE>stmt:bind*()</CODE> functions retain their values.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:rows">stmt:rows</A></H2>
|
||||
<PRE>
|
||||
stmt:rows()</PRE>
|
||||
<P>Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns an array with the values for the
|
||||
current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:rows"><CODE>db:rows()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:step">stmt:step</A></H2>
|
||||
<PRE>
|
||||
stmt:step()</PRE>
|
||||
<P>This function must be called to evaluate the (next iteration of the)
|
||||
prepared statement stmt. It will return one of the following values:</P>
|
||||
<UL>
|
||||
<LI>
|
||||
<CODE>sqlite3.BUSY</CODE>: the engine was unable to acquire the locks needed. If the
|
||||
statement is a COMMIT or occurs outside of an explicit transaction, then
|
||||
you can retry the statement. If the statement is not a COMMIT and occurs
|
||||
within a explicit transaction then you should rollback the transaction
|
||||
before continuing.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.DONE</CODE>: the statement has finished executing successfully.
|
||||
<A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> should not be called again on this statement
|
||||
without first calling <A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A> to reset the virtual
|
||||
machine back to the initial state.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.ROW</CODE>: this is returned each time a new row of data is ready for
|
||||
processing by the caller. The values may be accessed using the column
|
||||
access functions. <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> can be called again to
|
||||
retrieve the next row of data.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.ERROR</CODE>: a run-time error (such as a constraint violation) has
|
||||
occurred. <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> should not be called again. More
|
||||
information may be found by calling <A HREF="#db:errmsg"><CODE>db:errmsg()</CODE></A>. A more
|
||||
specific error
|
||||
code (can be obtained by calling <A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A>.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.MISUSE</CODE>: the function was called inappropriately, perhaps
|
||||
because the statement has already been finalized or a previous call to
|
||||
<A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> has returned <CODE>sqlite3.ERROR</CODE> or
|
||||
<CODE>sqlite3.DONE</CODE>.
|
||||
<P></P></UL>
|
||||
<P>
|
||||
<H2><A NAME="stmt:urows">stmt:urows</A></H2>
|
||||
<PRE>
|
||||
stmt:urows()</PRE>
|
||||
<P>Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns the values for the current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:urows"><CODE>db:urows()</CODE></A>.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="methods for callback contexts">Methods for callback contexts</A></H1>
|
||||
<P>A callback context is available as a parameter inside the callback
|
||||
functions <A HREF="#db:create_aggregate"><CODE>db:create_aggregate()</CODE></A> and
|
||||
<A HREF="#db:create_function"><CODE>db:create_function()</CODE></A>. It can be used
|
||||
to get further information about the state of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:aggregate_count">context:aggregate_count</A></H2>
|
||||
<PRE>
|
||||
context:aggregate_count()</PRE>
|
||||
<P>Returns the number of calls to the aggregate step function.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:get_aggregate_data">context:get_aggregate_data</A></H2>
|
||||
<PRE>
|
||||
context:get_aggregate_data()</PRE>
|
||||
<P>Returns the user-definable data field for callback funtions.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:set_aggregate_data">context:set_aggregate_data</A></H2>
|
||||
<PRE>
|
||||
context:set_aggregate_data(udata)</PRE>
|
||||
<P>Set the user-definable data field for callback funtions to <CODE>udata</CODE>.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result">context:result</A></H2>
|
||||
<PRE>
|
||||
context:result(res)</PRE>
|
||||
<P>This function sets the result of a callback function to res. The type of
|
||||
the result depends on the type of res and is either a number or a string
|
||||
or nil. All other values will raise an error message.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_null">context:result_null</A></H2>
|
||||
<PRE>
|
||||
context:result_null()</PRE>
|
||||
<P>This function sets the result of a callback function to nil. It returns
|
||||
nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_number">context:result_number</A></H2>
|
||||
<PRE>
|
||||
context:result_number(number)
|
||||
context:result_double(number)</PRE>
|
||||
<P>This function sets the result of a callback function to the value
|
||||
<CODE>number</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_int">context:result_int</A></H2>
|
||||
<PRE>
|
||||
context:result_int(number)</PRE>
|
||||
<P>This function sets the result of a callback function to the integer
|
||||
value in <CODE>number</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_text">context:result_text</A></H2>
|
||||
<PRE>
|
||||
context:result_text(str)</PRE>
|
||||
<P>This function sets the result of a callback function to the string in
|
||||
<CODE>str</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_blob">context:result_blob</A></H2>
|
||||
<PRE>
|
||||
context:result_blob(blob)</PRE>
|
||||
<P>This function sets the result of a callback function to the binary
|
||||
string in <CODE>blob</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_error">context:result_error</A></H2>
|
||||
<PRE>
|
||||
context:result_error(err)</PRE>
|
||||
<P>This function sets the result of a callback function to the error value
|
||||
in <CODE>err</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:user_data">context:user_data</A></H2>
|
||||
<PRE>
|
||||
context:user_data()</PRE>
|
||||
<P>Returns the userdata parameter given in the call to install the callback
|
||||
function (see <A HREF="#db:create_aggregate"><CODE>db:create_aggregate()</CODE></A> and
|
||||
<A HREF="#db:create_function"><CODE>db:create_function()</CODE></A> for details).</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="numerical error and result codes">Numerical error and result codes</A></H1>
|
||||
<P>The following constants are defined by module sqlite3:</P>
|
||||
<PRE>
|
||||
OK: 0 ERROR: 1 INTERNAL: 2 PERM: 3 ABORT: 4
|
||||
BUSY: 5 LOCKED: 6 NOMEM: 7 READONLY: 8 INTERRUPT: 9
|
||||
IOERR: 10 CORRUPT: 11 NOTFOUND: 12 FULL: 13 CANTOPEN: 14
|
||||
PROTOCOL: 15 EMPTY: 16 SCHEMA: 17 TOOBIG: 18 CONSTRAINT: 19
|
||||
MISMATCH: 20 MISUSE: 21 NOLFS: 22 FORMAT: 24 RANGE: 25
|
||||
NOTADB: 26 ROW: 100 DONE: 101</PRE>
|
||||
<P>For details about their exact meaning please see the <STRONG>SQLite3
|
||||
documentation</STRONG> <A HREF="http://www.sqlite.org/">http://www.sqlite.org/</A>.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="version">VERSION</A></H1>
|
||||
<P>This is <CODE>lsqlite3</CODE> subversion 6, also known as ``devel-0.6''.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="credits">CREDITS</A></H1>
|
||||
<P><CODE>lsqlite3</CODE> was developed by Tiago Dionizio and Doug Currie with
|
||||
contributions from Thomas Lauer and Michael Roth.</P>
|
||||
<P>This documentation is based on the ``(very) preliminary'' documents
|
||||
for the Idle-SQLite3 database module. Thanks to Thomas Lauer for
|
||||
making it available.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="license">LICENSE</A></H1>
|
||||
<PRE>
|
||||
/************************************************************************
|
||||
* lsqlite3 *
|
||||
* Copyright (C) 2002-2007 Tiago Dionizio, Doug Currie *
|
||||
* All rights reserved. *
|
||||
* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> *
|
||||
* Author : Doug Currie <doug.currie@alum.mit.edu> *
|
||||
* Library : lsqlite3 - a SQLite 3 database binding for Lua 5 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining *
|
||||
* a copy of this software and associated documentation files (the *
|
||||
* "Software"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to *
|
||||
* the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be *
|
||||
* included in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, *
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
************************************************************************/</PRE>
|
||||
|
||||
</BODY>
|
||||
|
||||
</HTML>
|
866
3rdparty/lsqlite3/doc/lsqlite3.pod
vendored
866
3rdparty/lsqlite3/doc/lsqlite3.pod
vendored
@ -1,866 +0,0 @@
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
B<LuaSQLite 3> - a Lua 5.1 wrapper for the SQLite3 library
|
||||
|
||||
=head1 OVERVIEW
|
||||
|
||||
B<LuaSQLite 3> is a thin wrapper around the public domain SQLite3
|
||||
database engine.
|
||||
|
||||
The C<lsqlite3> module supports the creation and manipulation of
|
||||
SQLite3 databases. After a C<require('lsqlite3')> the exported
|
||||
functions are called with prefix C<sqlite3>. However, most sqlite3
|
||||
functions are called via an object-oriented interface to either
|
||||
database or SQL statement objects; see below for details.
|
||||
|
||||
This documentation does not attempt to describe how SQLite3 itself
|
||||
works, it just describes the Lua binding and the available functions.
|
||||
For more information about the SQL features supported by SQLite3 and
|
||||
details about the syntax of SQL statements and queries, please see the
|
||||
B<SQLite3 documentation> L<http://www.sqlite.org/>. Using some of the
|
||||
advanced features (how to use callbacks, for instance) will require
|
||||
some familiarity with the SQLite3 API.
|
||||
|
||||
=head1 DOWNLOAD
|
||||
|
||||
B<LuaSQLite 3> source code can be downloaded from its
|
||||
LuaForge (L<http://luaforge.net/projects/luasqlite/>) page.
|
||||
|
||||
You will also need to build or obtain an SQLite3 loadable library
|
||||
(DLL or .so). See L<http://www.sqlite.org/> for obtaining SQLite3
|
||||
source code or downloading a binary SQLite3 library.
|
||||
|
||||
=head1 INSTALLATION
|
||||
|
||||
A I<Makefile> is provided; it assumes an SQLite3 library is already
|
||||
installed.
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
The distribution contains an I<examples> directory. The unit tests
|
||||
also show some example use.
|
||||
|
||||
=head1 VERIFICATION TESTS
|
||||
|
||||
The distribution contains some units tests using Michael Roth's
|
||||
C<lunit> (which is also included). Some of the tests were also derived
|
||||
from Michael's B<lua-sqlite3> module, and more unit tests added by
|
||||
Doug Currie.
|
||||
|
||||
The distribution also contains some functional tests by Tiago.
|
||||
|
||||
This version of C<lsqlite3> was tested with SQLite 3.4.2.
|
||||
|
||||
=head1 REFERENCE
|
||||
|
||||
=head1 SQLite3 functions
|
||||
|
||||
=head2 sqlite3.complete
|
||||
|
||||
sqlite3.complete(sql)
|
||||
|
||||
Returns true if the string C<sql> comprises one or more complete SQL
|
||||
statements and false otherwise.
|
||||
|
||||
=head2 sqlite3.open
|
||||
|
||||
sqlite3.open(filename)
|
||||
|
||||
Opens (or creates if it does not exist) an SQLite database with name
|
||||
C<filename> and returns its handle as userdata (the returned object
|
||||
should be used for all further method calls in connection with this
|
||||
specific database, see L</Database methods>). Example:
|
||||
|
||||
myDB=sqlite3.open('MyDatabase.sqlite3') -- open
|
||||
-- do some database calls...
|
||||
myDB:close() -- close
|
||||
|
||||
In case of an error, the function returns nil, an error code and an
|
||||
error message.
|
||||
|
||||
=head2 sqlite3.open_memory
|
||||
|
||||
sqlite3.open_memory()
|
||||
|
||||
Opens an SQLite database B<in memory> and returns its handle as
|
||||
userdata. In case of an error, the function returns nil, an error code
|
||||
and an error message. (In-memory databases are volatile as they are
|
||||
never stored on disk.)
|
||||
|
||||
=head2 sqlite3.temp_directory
|
||||
|
||||
sqlite3.temp_directory([temp])
|
||||
|
||||
Sets or queries the directory used by SQLite for temporary files. If
|
||||
string C<temp> is a directory name or nil, the temporary directory is
|
||||
set accordingly and the old value is returned. If C<temp> is missing,
|
||||
the function simply returns the current temporary directory.
|
||||
|
||||
=head2 sqlite3.version
|
||||
|
||||
sqlite3.version()
|
||||
|
||||
Returns a string with SQLite version information, in the form 'x.y[.z]'.
|
||||
|
||||
=head1 Database methods
|
||||
|
||||
After opening a database with L<C<sqlite3.open()>|/sqlite3.open> or
|
||||
L<C<sqlite3.open_memory()>|/sqlite3.open_memory>
|
||||
the returned database object should be used for all further method calls
|
||||
in connection with that database. An open database object supports the
|
||||
following methods.
|
||||
|
||||
=head2 db:busy_handler
|
||||
|
||||
db:busy_handler([func[,udata]])
|
||||
|
||||
Sets or removes a busy handler for a database. C<func> is either a Lua
|
||||
function that implements the busy handler or nil to remove a previously
|
||||
set handler. This function returns nothing.
|
||||
|
||||
The handler function is called with two parameters: C<udata> and the
|
||||
number of (re-)tries for a pending transaction. It should return nil,
|
||||
false or 0 if the transaction is to be aborted. All other values will
|
||||
result in another attempt to perform the transaction. (See the SQLite
|
||||
documentation for important hints about writing busy handlers.)
|
||||
|
||||
=head2 db:busy_timeout
|
||||
|
||||
db:busy_timeout(t)
|
||||
|
||||
Sets a busy handler that waits for C<t> milliseconds if a transaction
|
||||
cannot proceed. Calling this function will remove any busy handler set
|
||||
by L<C<db:busy_handler()>|/db:busy_handler>; calling it with an argument
|
||||
less than or equal to 0 will turn off all busy handlers.
|
||||
|
||||
=head2 db:changes
|
||||
|
||||
db:changes()
|
||||
|
||||
This function returns the number of database rows that were changed (or
|
||||
inserted or deleted) by the most recent SQL statement. Only changes that
|
||||
are directly specified by INSERT, UPDATE, or DELETE statements are
|
||||
counted. Auxiliary changes caused by triggers are not counted. Use
|
||||
L<C<db:total_changes()>|/db:total_changes> to find the total number of
|
||||
changes.
|
||||
|
||||
=head2 db:close
|
||||
|
||||
db:close()
|
||||
|
||||
Closes a database. All SQL statements prepared using
|
||||
L<C<db:prepare()>|/db:prepare> should
|
||||
have been finalized before this function is called. The function returns
|
||||
C<sqlite3.OK> on success or else a numerical error code (see the list of
|
||||
L</Numerical error and result codes>).
|
||||
|
||||
=head2 db:close_vm
|
||||
|
||||
db:close_vm(temponly)
|
||||
|
||||
Finalizes all statements that have not been explicitly finalized. If
|
||||
C<temponly> is true, only internal, temporary statements are finalized.
|
||||
This function returns nothing.
|
||||
|
||||
=head2 db:create_aggregate
|
||||
|
||||
db:create_aggregate(name,nargs,step,final)
|
||||
|
||||
This function creates an aggregate callback function. Aggregates perform
|
||||
an operation over all rows in a query. C<name> is a string with the name
|
||||
of the aggregate function as given in an SQL statement; C<nargs> is the
|
||||
number of arguments this call will provide. C<step> is the actual Lua
|
||||
function that gets called once for every row; it should accept a function
|
||||
context (see L</Methods for callback contexts>) plus the same number of
|
||||
parameters as given in C<nargs>. C<final> is a function that is called
|
||||
once after all rows have been processed; it receives one argument, the
|
||||
function context.
|
||||
|
||||
The function context can be used inside the two callback functions to
|
||||
communicate with SQLite3. Here is a simple example:
|
||||
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
local num_sum=0
|
||||
local function oneRow(context,num) -- add one column in all rows
|
||||
num_sum=num_sum+num
|
||||
end
|
||||
local function afterLast(context) -- return sum after last row has been processed
|
||||
context:result_number(num_sum)
|
||||
num_sum=0
|
||||
end
|
||||
db:create_aggregate("do_the_sums",1,oneRow,afterLast)
|
||||
for sum in db:urows('SELECT do_the_sums(num1) FROM numbers') do print("Sum of col 1:",sum) end
|
||||
for sum in db:urows('SELECT do_the_sums(num2) FROM numbers') do print("Sum of col 2:",sum) end
|
||||
|
||||
This prints:
|
||||
|
||||
Sum of col 1: 6
|
||||
Sum of col 2: 66
|
||||
|
||||
=head2 db:create_collation
|
||||
|
||||
db:create_collation(name,func)
|
||||
|
||||
This creates a collation callback. A collation callback is used to
|
||||
establish a collation order, mostly for string comparisons and sorting
|
||||
purposes. C<name> is a string with the name of the collation to be created;
|
||||
C<func> is a function that accepts two string arguments, compares them
|
||||
and returns 0 if both strings are identical, -1 if the first argument is
|
||||
lower in the collation order than the second and 1 if the first argument
|
||||
is higher in the collation order than the second. A simple example:
|
||||
|
||||
local function collate(s1,s2)
|
||||
s1=s1:lower()
|
||||
s2=s2:lower()
|
||||
if s1==s2 then return 0
|
||||
elseif s1<s2 then return -1
|
||||
else return 1 end
|
||||
end
|
||||
db:exec[=[
|
||||
CREATE TABLE test(id INTEGER PRIMARY KEY,content COLLATE CINSENS);
|
||||
INSERT INTO test VALUES(NULL,'hello world');
|
||||
INSERT INTO test VALUES(NULL,'Buenos dias');
|
||||
INSERT INTO test VALUES(NULL,'HELLO WORLD');
|
||||
]=]
|
||||
db:create_collation('CINSENS',collate)
|
||||
for row in db:nrows('SELECT * FROM test') do print(row.id,row.content) end
|
||||
|
||||
=head2 db:create_function
|
||||
|
||||
db:create_function(name,nargs,func)
|
||||
|
||||
This function creates a callback function. Callback function are called
|
||||
by SQLite3 once for every row in a query. C<name> is a string with the
|
||||
name of the callback function as given in an SQL statement; C<nargs> is
|
||||
the number of arguments this call will provide. C<func> is the actual Lua
|
||||
function that gets called once for every row; it should accept a
|
||||
function context (see L</Methods for callback contexts>) plus the same
|
||||
number of parameters as given in nargs. Here is an example:
|
||||
|
||||
db:exec'CREATE TABLE test(col1,col2,col3)'
|
||||
db:exec'INSERT INTO test VALUES(1,2,4)'
|
||||
db:exec'INSERT INTO test VALUES(2,4,9)'
|
||||
db:exec'INSERT INTO test VALUES(3,6,16)'
|
||||
db:create_function('sum_cols',3,function(ctx,a,b,c)
|
||||
ctx:result_number(a+b+c)
|
||||
end))
|
||||
for col1,col2,col3,sum in db:urows('SELECT *,sum_cols(col1,col2,col3) FROM test') do
|
||||
util.printf('%2i+%2i+%2i=%2i\n',col1,col2,col3,sum)
|
||||
end
|
||||
|
||||
=head2 db:errcode
|
||||
|
||||
db:errcode()
|
||||
db:error_code()
|
||||
|
||||
Returns the numerical result code (or extended result code) for the most
|
||||
recent failed call associated with database db. See
|
||||
L</Numerical error and result codes> for details.
|
||||
|
||||
=head2 db:errmsg
|
||||
|
||||
db:errmsg()
|
||||
db:error_message()
|
||||
|
||||
Returns a string that contains an error message for the most recent
|
||||
failed call associated with database db.
|
||||
|
||||
=head2 db:exec
|
||||
|
||||
db:exec(sql[,func[,udata]])
|
||||
db:execute(sql[,func[,udata]])
|
||||
|
||||
Compiles and executes the SQL statement(s) given in string C<sql>. The
|
||||
statements are simply executed one after the other and not stored. The
|
||||
function returns C<sqlite3.OK> on success or else a numerical error code
|
||||
(see L</Numerical error and result codes>).
|
||||
|
||||
If one or more of the SQL statements are queries, then the callback
|
||||
function specified in C<func> is invoked once for each row of the query
|
||||
result (if C<func> is nil, no callback is invoked). The callback receives
|
||||
four arguments: C<udata> (the third parameter of the C<db:exec()> call),
|
||||
the number of columns in the row, a table with the column values and
|
||||
another table with the column names. The callback function should return
|
||||
0. If the callback returns a non-zero value then the query is aborted,
|
||||
all subsequent SQL statements are skipped and C<db:exec()> returns
|
||||
C<sqlite3.ABORT>. Here is a simple example:
|
||||
|
||||
sql=[=[
|
||||
CREATE TABLE numbers(num1,num2,str);
|
||||
INSERT INTO numbers VALUES(1,11,"ABC");
|
||||
INSERT INTO numbers VALUES(2,22,"DEF");
|
||||
INSERT INTO numbers VALUES(3,33,"UVW");
|
||||
INSERT INTO numbers VALUES(4,44,"XYZ");
|
||||
SELECT * FROM numbers;
|
||||
]=]
|
||||
function showrow(udata,cols,values,names)
|
||||
assert(udata=='test_udata')
|
||||
print('exec:')
|
||||
for i=1,cols do print('',names[i],values[i]) end
|
||||
return 0
|
||||
end
|
||||
db:exec(sql,showrow,'test_udata')
|
||||
|
||||
=head2 db:interrupt
|
||||
|
||||
db:interrupt()
|
||||
|
||||
This function causes any pending database operation to abort and return
|
||||
at the next opportunity. This function returns nothing.
|
||||
|
||||
=head2 db:isopen
|
||||
|
||||
db:isopen()
|
||||
|
||||
Returns true if database db is open, false otherwise.
|
||||
|
||||
=head2 db:last_insert_rowid
|
||||
|
||||
db:last_insert_rowid()
|
||||
|
||||
This function returns the rowid of the most recent INSERT into the
|
||||
database. If no inserts have ever occurred, 0 is returned. (Each row in
|
||||
an SQLite table has a unique 64-bit signed integer key called the
|
||||
'rowid'. This id is always available as an undeclared column named
|
||||
ROWID, OID, or _ROWID_. If the table has a column of type INTEGER
|
||||
PRIMARY KEY then that column is another alias for the rowid.)
|
||||
|
||||
If an INSERT occurs within a trigger, then the rowid of the inserted row
|
||||
is returned as long as the trigger is running. Once the trigger
|
||||
terminates, the value returned reverts to the last value inserted before
|
||||
the trigger fired.
|
||||
|
||||
=head2 db:nrows
|
||||
|
||||
db:nrows(sql)
|
||||
|
||||
Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string C<sql>. Each call to the iterator returns a
|
||||
table in which the named fields correspond to the columns in the database.
|
||||
Here is an example:
|
||||
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:nrows('SELECT * FROM numbers') do table.print(a) end
|
||||
|
||||
This script prints:
|
||||
|
||||
num2: 11
|
||||
num1: 1
|
||||
num2: 22
|
||||
num1: 2
|
||||
num2: 33
|
||||
num1: 3
|
||||
|
||||
=head2 db:prepare
|
||||
|
||||
db:prepare(sql)
|
||||
|
||||
This function compiles the SQL statement in string C<sql> into an internal
|
||||
representation and returns this as userdata. The returned object should
|
||||
be used for all further method calls in connection with this specific
|
||||
SQL statement (see L</Methods for prepared statements>).
|
||||
|
||||
=head2 db:progress_handler
|
||||
|
||||
db:progress_handler(n,func,udata)
|
||||
|
||||
This function installs a callback function C<func> that is invoked
|
||||
periodically during long-running calls to L<C<db:exec()>|/db:exec>
|
||||
or L<C<stmt:step()>|/stmt:step>. The
|
||||
progress callback is invoked once for every C<n> internal operations,
|
||||
where C<n> is the first argument to this function. C<udata> is passed to
|
||||
the progress callback function each time it is invoked. If a call to
|
||||
C<db:exec()> or C<stmt:step()> results in fewer than C<n> operations
|
||||
being executed, then the progress callback is never invoked. Only a
|
||||
single progress callback function may be registered for each opened
|
||||
database and a call to this function will overwrite any previously set
|
||||
callback function. To remove the progress callback altogether, pass nil
|
||||
as the second argument.
|
||||
|
||||
If the progress callback returns a result other than 0, then the current
|
||||
query is immediately terminated, any database changes are rolled back
|
||||
and the containing C<db:exec()> or C<stmt:step()> call returns
|
||||
C<sqlite3.INTERRUPT>. This feature can be used to cancel long-running
|
||||
queries.
|
||||
|
||||
=head2 db:rows
|
||||
|
||||
db:rows(sql)
|
||||
|
||||
Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string C<sql>. Each call to the iterator returns a table
|
||||
in which the numerical indices 1 to n correspond to the selected columns
|
||||
1 to n in the database. Here is an example:
|
||||
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:rows('SELECT * FROM numbers') do table.print(a) end
|
||||
|
||||
This script prints:
|
||||
|
||||
1: 1
|
||||
2: 11
|
||||
1: 2
|
||||
2: 22
|
||||
1: 3
|
||||
2: 33
|
||||
|
||||
=head2 db:total_changes
|
||||
|
||||
db:total_changes()
|
||||
|
||||
This function returns the number of database rows that have been
|
||||
modified by INSERT, UPDATE or DELETE statements since the database was
|
||||
opened. This includes UPDATE, INSERT and DELETE statements executed as
|
||||
part of trigger programs. All changes are counted as soon as the
|
||||
statement that produces them is completed by calling either
|
||||
L<C<stmt:reset()>|/stmt:reset> or L<C<stmt:finalize()>|/stmt:finalize>.
|
||||
|
||||
=head2 db:trace
|
||||
|
||||
db:trace(func,udata)
|
||||
|
||||
This function installs a trace callback handler. C<func> is a Lua
|
||||
function that is called by SQLite3 just before the evaluation of an SQL
|
||||
statement. This callback receives two arguments: the first is the
|
||||
C<udata> argument used when the callback was installed; the second is a
|
||||
string with the SQL statement about to be executed.
|
||||
|
||||
=head2 db:urows
|
||||
|
||||
db:urows(sql)
|
||||
|
||||
Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string C<sql>. Each call to the iterator returns the
|
||||
values that correspond to the columns in the currently selected row.
|
||||
Here is an example:
|
||||
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for num1,num2 in db:urows('SELECT * FROM numbers') do print(num1,num2) end
|
||||
|
||||
This script prints:
|
||||
|
||||
1 11
|
||||
2 22
|
||||
3 33
|
||||
|
||||
=head1 Methods for prepared statements
|
||||
|
||||
After creating a prepared statement with L<C<db:prepare()>|/db:prepare>
|
||||
the returned statement object should be used for all further calls in
|
||||
connection with that statement. Statement objects support the following
|
||||
methods.
|
||||
|
||||
=head2 stmt:bind
|
||||
|
||||
stmt:bind(n[,value])
|
||||
|
||||
Binds value to statement parameter C<n>. If the type of value is string
|
||||
or number, it is bound as text or double, respectively. If C<value> is a
|
||||
boolean or nil or missing, any previous binding is removed. The function
|
||||
returns C<sqlite3.OK> on success or else a numerical error code (see
|
||||
L</Numerical error and result codes>).
|
||||
|
||||
=head2 stmt:bind_blob
|
||||
|
||||
stmt:bind_blob(n,blob)
|
||||
|
||||
Binds string C<blob> (which can be a binary string) as a blob to
|
||||
statement parameter C<n>. The function returns C<sqlite3.OK> on success
|
||||
or else a numerical error code (see L</Numerical error and result codes>).
|
||||
|
||||
=head2 stmt:bind_names
|
||||
|
||||
stmt:bind_names(nametable)
|
||||
|
||||
Binds the values in C<nametable> to statement parameters. If the
|
||||
statement parameters are named (i.e., of the form ":AAA" or "$AAA")
|
||||
then this function looks for appropriately named fields in C<nametable>;
|
||||
if the statement parameters are
|
||||
not named, it looks for numerical fields 1 to the number of statement
|
||||
parameters. The function returns C<sqlite3.OK> on success or else a
|
||||
numerical error code (see L</Numerical error and result codes>).
|
||||
|
||||
=head2 stmt:bind_parameter_count
|
||||
|
||||
stmt:bind_parameter_count()
|
||||
|
||||
Returns the largest statement parameter index in prepared statement
|
||||
C<stmt>. When the statement parameters are of the forms ":AAA" or "?",
|
||||
then they are assigned sequentially increasing numbers beginning with
|
||||
one, so the value returned is the number of parameters. However if the
|
||||
same statement parameter name is used multiple times, each occurrence
|
||||
is given the same number, so the value returned is the number of unique
|
||||
statement parameter names.
|
||||
|
||||
If statement parameters of the form "?NNN" are used (where NNN is an
|
||||
integer) then there might be gaps in the numbering and the value
|
||||
returned by this interface is the index of the statement parameter with
|
||||
the largest index value.
|
||||
|
||||
=head2 stmt:bind_parameter_name
|
||||
|
||||
stmt:bind_parameter_name(n)
|
||||
|
||||
Returns the name of the C<n>-th parameter in prepared statement C<stmt>.
|
||||
Statement parameters of the form ":AAA" or "@AAA" or "$VVV" have a name
|
||||
which is the string ":AAA" or "@AAA" or "$VVV". In other words, the
|
||||
initial ":" or "$" or "@" is included as part of the name. Parameters
|
||||
of the form "?" or "?NNN" have no name. The first bound parameter has
|
||||
an index of 1.
|
||||
If the value C<n> is out of range or if the C<n>-th parameter is
|
||||
nameless, then nil is returned. The function returns C<sqlite3.OK> on
|
||||
success or else a numerical error code (see
|
||||
L</Numerical error and result codes>)
|
||||
|
||||
=head2 stmt:bind_values
|
||||
|
||||
stmt:bind_values(value1,value2,...,valueN)
|
||||
|
||||
Binds the given values to statement parameters. The function returns
|
||||
C<sqlite3.OK> on success or else a numerical error code (see
|
||||
L</Numerical error and result codes>).
|
||||
|
||||
=head2 stmt:columns
|
||||
|
||||
stmt:columns()
|
||||
|
||||
Returns the number of columns in the result set returned by statement
|
||||
stmt or 0 if the statement does not return data (for example an UPDATE).
|
||||
|
||||
=head2 stmt:finalize
|
||||
|
||||
stmt:finalize()
|
||||
|
||||
This function frees prepared statement stmt. If the statement was
|
||||
executed successfully, or not executed at all, then C<sqlite3.OK> is
|
||||
returned. If execution of the statement failed then an error code is
|
||||
returned.
|
||||
|
||||
=head2 stmt:get_name
|
||||
|
||||
stmt:get_name(n)
|
||||
|
||||
Returns the name of column C<n> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)
|
||||
|
||||
=head2 stmt:get_named_types
|
||||
|
||||
stmt:get_named_types()
|
||||
|
||||
Returns a table with the names and types of all columns in the result
|
||||
set of statement stmt.
|
||||
|
||||
=head2 stmt:get_named_values
|
||||
|
||||
stmt:get_named_values()
|
||||
|
||||
This function returns a table with names and values of all columns in
|
||||
the current result row of a query.
|
||||
|
||||
=head2 stmt:get_names
|
||||
|
||||
stmt:get_names()
|
||||
|
||||
This function returns an array with the names of all columns in the
|
||||
result set returned by statement stmt.
|
||||
|
||||
=head2 stmt:get_type
|
||||
|
||||
stmt:get_type(n)
|
||||
|
||||
Returns the type of column C<n> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)
|
||||
|
||||
=head2 stmt:get_types
|
||||
|
||||
stmt:get_types()
|
||||
|
||||
This function returns an array with the types of all columns in the
|
||||
result set returned by statement stmt.
|
||||
|
||||
=head2 stmt:get_unames
|
||||
|
||||
stmt:get_unames()
|
||||
|
||||
This function returns a list with the names of all columns in the result
|
||||
set returned by statement stmt.
|
||||
|
||||
=head2 stmt:get_utypes
|
||||
|
||||
stmt:get_utypes()
|
||||
|
||||
This function returns a list with the types of all columns in the result
|
||||
set returned by statement stmt.
|
||||
|
||||
=head2 stmt:get_uvalues
|
||||
|
||||
stmt:get_uvalues()
|
||||
|
||||
This function returns a list with the values of all columns in the
|
||||
current result row of a query.
|
||||
|
||||
=head2 stmt:get_value
|
||||
|
||||
stmt:get_value(n)
|
||||
|
||||
Returns the value of column C<n> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)
|
||||
|
||||
=head2 stmt:get_values
|
||||
|
||||
stmt:get_values()
|
||||
|
||||
This function returns an array with the values of all columns in the
|
||||
result set returned by statement stmt.
|
||||
|
||||
=head2 stmt:isopen
|
||||
|
||||
stmt:isopen()
|
||||
|
||||
Returns true if stmt has not yet been finalized, false otherwise.
|
||||
|
||||
=head2 stmt:nrows
|
||||
|
||||
stmt:nrows()
|
||||
|
||||
Returns an function that iterates over the names and values of the
|
||||
result set of statement C<stmt>. Each iteration returns a table with the
|
||||
names and values for the current row.
|
||||
This is the prepared statement equivalent of L<C<db:nrows()>|/db:nrows>.
|
||||
|
||||
=head2 stmt:reset
|
||||
|
||||
stmt:reset()
|
||||
|
||||
This function resets SQL statement C<stmt>, so that it is ready to be
|
||||
re-executed. Any statement variables that had values bound to them using
|
||||
the C<stmt:bind*()> functions retain their values.
|
||||
|
||||
=head2 stmt:rows
|
||||
|
||||
stmt:rows()
|
||||
|
||||
Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns an array with the values for the
|
||||
current row.
|
||||
This is the prepared statement equivalent of L<C<db:rows()>|/db:rows>.
|
||||
|
||||
=head2 stmt:step
|
||||
|
||||
stmt:step()
|
||||
|
||||
This function must be called to evaluate the (next iteration of the)
|
||||
prepared statement stmt. It will return one of the following values:
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.BUSY>: the engine was unable to acquire the locks needed. If the
|
||||
statement is a COMMIT or occurs outside of an explicit transaction, then
|
||||
you can retry the statement. If the statement is not a COMMIT and occurs
|
||||
within a explicit transaction then you should rollback the transaction
|
||||
before continuing.
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.DONE>: the statement has finished executing successfully.
|
||||
L<C<stmt:step()>|/stmt:step> should not be called again on this statement
|
||||
without first calling L<C<stmt:reset()>|/stmt:reset> to reset the virtual
|
||||
machine back to the initial state.
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.ROW>: this is returned each time a new row of data is ready for
|
||||
processing by the caller. The values may be accessed using the column
|
||||
access functions. L<C<stmt:step()>|/stmt:step> can be called again to
|
||||
retrieve the next row of data.
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.ERROR>: a run-time error (such as a constraint violation) has
|
||||
occurred. L<C<stmt:step()>|/stmt:step> should not be called again. More
|
||||
information may be found by calling L<C<db:errmsg()>|/db:errmsg>. A more
|
||||
specific error
|
||||
code (can be obtained by calling L<C<stmt:reset()>|/stmt:reset>.
|
||||
|
||||
=item *
|
||||
|
||||
C<sqlite3.MISUSE>: the function was called inappropriately, perhaps
|
||||
because the statement has already been finalized or a previous call to
|
||||
L<C<stmt:step()>|/stmt:step> has returned C<sqlite3.ERROR> or
|
||||
C<sqlite3.DONE>.
|
||||
|
||||
=back
|
||||
|
||||
=head2 stmt:urows
|
||||
|
||||
stmt:urows()
|
||||
|
||||
Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns the values for the current row.
|
||||
This is the prepared statement equivalent of L<C<db:urows()>|/db:urows>.
|
||||
|
||||
=head1 Methods for callback contexts
|
||||
|
||||
A callback context is available as a parameter inside the callback
|
||||
functions L<C<db:create_aggregate()>|/db:create_aggregate> and
|
||||
L<C<db:create_function()>|/db:create_function>. It can be used
|
||||
to get further information about the state of a query.
|
||||
|
||||
=head2 context:aggregate_count
|
||||
|
||||
context:aggregate_count()
|
||||
|
||||
Returns the number of calls to the aggregate step function.
|
||||
|
||||
=head2 context:get_aggregate_data
|
||||
|
||||
context:get_aggregate_data()
|
||||
|
||||
Returns the user-definable data field for callback funtions.
|
||||
|
||||
=head2 context:set_aggregate_data
|
||||
|
||||
context:set_aggregate_data(udata)
|
||||
|
||||
Set the user-definable data field for callback funtions to C<udata>.
|
||||
|
||||
=head2 context:result
|
||||
|
||||
context:result(res)
|
||||
|
||||
This function sets the result of a callback function to res. The type of
|
||||
the result depends on the type of res and is either a number or a string
|
||||
or nil. All other values will raise an error message.
|
||||
|
||||
=head2 context:result_null
|
||||
|
||||
context:result_null()
|
||||
|
||||
This function sets the result of a callback function to nil. It returns
|
||||
nothing.
|
||||
|
||||
=head2 context:result_number
|
||||
|
||||
context:result_number(number)
|
||||
context:result_double(number)
|
||||
|
||||
This function sets the result of a callback function to the value
|
||||
C<number>. It returns nothing.
|
||||
|
||||
=head2 context:result_int
|
||||
|
||||
context:result_int(number)
|
||||
|
||||
This function sets the result of a callback function to the integer
|
||||
value in C<number>. It returns nothing.
|
||||
|
||||
=head2 context:result_text
|
||||
|
||||
context:result_text(str)
|
||||
|
||||
This function sets the result of a callback function to the string in
|
||||
C<str>. It returns nothing.
|
||||
|
||||
=head2 context:result_blob
|
||||
|
||||
context:result_blob(blob)
|
||||
|
||||
This function sets the result of a callback function to the binary
|
||||
string in C<blob>. It returns nothing.
|
||||
|
||||
=head2 context:result_error
|
||||
|
||||
context:result_error(err)
|
||||
|
||||
This function sets the result of a callback function to the error value
|
||||
in C<err>. It returns nothing.
|
||||
|
||||
=head2 context:user_data
|
||||
|
||||
context:user_data()
|
||||
|
||||
Returns the userdata parameter given in the call to install the callback
|
||||
function (see L<C<db:create_aggregate()>|/db:create_aggregate> and
|
||||
L<C<db:create_function()>|/db:create_function> for details).
|
||||
|
||||
=head1 Numerical error and result codes
|
||||
|
||||
The following constants are defined by module sqlite3:
|
||||
|
||||
OK: 0 ERROR: 1 INTERNAL: 2 PERM: 3 ABORT: 4
|
||||
BUSY: 5 LOCKED: 6 NOMEM: 7 READONLY: 8 INTERRUPT: 9
|
||||
IOERR: 10 CORRUPT: 11 NOTFOUND: 12 FULL: 13 CANTOPEN: 14
|
||||
PROTOCOL: 15 EMPTY: 16 SCHEMA: 17 TOOBIG: 18 CONSTRAINT: 19
|
||||
MISMATCH: 20 MISUSE: 21 NOLFS: 22 FORMAT: 24 RANGE: 25
|
||||
NOTADB: 26 ROW: 100 DONE: 101
|
||||
|
||||
For details about their exact meaning please see the B<SQLite3
|
||||
documentation> L<http://www.sqlite.org/>.
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
This is C<lsqlite3> subversion 6, also known as "devel-0.6".
|
||||
|
||||
=head1 CREDITS
|
||||
|
||||
C<lsqlite3> was developed by Tiago Dionizio and Doug Currie with
|
||||
contributions from Thomas Lauer and Michael Roth.
|
||||
|
||||
This documentation is based on the "(very) preliminary" documents
|
||||
for the Idle-SQLite3 database module. Thanks to Thomas Lauer for
|
||||
making it available.
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
/************************************************************************
|
||||
* lsqlite3 *
|
||||
* Copyright (C) 2002-2007 Tiago Dionizio, Doug Currie *
|
||||
* All rights reserved. *
|
||||
* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> *
|
||||
* Author : Doug Currie <doug.currie@alum.mit.edu> *
|
||||
* Library : lsqlite3 - a SQLite 3 database binding for Lua 5 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining *
|
||||
* a copy of this software and associated documentation files (the *
|
||||
* "Software"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to *
|
||||
* the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be *
|
||||
* included in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, *
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
************************************************************************/
|
||||
|
7
3rdparty/lsqlite3/doc/pod2html.pl
vendored
7
3rdparty/lsqlite3/doc/pod2html.pl
vendored
@ -1,7 +0,0 @@
|
||||
#!perl
|
||||
|
||||
use Pod::Html;
|
||||
|
||||
pod2html @ARGV;
|
||||
|
||||
__END__
|
35
3rdparty/lsqlite3/examples/aggregate.lua
vendored
35
3rdparty/lsqlite3/examples/aggregate.lua
vendored
@ -1,35 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
assert( db:exec "CREATE TABLE test (col1, col2)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (1, 2)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (2, 4)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (3, 6)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (4, 8)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (5, 10)" )
|
||||
|
||||
do
|
||||
|
||||
local square_error_sum = 0
|
||||
|
||||
local function step(ctx, a, b)
|
||||
local error = a - b
|
||||
local square_error = error * error
|
||||
square_error_sum = square_error_sum + square_error
|
||||
end
|
||||
|
||||
local function final(ctx)
|
||||
ctx:result_number( square_error_sum / ctx:aggregate_count() )
|
||||
end
|
||||
|
||||
assert( db:create_aggregate("my_stats", 2, step, final) )
|
||||
|
||||
end
|
||||
|
||||
--for a,b in db:urows("SELECT col1, col2 FROM test")
|
||||
--do print("a b: ", a, b) end
|
||||
|
||||
for my_stats in db:urows("SELECT my_stats(col1, col2) FROM test")
|
||||
do print("my_stats:", my_stats) end
|
21
3rdparty/lsqlite3/examples/function.lua
vendored
21
3rdparty/lsqlite3/examples/function.lua
vendored
@ -1,21 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
assert( db:exec "CREATE TABLE test (col1, col2)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (1, 2)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (2, 4)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (3, 6)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (4, 8)" )
|
||||
assert( db:exec "INSERT INTO test VALUES (5, 10)" )
|
||||
|
||||
assert( db:create_function("my_sum", 2, function(ctx, a, b)
|
||||
ctx:result_number( a + b )
|
||||
end))
|
||||
|
||||
|
||||
for col1, col2, sum in db:urows("SELECT *, my_sum(col1, col2) FROM test") do
|
||||
print(col1, col2, sum)
|
||||
end
|
122
3rdparty/lsqlite3/examples/order.lua
vendored
122
3rdparty/lsqlite3/examples/order.lua
vendored
@ -1,122 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = assert( sqlite3:open_memory() )
|
||||
|
||||
assert( db:exec[[
|
||||
|
||||
CREATE TABLE customer (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name VARCHAR(40)
|
||||
);
|
||||
|
||||
CREATE TABLE invoice (
|
||||
id INTEGER PRIMARY KEY,
|
||||
customer INTEGER NOT NULL,
|
||||
title VARCHAR(80) NOT NULL,
|
||||
article1 VARCHAR(40) NOT NULL,
|
||||
price1 REAL NOT NULL,
|
||||
article2 VARCHAR(40),
|
||||
price2 REAL
|
||||
);
|
||||
|
||||
CREATE TABLE invoice_overflow (
|
||||
id INTEGER PRIMARY KEY,
|
||||
invoice INTEGER NOT NULL,
|
||||
article VARCHAR(40) NOT NULL,
|
||||
price REAL NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO customer VALUES(
|
||||
1, "Michael" );
|
||||
|
||||
INSERT INTO invoice VALUES(
|
||||
1, 1, "Computer parts", "harddisc", 89.90, "floppy", 9.99 );
|
||||
|
||||
INSERT INTO customer VALUES(
|
||||
2, "John" );
|
||||
|
||||
INSERT INTO invoice VALUES(
|
||||
2, 2, "Somme food", "apples", 2.79, "pears", 5.99 );
|
||||
|
||||
INSERT INTO invoice_overflow VALUES(
|
||||
NULL, 2, "grapes", 6.34 );
|
||||
|
||||
INSERT INTO invoice_overflow VALUES(
|
||||
NULL, 2, "strawberries", 4.12 );
|
||||
|
||||
INSERT INTO invoice_overflow VALUES(
|
||||
NULL, 2, "tomatoes", 6.17 );
|
||||
|
||||
INSERT INTO invoice VALUES(
|
||||
3, 2, "A new car", "Cybercar XL-1000", 65000.00, NULL, NULL );
|
||||
|
||||
]] )
|
||||
|
||||
|
||||
local function customer_name(id)
|
||||
local stmt = db:prepare("SELECT name FROM customer WHERE id = ?")
|
||||
stmt:bind_values(id)
|
||||
stmt:step()
|
||||
local r = stmt:get_uvalues()
|
||||
stmt:finalize()
|
||||
return r
|
||||
end
|
||||
|
||||
|
||||
local function all_invoices()
|
||||
return db:nrows("SELECT id, customer, title FROM invoice")
|
||||
end
|
||||
|
||||
|
||||
local function all_articles(invoice)
|
||||
|
||||
local function iterator()
|
||||
local stmt, row
|
||||
|
||||
-- Get the articles that are contained in the invoice table itself.
|
||||
stmt = db:prepare("SELECT article1, price1, article2, price2 FROM invoice WHERE id = ?")
|
||||
stmt:bind_values(invoice)
|
||||
stmt:step()
|
||||
row = stmt:get_named_values()
|
||||
|
||||
-- Every Invoice has at least one article.
|
||||
coroutine.yield(row.article1, row.price1)
|
||||
|
||||
-- Maybe the Invoice has a second article?
|
||||
if row.article2 then
|
||||
|
||||
-- Yes, there is a second article, so return it.
|
||||
coroutine.yield(row.article2, row.price2)
|
||||
|
||||
-- When there was an second article, maybe there are even
|
||||
-- more articles in the overflow table? We will see...
|
||||
|
||||
stmt = db:prepare("SELECT article, price FROM invoice_overflow WHERE invoice = ? ORDER BY id")
|
||||
stmt:bind_values(invoice)
|
||||
|
||||
for row in stmt:nrows() do
|
||||
coroutine.yield(row.article, row.price)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return coroutine.wrap(iterator)
|
||||
end
|
||||
|
||||
|
||||
for invoice in all_invoices() do
|
||||
local id = invoice.id
|
||||
local name = customer_name(invoice.customer)
|
||||
local title = invoice.title
|
||||
|
||||
print()
|
||||
print("Invoice #"..id..", "..name..": '"..title.."'")
|
||||
print("----------------------------------------")
|
||||
|
||||
for article, price in all_articles(id) do
|
||||
print( string.format("%20s %8.2f", article, price) )
|
||||
end
|
||||
|
||||
print()
|
||||
end
|
16
3rdparty/lsqlite3/examples/simple.lua
vendored
16
3rdparty/lsqlite3/examples/simple.lua
vendored
@ -1,16 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
db:exec[[
|
||||
CREATE TABLE test (id INTEGER PRIMARY KEY, content);
|
||||
|
||||
INSERT INTO test VALUES (NULL, 'Hello World');
|
||||
INSERT INTO test VALUES (NULL, 'Hello Lua');
|
||||
INSERT INTO test VALUES (NULL, 'Hello Sqlite3')
|
||||
]]
|
||||
|
||||
for row in db:nrows("SELECT * FROM test") do
|
||||
print(row.id, row.content)
|
||||
end
|
22
3rdparty/lsqlite3/examples/smart.lua
vendored
22
3rdparty/lsqlite3/examples/smart.lua
vendored
@ -1,22 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
db:exec[[ CREATE TABLE test (id INTEGER PRIMARY KEY, content) ]]
|
||||
|
||||
local stmt = db:prepare[[ INSERT INTO test VALUES (:key, :value) ]]
|
||||
|
||||
stmt:bind_names{ key = 1, value = "Hello World" }
|
||||
stmt:step()
|
||||
stmt:reset()
|
||||
stmt:bind_names{ key = 2, value = "Hello Lua" }
|
||||
stmt:step()
|
||||
stmt:reset()
|
||||
stmt:bind_names{ key = 3, value = "Hello Sqlite3" }
|
||||
stmt:step()
|
||||
stmt:finalize()
|
||||
|
||||
for row in db:nrows("SELECT * FROM test") do
|
||||
print(row.id, row.content)
|
||||
end
|
39
3rdparty/lsqlite3/examples/statement.lua
vendored
39
3rdparty/lsqlite3/examples/statement.lua
vendored
@ -1,39 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
db:exec[[
|
||||
CREATE TABLE test (
|
||||
id INTEGER PRIMARY KEY,
|
||||
content VARCHAR
|
||||
);
|
||||
]]
|
||||
|
||||
local insert_stmt = assert( db:prepare("INSERT INTO test VALUES (NULL, ?)") )
|
||||
|
||||
local function insert(data)
|
||||
insert_stmt:bind_values(data)
|
||||
insert_stmt:step()
|
||||
insert_stmt:reset()
|
||||
end
|
||||
|
||||
local select_stmt = assert( db:prepare("SELECT * FROM test") )
|
||||
|
||||
local function select()
|
||||
for row in select_stmt:nrows() do
|
||||
print(row.id, row.content)
|
||||
end
|
||||
end
|
||||
|
||||
insert("Hello World")
|
||||
print("First:")
|
||||
select()
|
||||
|
||||
insert("Hello Lua")
|
||||
print("Second:")
|
||||
select()
|
||||
|
||||
insert("Hello Sqlite3")
|
||||
print("Third:")
|
||||
select()
|
20
3rdparty/lsqlite3/examples/tracing.lua
vendored
20
3rdparty/lsqlite3/examples/tracing.lua
vendored
@ -1,20 +0,0 @@
|
||||
|
||||
require("lsqlite3")
|
||||
|
||||
local db = sqlite3.open_memory()
|
||||
|
||||
db:trace( function(ud, sql)
|
||||
print("Sqlite Trace:", sql)
|
||||
end )
|
||||
|
||||
db:exec[[
|
||||
CREATE TABLE test ( id INTEGER PRIMARY KEY, content VARCHAR );
|
||||
|
||||
INSERT INTO test VALUES (NULL, 'Hello World');
|
||||
INSERT INTO test VALUES (NULL, 'Hello Lua');
|
||||
INSERT INTO test VALUES (NULL, 'Hello Sqlite3');
|
||||
]]
|
||||
|
||||
for row in db:rows("SELECT * FROM test") do
|
||||
-- NOP
|
||||
end
|
2157
3rdparty/lsqlite3/lsqlite3.c
vendored
2157
3rdparty/lsqlite3/lsqlite3.c
vendored
File diff suppressed because it is too large
Load Diff
2
3rdparty/lsqlite3/lsqlite3.def
vendored
2
3rdparty/lsqlite3/lsqlite3.def
vendored
@ -1,2 +0,0 @@
|
||||
EXPORTS
|
||||
luaopen_lsqlite3
|
693
3rdparty/lsqlite3/lunit.lua
vendored
693
3rdparty/lsqlite3/lunit.lua
vendored
@ -1,693 +0,0 @@
|
||||
|
||||
--[[--------------------------------------------------------------------------
|
||||
|
||||
This file is part of lunit 0.4pre (alpha).
|
||||
|
||||
For Details about lunit look at: http://www.nessie.de/mroth/lunit/
|
||||
|
||||
Author: Michael Roth <mroth@nessie.de>
|
||||
|
||||
Copyright (c) 2004 Michael Roth <mroth@nessie.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
--]]--------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
-- Intialize package --
|
||||
-----------------------
|
||||
|
||||
local P = { }
|
||||
lunit = P
|
||||
|
||||
-- Import
|
||||
local type = type
|
||||
local print = print
|
||||
local ipairs = ipairs
|
||||
local pairs = pairs
|
||||
local string = string
|
||||
local table = table
|
||||
local pcall = pcall
|
||||
local xpcall = xpcall
|
||||
local traceback = debug.traceback
|
||||
local error = error
|
||||
local setmetatable = setmetatable
|
||||
local rawset = rawset
|
||||
local orig_assert = assert
|
||||
local getfenv = getfenv
|
||||
local setfenv = setfenv
|
||||
local tostring = tostring
|
||||
|
||||
|
||||
-- Start package scope
|
||||
setfenv(1, P)
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------
|
||||
-- Private data and functions --
|
||||
--------------------------------
|
||||
|
||||
local run_testcase
|
||||
local do_assert, check_msg
|
||||
local stats = { }
|
||||
local testcases = { }
|
||||
local stats_inc, tc_mt
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------
|
||||
-- Type check functions --
|
||||
--------------------------
|
||||
|
||||
function is_nil(x)
|
||||
return type(x) == "nil"
|
||||
end
|
||||
|
||||
function is_boolean(x)
|
||||
return type(x) == "boolean"
|
||||
end
|
||||
|
||||
function is_number(x)
|
||||
return type(x) == "number"
|
||||
end
|
||||
|
||||
function is_string(x)
|
||||
return type(x) == "string"
|
||||
end
|
||||
|
||||
function is_table(x)
|
||||
return type(x) == "table"
|
||||
end
|
||||
|
||||
function is_function(x)
|
||||
return type(x) == "function"
|
||||
end
|
||||
|
||||
function is_thread(x)
|
||||
return type(x) == "thread"
|
||||
end
|
||||
|
||||
function is_userdata(x)
|
||||
return type(x) == "userdata"
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------
|
||||
-- Assert functions --
|
||||
----------------------
|
||||
|
||||
function assert(assertion, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert", msg)
|
||||
do_assert(not not assertion, "assertion failed (was: "..tostring(assertion)..")", msg) -- (convert assertion to bool)
|
||||
return assertion
|
||||
end
|
||||
|
||||
|
||||
function assert_fail(msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_fail", msg)
|
||||
do_assert(false, "failure", msg)
|
||||
end
|
||||
|
||||
|
||||
function assert_true(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_true", msg)
|
||||
do_assert(is_boolean(actual), "true expected but was a "..type(actual), msg)
|
||||
do_assert(actual == true, "true expected but was false", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_false(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_false", msg)
|
||||
do_assert(is_boolean(actual), "false expected but was a "..type(actual), msg)
|
||||
do_assert(actual == false, "false expected but was true", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_equal(expected, actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_equal", msg)
|
||||
do_assert(expected == actual, "expected '"..tostring(expected).."' but was '"..tostring(actual).."'", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_equal(unexpected, actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_equal", msg)
|
||||
do_assert(unexpected ~= actual, "'"..tostring(expected).."' not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_match(pattern, actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_match", msg)
|
||||
do_assert(is_string(pattern), "assert_match expects the pattern as a string")
|
||||
do_assert(is_string(actual), "expected a string to match pattern '"..pattern.."' but was a '"..type(actual).."'", msg)
|
||||
do_assert(not not string.find(actual, pattern), "expected '"..actual.."' to match pattern '"..pattern.."' but doesn't", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_match(pattern, actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_match", msg)
|
||||
do_assert(is_string(actual), "expected a string to not match pattern '"..pattern.."' but was a '"..type(actual).."'", msg)
|
||||
do_assert(string.find(actual, pattern) == nil, "expected '"..actual.."' to not match pattern '"..pattern.."' but it does", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_nil(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_nil", msg)
|
||||
do_assert(is_nil(actual), "nil expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_nil(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_nil", msg)
|
||||
do_assert(not is_nil(actual), "nil not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_boolean(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_boolean", msg)
|
||||
do_assert(is_boolean(actual), "boolean expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_boolean(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_boolean", msg)
|
||||
do_assert(not is_boolean(actual), "boolean not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_number(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_number", msg)
|
||||
do_assert(is_number(actual), "number expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_number(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_number", msg)
|
||||
do_assert(not is_number(actual), "number not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_string(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_string", msg)
|
||||
do_assert(is_string(actual), "string expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_string(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_string", msg)
|
||||
do_assert(not is_string(actual), "string not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_table(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_table", msg)
|
||||
do_assert(is_table(actual), "table expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_table(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_table", msg)
|
||||
do_assert(not is_table(actual), "table not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_function(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_function", msg)
|
||||
do_assert(is_function(actual), "function expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_function(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_function", msg)
|
||||
do_assert(not is_function(actual), "function not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_thread(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_thread", msg)
|
||||
do_assert(is_thread(actual), "thread expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_thread(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_thread", msg)
|
||||
do_assert(not is_thread(actual), "thread not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_userdata(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_userdata", msg)
|
||||
do_assert(is_userdata(actual), "userdata expected but was a "..type(actual), msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_not_userdata(actual, msg)
|
||||
stats_inc("assertions")
|
||||
check_msg("assert_not_userdata", msg)
|
||||
do_assert(not is_userdata(actual), "userdata not expected but was one", msg)
|
||||
return actual
|
||||
end
|
||||
|
||||
|
||||
function assert_error(msg, func)
|
||||
stats_inc("assertions")
|
||||
if is_nil(func) then func, msg = msg, nil end
|
||||
check_msg("assert_error", msg)
|
||||
do_assert(is_function(func), "assert_error expects a function as the last argument but it was a "..type(func))
|
||||
local ok, errmsg = pcall(func)
|
||||
do_assert(ok == false, "error expected but no error occurred", msg)
|
||||
end
|
||||
|
||||
|
||||
function assert_pass(msg, func)
|
||||
stats_inc("assertions")
|
||||
if is_nil(func) then func, msg = msg, nil end
|
||||
check_msg("assert_pass", msg)
|
||||
do_assert(is_function(func), "assert_pass expects a function as the last argument but it was a "..type(func))
|
||||
local ok, errmsg = pcall(func)
|
||||
if not ok then do_assert(ok == true, "no error expected but error was: "..errmsg, msg) end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
-- Assert implementation that assumes it was called from --
|
||||
-- lunit code which was called directly from user code. --
|
||||
-----------------------------------------------------------
|
||||
|
||||
function do_assert(assertion, base_msg, user_msg)
|
||||
orig_assert(is_boolean(assertion))
|
||||
orig_assert(is_string(base_msg))
|
||||
orig_assert(is_string(user_msg) or is_nil(user_msg))
|
||||
if not assertion then
|
||||
if user_msg then
|
||||
error(base_msg..": "..user_msg, 3)
|
||||
else
|
||||
error(base_msg.."!", 3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------
|
||||
-- Checks the msg argument in assert_xxx --
|
||||
-------------------------------------------
|
||||
|
||||
function check_msg(name, msg)
|
||||
orig_assert(is_string(name))
|
||||
if not (is_nil(msg) or is_string(msg)) then
|
||||
error("lunit."..name.."() expects the optional message as a string but it was a "..type(msg).."!" ,3)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-------------------------------------
|
||||
-- Creates a new TestCase 'Object' --
|
||||
-------------------------------------
|
||||
|
||||
function TestCase(name)
|
||||
do_assert(is_string(name), "lunit.TestCase() needs a string as an argument")
|
||||
local tc = {
|
||||
__lunit_name = name;
|
||||
__lunit_setup = nil;
|
||||
__lunit_tests = { };
|
||||
__lunit_teardown = nil;
|
||||
}
|
||||
setmetatable(tc, tc_mt)
|
||||
table.insert(testcases, tc)
|
||||
return tc
|
||||
end
|
||||
|
||||
tc_mt = {
|
||||
__newindex = function(tc, key, value)
|
||||
rawset(tc, key, value)
|
||||
if is_string(key) and is_function(value) then
|
||||
local name = string.lower(key)
|
||||
if string.find(name, "^test") or string.find(name, "test$") then
|
||||
table.insert(tc.__lunit_tests, key)
|
||||
elseif name == "setup" then
|
||||
tc.__lunit_setup = value
|
||||
elseif name == "teardown" then
|
||||
tc.__lunit_teardown = value
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
|
||||
-----------------------------------------
|
||||
-- Wrap Functions in a TestCase object --
|
||||
-----------------------------------------
|
||||
|
||||
function wrap(name, ...)
|
||||
if is_function(name) then
|
||||
table.insert({...}, 1, name)
|
||||
name = "Anonymous Testcase"
|
||||
end
|
||||
|
||||
local tc = TestCase(name)
|
||||
for index, test in ipairs({...}) do
|
||||
tc["Test #"..index] = test
|
||||
end
|
||||
return tc
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
----------------------------------
|
||||
-- Runs the complete Test Suite --
|
||||
----------------------------------
|
||||
|
||||
function run()
|
||||
|
||||
---------------------------
|
||||
-- Initialize statistics --
|
||||
---------------------------
|
||||
|
||||
stats.testcases = 0 -- Total number of Test Cases
|
||||
stats.tests = 0 -- Total number of all Tests in all Test Cases
|
||||
stats.run = 0 -- Number of Tests run
|
||||
stats.notrun = 0 -- Number of Tests not run
|
||||
stats.failed = 0 -- Number of Tests failed
|
||||
stats.warnings = 0 -- Number of Warnings (teardown)
|
||||
stats.errors = 0 -- Number of Errors (setup)
|
||||
stats.passed = 0 -- Number of Test passed
|
||||
stats.assertions = 0 -- Number of all assertions made in all Test in all Test Cases
|
||||
|
||||
--------------------------------
|
||||
-- Count Test Cases and Tests --
|
||||
--------------------------------
|
||||
|
||||
stats.testcases = table.getn(testcases)
|
||||
|
||||
for _, tc in ipairs(testcases) do
|
||||
stats_inc("tests" , table.getn(tc.__lunit_tests))
|
||||
end
|
||||
|
||||
------------------
|
||||
-- Print Header --
|
||||
------------------
|
||||
|
||||
print()
|
||||
print("#### Test Suite with "..stats.tests.." Tests in "..stats.testcases.." Test Cases loaded.")
|
||||
|
||||
------------------------
|
||||
-- Run all Test Cases --
|
||||
------------------------
|
||||
|
||||
for _, tc in ipairs(testcases) do
|
||||
run_testcase(tc)
|
||||
end
|
||||
|
||||
------------------
|
||||
-- Print Footer --
|
||||
------------------
|
||||
|
||||
print()
|
||||
print("#### Test Suite finished.")
|
||||
|
||||
local msg_assertions = stats.assertions.." Assertions checked. "
|
||||
local msg_passed = stats.passed == stats.tests and "All Tests passed" or stats.passed.." Tests passed"
|
||||
local msg_failed = stats.failed > 0 and ", "..stats.failed.." failed" or ""
|
||||
local msg_run = stats.notrun > 0 and ", "..stats.notrun.." not run" or ""
|
||||
local msg_warn = stats.warnings > 0 and ", "..stats.warnings.." warnings" or ""
|
||||
|
||||
print()
|
||||
print(msg_assertions..msg_passed..msg_failed..msg_run..msg_warn.."!")
|
||||
|
||||
-----------------
|
||||
-- Return code --
|
||||
-----------------
|
||||
|
||||
if stats.passed == stats.tests then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------------
|
||||
-- Runs a single Test Case --
|
||||
-----------------------------
|
||||
|
||||
function run_testcase(tc)
|
||||
|
||||
orig_assert(is_table(tc))
|
||||
orig_assert(is_table(tc.__lunit_tests))
|
||||
orig_assert(is_string(tc.__lunit_name))
|
||||
orig_assert(is_nil(tc.__lunit_setup) or is_function(tc.__lunit_setup))
|
||||
orig_assert(is_nil(tc.__lunit_teardown) or is_function(tc.__lunit_teardown))
|
||||
|
||||
----------------------------------
|
||||
-- Protected call to a function --
|
||||
----------------------------------
|
||||
|
||||
local function call(errprefix, func)
|
||||
orig_assert(is_string(errprefix))
|
||||
orig_assert(is_function(func))
|
||||
local ok, errmsg = xpcall(function() func(tc) end, traceback)
|
||||
if not ok then
|
||||
print()
|
||||
print(errprefix..": "..errmsg)
|
||||
end
|
||||
return ok
|
||||
end
|
||||
|
||||
------------------------------------
|
||||
-- Calls setup() on the Test Case --
|
||||
------------------------------------
|
||||
|
||||
local function setup(testname)
|
||||
if tc.__lunit_setup then
|
||||
return call("ERROR: "..testname..": setup() failed", tc.__lunit_setup)
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------------
|
||||
-- Calls a single Test on the Test Case --
|
||||
------------------------------------------
|
||||
|
||||
local function run(testname)
|
||||
orig_assert(is_string(testname))
|
||||
orig_assert(is_function(tc[testname]))
|
||||
local ok = call("FAIL: "..testname, tc[testname])
|
||||
if not ok then
|
||||
stats_inc("failed")
|
||||
else
|
||||
stats_inc("passed")
|
||||
end
|
||||
return ok
|
||||
end
|
||||
|
||||
---------------------------------------
|
||||
-- Calls teardown() on the Test Case --
|
||||
---------------------------------------
|
||||
|
||||
local function teardown(testname)
|
||||
if tc.__lunit_teardown then
|
||||
if not call("WARNING: "..testname..": teardown() failed", tc.__lunit_teardown) then
|
||||
stats_inc("warnings")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------
|
||||
-- Run all Tests on a TestCase --
|
||||
---------------------------------
|
||||
|
||||
print()
|
||||
print("#### Running '"..tc.__lunit_name.."' ("..table.getn(tc.__lunit_tests).." Tests)...")
|
||||
|
||||
for _, testname in ipairs(tc.__lunit_tests) do
|
||||
if setup(testname) then
|
||||
run(testname)
|
||||
stats_inc("run")
|
||||
teardown(testname)
|
||||
else
|
||||
print("WARN: Skipping '"..testname.."'...")
|
||||
stats_inc("notrun")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
---------------------
|
||||
-- Import function --
|
||||
---------------------
|
||||
|
||||
function import(name)
|
||||
|
||||
do_assert(is_string(name), "lunit.import() expects a single string as argument")
|
||||
|
||||
local user_env = getfenv(2)
|
||||
|
||||
--------------------------------------------------
|
||||
-- Installs a specific function in the user env --
|
||||
--------------------------------------------------
|
||||
|
||||
local function install(funcname)
|
||||
user_env[funcname] = P[funcname]
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------------------------
|
||||
-- Install functions matching a pattern in the user env --
|
||||
----------------------------------------------------------
|
||||
|
||||
local function install_pattern(pattern)
|
||||
for funcname, _ in pairs(P) do
|
||||
if string.find(funcname, pattern) then
|
||||
install(funcname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------------------------------
|
||||
-- Installs assert() and all assert_xxx() in the user env --
|
||||
------------------------------------------------------------
|
||||
|
||||
local function install_asserts()
|
||||
install_pattern("^assert.*")
|
||||
end
|
||||
|
||||
-------------------------------------------
|
||||
-- Installs all is_xxx() in the user env --
|
||||
-------------------------------------------
|
||||
|
||||
local function install_tests()
|
||||
install_pattern("^is_.+")
|
||||
end
|
||||
|
||||
if name == "asserts" or name == "assertions" then
|
||||
install_asserts()
|
||||
elseif name == "tests" or name == "checks" then
|
||||
install_tests()
|
||||
elseif name == "all" then
|
||||
install_asserts()
|
||||
install_tests()
|
||||
install("TestCase")
|
||||
elseif string.find(name, "^assert.*") and P[name] then
|
||||
install(name)
|
||||
elseif string.find(name, "^is_.+") and P[name] then
|
||||
install(name)
|
||||
elseif name == "TestCase" then
|
||||
install("TestCase")
|
||||
else
|
||||
error("luniit.import(): invalid function '"..name.."' to import", 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
-- Installs a private environment on the caller --
|
||||
--------------------------------------------------
|
||||
|
||||
function setprivfenv()
|
||||
local new_env = { }
|
||||
local new_env_mt = { __index = getfenv(2) }
|
||||
setmetatable(new_env, new_env_mt)
|
||||
setfenv(2, new_env)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
-- Increments a counter in the statistics table --
|
||||
--------------------------------------------------
|
||||
|
||||
function stats_inc(varname, value)
|
||||
orig_assert(is_table(stats))
|
||||
orig_assert(is_string(varname))
|
||||
orig_assert(is_nil(value) or is_number(value))
|
||||
if not stats[varname] then return end
|
||||
stats[varname] = stats[varname] + (value or 1)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
153
3rdparty/lsqlite3/test.lua
vendored
153
3rdparty/lsqlite3/test.lua
vendored
@ -1,153 +0,0 @@
|
||||
require("lsqlite3")
|
||||
|
||||
local width = 78
|
||||
local function line(pref, suff)
|
||||
pref = pref or ''
|
||||
suff = suff or ''
|
||||
local len = width - 2 - string.len(pref) - string.len(suff)
|
||||
print(pref .. string.rep('-', len) .. suff)
|
||||
end
|
||||
|
||||
local db, vm
|
||||
local assert_, assert = assert, function (test)
|
||||
if (not test) then
|
||||
error(db:errmsg(), 2)
|
||||
end
|
||||
end
|
||||
|
||||
line(sqlite3.version())
|
||||
|
||||
os.remove('test.db')
|
||||
db = sqlite3.open('test.db')
|
||||
|
||||
line(nil, 'db:exec')
|
||||
db:exec('CREATE TABLE t(a, b)')
|
||||
|
||||
line(nil, 'prepare')
|
||||
vm = db:prepare('insert into t values(?, :bork)')
|
||||
assert(vm, db:errmsg())
|
||||
assert(vm:bind_parameter_count() == 2)
|
||||
assert(vm:bind_values(2, 4) == sqlite3.OK)
|
||||
assert(vm:step() == sqlite3.DONE)
|
||||
assert(vm:reset() == sqlite3.OK)
|
||||
assert(vm:bind_names{ 'pork', bork = 'nono' } == sqlite3.OK)
|
||||
assert(vm:step() == sqlite3.DONE)
|
||||
assert(vm:reset() == sqlite3.OK)
|
||||
assert(vm:bind_names{ bork = 'sisi' } == sqlite3.OK)
|
||||
assert(vm:step() == sqlite3.DONE)
|
||||
assert(vm:reset() == sqlite3.OK)
|
||||
assert(vm:bind_names{ 1 } == sqlite3.OK)
|
||||
assert(vm:step() == sqlite3.DONE)
|
||||
assert(vm:finalize() == sqlite3.OK)
|
||||
|
||||
line("select * from t", 'db:exec')
|
||||
|
||||
assert(db:exec('select * from t', function (ud, ncols, values, names)
|
||||
--table.setn(values, 2)
|
||||
print(unpack(values))
|
||||
return sqlite3.OK
|
||||
end) == sqlite3.OK)
|
||||
|
||||
line("select * from t", 'db:prepare')
|
||||
|
||||
vm = db:prepare('select * from t')
|
||||
assert(vm, db:errmsg())
|
||||
print(vm:get_unames())
|
||||
while (vm:step() == sqlite3.ROW) do
|
||||
print(vm:get_uvalues())
|
||||
end
|
||||
assert(vm:finalize() == sqlite3.OK)
|
||||
|
||||
|
||||
|
||||
line('udf', 'scalar')
|
||||
|
||||
local function do_query(sql)
|
||||
local r
|
||||
local vm = db:prepare(sql)
|
||||
assert(vm, db:errmsg())
|
||||
print('====================================')
|
||||
print(vm:get_unames())
|
||||
print('------------------------------------')
|
||||
r = vm:step()
|
||||
while (r == sqlite3.ROW) do
|
||||
print(vm:get_uvalues())
|
||||
r = vm:step()
|
||||
end
|
||||
assert(r == sqlite3.DONE)
|
||||
assert(vm:finalize() == sqlite3.OK)
|
||||
print('====================================')
|
||||
end
|
||||
|
||||
local function udf1_scalar(ctx, v)
|
||||
local ud = ctx:user_data()
|
||||
ud.r = (ud.r or '') .. tostring(v)
|
||||
ctx:result_text(ud.r)
|
||||
end
|
||||
|
||||
db:create_function('udf1', 1, udf1_scalar, { })
|
||||
do_query('select udf1(a) from t')
|
||||
|
||||
|
||||
line('udf', 'aggregate')
|
||||
|
||||
local function udf2_aggregate(ctx, ...)
|
||||
local ud = ctx:get_aggregate_data()
|
||||
if (not ud) then
|
||||
ud = {}
|
||||
ctx:set_aggregate_data(ud)
|
||||
end
|
||||
ud.r = (ud.r or 0) + 2
|
||||
end
|
||||
|
||||
local function udf2_aggregate_finalize(ctx, v)
|
||||
local ud = ctx:get_aggregate_data()
|
||||
ctx:result_number(ud and ud.r or 0)
|
||||
end
|
||||
|
||||
db:create_aggregate('udf2', 1, udf2_aggregate, udf2_aggregate_finalize, { })
|
||||
do_query('select udf2(a) from t')
|
||||
|
||||
if (true) then
|
||||
line(nil, '100 insert exec')
|
||||
db:exec('delete from t')
|
||||
local t = os.time()
|
||||
for i = 1, 100 do
|
||||
db:exec('insert into t values('..i..', '..(i * 2 * -1^i)..')')
|
||||
end
|
||||
print('elapsed: '..(os.time() - t))
|
||||
do_query('select count(*) from t')
|
||||
|
||||
line(nil, '100000 insert exec T')
|
||||
db:exec('delete from t')
|
||||
local t = os.time()
|
||||
db:exec('begin')
|
||||
for i = 1, 100000 do
|
||||
db:exec('insert into t values('..i..', '..(i * 2 * -1^i)..')')
|
||||
end
|
||||
db:exec('commit')
|
||||
print('elapsed: '..(os.time() - t))
|
||||
do_query('select count(*) from t')
|
||||
|
||||
line(nil, '100000 insert prepare/bind T')
|
||||
db:exec('delete from t')
|
||||
local t = os.time()
|
||||
local vm = db:prepare('insert into t values(?, ?)')
|
||||
db:exec('begin')
|
||||
for i = 1, 100000 do
|
||||
vm:bind_values(i, i * 2 * -1^i)
|
||||
vm:step()
|
||||
vm:reset()
|
||||
end
|
||||
vm:finalize()
|
||||
db:exec('commit')
|
||||
print('elapsed: '..(os.time() - t))
|
||||
do_query('select count(*) from t')
|
||||
|
||||
end
|
||||
|
||||
line(nil, "db:close")
|
||||
|
||||
assert(db:close() == sqlite3.OK)
|
||||
|
||||
line(sqlite3.version())
|
587
3rdparty/lsqlite3/tests-sqlite3.lua
vendored
587
3rdparty/lsqlite3/tests-sqlite3.lua
vendored
@ -1,587 +0,0 @@
|
||||
|
||||
--[[--------------------------------------------------------------------------
|
||||
|
||||
Author: Michael Roth <mroth@nessie.de>
|
||||
|
||||
Copyright (c) 2004, 2005 Michael Roth <mroth@nessie.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
--]]--------------------------------------------------------------------------
|
||||
|
||||
|
||||
require "lsqlite3"
|
||||
|
||||
require "lunit"
|
||||
|
||||
lunit.setprivfenv()
|
||||
lunit.import "assertions"
|
||||
lunit.import "checks"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-------------------------------
|
||||
-- Basic open and close test --
|
||||
-------------------------------
|
||||
|
||||
lunit.wrap("open_memory", function()
|
||||
local db = assert_userdata( sqlite3.open_memory() )
|
||||
assert( db:close() )
|
||||
end)
|
||||
|
||||
lunit.wrap("open", function()
|
||||
local filename = "/tmp/__lua-sqlite3-20040906135849." .. os.time()
|
||||
local db = assert_userdata( sqlite3.open(filename) )
|
||||
assert( db:close() )
|
||||
os.remove(filename)
|
||||
end)
|
||||
|
||||
|
||||
|
||||
-------------------------------------
|
||||
-- Presence of db member functions --
|
||||
-------------------------------------
|
||||
|
||||
local db_funcs = lunit.TestCase("Database Member Functions")
|
||||
|
||||
function db_funcs:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
end
|
||||
|
||||
function db_funcs:teardown()
|
||||
assert( self.db:close() )
|
||||
end
|
||||
|
||||
function db_funcs:test()
|
||||
local db = self.db
|
||||
assert_function( db.close )
|
||||
assert_function( db.exec )
|
||||
--e assert_function( db.irows )
|
||||
assert_function( db.rows )
|
||||
--e assert_function( db.cols )
|
||||
--e assert_function( db.first_irow )
|
||||
--e assert_function( db.first_row )
|
||||
--e assert_function( db.first_cols )
|
||||
assert_function( db.prepare )
|
||||
assert_function( db.interrupt )
|
||||
assert_function( db.last_insert_rowid )
|
||||
assert_function( db.changes )
|
||||
assert_function( db.total_changes )
|
||||
end
|
||||
|
||||
|
||||
|
||||
---------------------------------------
|
||||
-- Presence of stmt member functions --
|
||||
---------------------------------------
|
||||
|
||||
local stmt_funcs = lunit.TestCase("Statement Member Functions")
|
||||
|
||||
function stmt_funcs:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
self.stmt = assert( self.db:prepare("CREATE TABLE test (id, content)") )
|
||||
end
|
||||
|
||||
function stmt_funcs:teardown()
|
||||
--e- assert( self.stmt:close() )
|
||||
assert( self.stmt:finalize() ) --e+
|
||||
assert( self.db:close() )
|
||||
end
|
||||
|
||||
function stmt_funcs:test()
|
||||
local stmt = self.stmt
|
||||
--e assert_function( stmt.close )
|
||||
assert_function( stmt.reset )
|
||||
--e assert_function( stmt.exec )
|
||||
assert_function( stmt.bind )
|
||||
--e assert_function( stmt.irows )
|
||||
--e assert_function( stmt.rows )
|
||||
--e assert_function( stmt.cols )
|
||||
--e assert_function( stmt.first_irow )
|
||||
--e assert_function( stmt.first_row )
|
||||
--e assert_function( stmt.first_cols )
|
||||
--e assert_function( stmt.column_names )
|
||||
--e assert_function( stmt.column_decltypes )
|
||||
--e assert_function( stmt.column_count )
|
||||
--e +
|
||||
assert_function( stmt.isopen )
|
||||
assert_function( stmt.step )
|
||||
assert_function( stmt.reset )
|
||||
assert_function( stmt.finalize )
|
||||
assert_function( stmt.columns )
|
||||
assert_function( stmt.bind )
|
||||
assert_function( stmt.bind_values )
|
||||
assert_function( stmt.bind_names )
|
||||
assert_function( stmt.bind_blob )
|
||||
assert_function( stmt.bind_parameter_count )
|
||||
assert_function( stmt.bind_parameter_name )
|
||||
assert_function( stmt.get_value )
|
||||
assert_function( stmt.get_values )
|
||||
assert_function( stmt.get_name )
|
||||
assert_function( stmt.get_names )
|
||||
assert_function( stmt.get_type )
|
||||
assert_function( stmt.get_types )
|
||||
assert_function( stmt.get_uvalues )
|
||||
assert_function( stmt.get_unames )
|
||||
assert_function( stmt.get_utypes )
|
||||
assert_function( stmt.get_named_values )
|
||||
assert_function( stmt.get_named_types )
|
||||
assert_function( stmt.idata )
|
||||
assert_function( stmt.inames )
|
||||
assert_function( stmt.itypes )
|
||||
assert_function( stmt.data )
|
||||
assert_function( stmt.type )
|
||||
--e +
|
||||
end
|
||||
|
||||
|
||||
|
||||
------------------
|
||||
-- Tests basics --
|
||||
------------------
|
||||
|
||||
local basics = lunit.TestCase("Basics")
|
||||
|
||||
function basics:setup()
|
||||
self.db = assert_userdata( sqlite3.open_memory() )
|
||||
end
|
||||
|
||||
function basics:teardown()
|
||||
assert_number( self.db:close() )
|
||||
end
|
||||
|
||||
function basics:create_table()
|
||||
assert_number( self.db:exec("CREATE TABLE test (id, name)") )
|
||||
end
|
||||
|
||||
function basics:drop_table()
|
||||
assert_number( self.db:exec("DROP TABLE test") )
|
||||
end
|
||||
|
||||
function basics:insert(id, name)
|
||||
assert_number( self.db:exec("INSERT INTO test VALUES ("..id..", '"..name.."')") )
|
||||
end
|
||||
|
||||
function basics:update(id, name)
|
||||
assert_number( self.db:exec("UPDATE test SET name = '"..name.."' WHERE id = "..id) )
|
||||
end
|
||||
|
||||
function basics:test_create_drop()
|
||||
self:create_table()
|
||||
self:drop_table()
|
||||
end
|
||||
|
||||
function basics:test_multi_create_drop()
|
||||
self:create_table()
|
||||
self:drop_table()
|
||||
self:create_table()
|
||||
self:drop_table()
|
||||
end
|
||||
|
||||
function basics:test_insert()
|
||||
self:create_table()
|
||||
self:insert(1, "Hello World")
|
||||
self:insert(2, "Hello Lua")
|
||||
self:insert(3, "Hello sqlite3")
|
||||
end
|
||||
|
||||
function basics:test_update()
|
||||
self:create_table()
|
||||
self:insert(1, "Hello Home")
|
||||
self:insert(2, "Hello Lua")
|
||||
self:update(1, "Hello World")
|
||||
end
|
||||
|
||||
|
||||
---------------------------------
|
||||
-- Statement Column Info Tests --
|
||||
---------------------------------
|
||||
|
||||
lunit.wrap("Column Info Test", function()
|
||||
local db = assert_userdata( sqlite3.open_memory() )
|
||||
assert_number( db:exec("CREATE TABLE test (id INTEGER, name TEXT)") )
|
||||
local stmt = assert_userdata( db:prepare("SELECT * FROM test") )
|
||||
|
||||
assert_equal(2, stmt:columns(), "Wrong number of columns." )
|
||||
|
||||
local names = assert_table( stmt:get_names() )
|
||||
assert_equal(2, #(names), "Wrong number of names.")
|
||||
assert_equal("id", names[1] )
|
||||
assert_equal("name", names[2] )
|
||||
|
||||
local types = assert_table( stmt:get_types() )
|
||||
assert_equal(2, #(types), "Wrong number of declaration types.")
|
||||
assert_equal("INTEGER", types[1] )
|
||||
assert_equal("TEXT", types[2] )
|
||||
|
||||
assert_equal( sqlite3.OK, stmt:finalize() )
|
||||
assert_equal( sqlite3.OK, db:close() )
|
||||
end)
|
||||
|
||||
|
||||
|
||||
---------------------
|
||||
-- Statement Tests --
|
||||
---------------------
|
||||
|
||||
st = lunit.TestCase("Statement Tests")
|
||||
|
||||
function st:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
assert_equal( sqlite3.OK, self.db:exec("CREATE TABLE test (id, name)") )
|
||||
assert_equal( sqlite3.OK, self.db:exec("INSERT INTO test VALUES (1, 'Hello World')") )
|
||||
assert_equal( sqlite3.OK, self.db:exec("INSERT INTO test VALUES (2, 'Hello Lua')") )
|
||||
assert_equal( sqlite3.OK, self.db:exec("INSERT INTO test VALUES (3, 'Hello sqlite3')") )
|
||||
end
|
||||
|
||||
function st:teardown()
|
||||
assert_equal( sqlite3.OK, self.db:close() )
|
||||
end
|
||||
|
||||
function st:check_content(expected)
|
||||
local stmt = assert( self.db:prepare("SELECT * FROM test ORDER BY id") )
|
||||
local i = 0
|
||||
for row in stmt:rows() do
|
||||
i = i + 1
|
||||
assert( i <= #(expected), "Too many rows." )
|
||||
assert_equal(2, #(row), "Two result column expected.")
|
||||
assert_equal(i, row[1], "Wrong 'id'.")
|
||||
assert_equal(expected[i], row[2], "Wrong 'name'.")
|
||||
end
|
||||
assert_equal( #(expected), i, "Too few rows." )
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
function st:test_setup()
|
||||
assert_pass(function() self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3" } end)
|
||||
assert_error(function() self:check_content{ "Hello World", "Hello Lua" } end)
|
||||
assert_error(function() self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "To much" } end)
|
||||
assert_error(function() self:check_content{ "Hello World", "Hello Lua", "Wrong" } end)
|
||||
assert_error(function() self:check_content{ "Hello World", "Wrong", "Hello sqlite3" } end)
|
||||
assert_error(function() self:check_content{ "Wrong", "Hello Lua", "Hello sqlite3" } end)
|
||||
end
|
||||
|
||||
function st:test_questionmark_args()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (?, ?)") )
|
||||
assert_number( stmt:bind_values(0, "Test") )
|
||||
assert_error(function() stmt:bind_values("To few") end)
|
||||
assert_error(function() stmt:bind_values(0, "Test", "To many") end)
|
||||
end
|
||||
|
||||
function st:test_questionmark()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (?, ?)") )
|
||||
assert_number( stmt:bind_values(4, "Good morning") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_number( stmt:bind_values(5, "Foo Bar") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function st:test_questionmark_multi()
|
||||
local stmt = assert_userdata( self.db:prepare([[
|
||||
INSERT INTO test VALUES (?, ?); INSERT INTO test VALUES (?, ?) ]]))
|
||||
assert( stmt:bind_values(5, "Foo Bar", 4, "Good morning") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
]===]
|
||||
|
||||
function st:test_identifiers()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (:id, :name)") )
|
||||
assert_number( stmt:bind_values(4, "Good morning") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_number( stmt:bind_values(5, "Foo Bar") )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function st:test_identifiers_multi()
|
||||
local stmt = assert_table( self.db:prepare([[
|
||||
INSERT INTO test VALUES (:id1, :name1); INSERT INTO test VALUES (:id2, :name2) ]]))
|
||||
assert( stmt:bind_values(5, "Foo Bar", 4, "Good morning") )
|
||||
assert( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
end
|
||||
]===]
|
||||
|
||||
function st:test_identifiers_names()
|
||||
--local stmt = assert_userdata( self.db:prepare({"name", "id"}, "INSERT INTO test VALUES (:id, $name)") )
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (:id, $name)") )
|
||||
assert_number( stmt:bind_names({name="Good morning", id=4}) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_number( stmt:bind_names({name="Foo Bar", id=5}) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function st:test_identifiers_multi_names()
|
||||
local stmt = assert_table( self.db:prepare( {"name", "id1", "id2"},[[
|
||||
INSERT INTO test VALUES (:id1, $name); INSERT INTO test VALUES ($id2, :name) ]]))
|
||||
assert( stmt:bind_values("Hoho", 4, 5) )
|
||||
assert( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Hoho", "Hoho" }
|
||||
end
|
||||
]===]
|
||||
|
||||
function st:test_colon_identifiers_names()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (:id, :name)") )
|
||||
assert_number( stmt:bind_names({name="Good morning", id=4}) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_number( stmt:bind_names({name="Foo Bar", id=5}) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function st:test_colon_identifiers_multi_names()
|
||||
local stmt = assert_table( self.db:prepare( {":name", ":id1", ":id2"},[[
|
||||
INSERT INTO test VALUES (:id1, $name); INSERT INTO test VALUES ($id2, :name) ]]))
|
||||
assert( stmt:bind_values("Hoho", 4, 5) )
|
||||
assert( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Hoho", "Hoho" }
|
||||
end
|
||||
|
||||
|
||||
function st:test_dollar_identifiers_names()
|
||||
local stmt = assert_table( self.db:prepare({"$name", "$id"}, "INSERT INTO test VALUES (:id, $name)") )
|
||||
assert_table( stmt:bind_values("Good morning", 4) )
|
||||
assert_table( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning" }
|
||||
assert_table( stmt:bind_values("Foo Bar", 5) )
|
||||
assert_table( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Good morning", "Foo Bar" }
|
||||
end
|
||||
|
||||
function st:test_dollar_identifiers_multi_names()
|
||||
local stmt = assert_table( self.db:prepare( {"$name", "$id1", "$id2"},[[
|
||||
INSERT INTO test VALUES (:id1, $name); INSERT INTO test VALUES ($id2, :name) ]]))
|
||||
assert( stmt:bind_values("Hoho", 4, 5) )
|
||||
assert( stmt:exec() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Hoho", "Hoho" }
|
||||
end
|
||||
]===]
|
||||
|
||||
function st:test_bind_by_names()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES (:id, :name)") )
|
||||
local args = { }
|
||||
args.id = 5
|
||||
args.name = "Hello girls"
|
||||
assert( stmt:bind_names(args) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
args.id = 4
|
||||
args.name = "Hello boys"
|
||||
assert( stmt:bind_names(args) )
|
||||
assert_number( stmt:step() )
|
||||
assert_number( stmt:reset() )
|
||||
self:check_content{ "Hello World", "Hello Lua", "Hello sqlite3", "Hello boys", "Hello girls" }
|
||||
assert_number( stmt:finalize() )
|
||||
end
|
||||
|
||||
|
||||
|
||||
--------------------------------
|
||||
-- Tests binding of arguments --
|
||||
--------------------------------
|
||||
|
||||
b = lunit.TestCase("Binding Tests")
|
||||
|
||||
function b:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
assert_number( self.db:exec("CREATE TABLE test (id, name, u, v, w, x, y, z)") )
|
||||
end
|
||||
|
||||
function b:teardown()
|
||||
assert_number( self.db:close() )
|
||||
end
|
||||
|
||||
function b:test_auto_parameter_names()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES(:a, $b, :a2, :b2, $a, :b, $a3, $b3)") )
|
||||
local parameters = assert_number( stmt:bind_parameter_count() )
|
||||
assert_equal( 8, parameters )
|
||||
assert_equal( ":a", stmt:bind_parameter_name(1) )
|
||||
assert_equal( "$b", stmt:bind_parameter_name(2) )
|
||||
assert_equal( ":a2", stmt:bind_parameter_name(3) )
|
||||
assert_equal( ":b2", stmt:bind_parameter_name(4) )
|
||||
assert_equal( "$a", stmt:bind_parameter_name(5) )
|
||||
assert_equal( ":b", stmt:bind_parameter_name(6) )
|
||||
assert_equal( "$a3", stmt:bind_parameter_name(7) )
|
||||
assert_equal( "$b3", stmt:bind_parameter_name(8) )
|
||||
end
|
||||
|
||||
function b:test_auto_parameter_names()
|
||||
local stmt = assert_userdata( self.db:prepare("INSERT INTO test VALUES($a, $b, $a2, $b2, $a, $b, $a3, $b3)") )
|
||||
local parameters = assert_number( stmt:bind_parameter_count() )
|
||||
assert_equal( 6, parameters )
|
||||
assert_equal( "$a", stmt:bind_parameter_name(1) )
|
||||
assert_equal( "$b", stmt:bind_parameter_name(2) )
|
||||
assert_equal( "$a2", stmt:bind_parameter_name(3) )
|
||||
assert_equal( "$b2", stmt:bind_parameter_name(4) )
|
||||
assert_equal( "$a3", stmt:bind_parameter_name(5) )
|
||||
assert_equal( "$b3", stmt:bind_parameter_name(6) )
|
||||
end
|
||||
|
||||
function b:test_no_parameter_names_1()
|
||||
local stmt = assert_userdata( self.db:prepare([[ SELECT * FROM test ]]))
|
||||
local parameters = assert_number( stmt:bind_parameter_count() )
|
||||
assert_equal( 0, (parameters) )
|
||||
end
|
||||
|
||||
function b:test_no_parameter_names_2()
|
||||
local stmt = assert_userdata( self.db:prepare([[ INSERT INTO test VALUES(?, ?, ?, ?, ?, ?, ?, ?) ]]))
|
||||
local parameters = assert_number( stmt:bind_parameter_count() )
|
||||
assert_equal( 8, (parameters) )
|
||||
assert_nil( stmt:bind_parameter_name(1) )
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------
|
||||
-- Tests loop break and statement reusage --
|
||||
--------------------------------------------
|
||||
|
||||
|
||||
|
||||
----------------------------
|
||||
-- Test for bugs reported --
|
||||
----------------------------
|
||||
|
||||
bug = lunit.TestCase("Bug-Report Tests")
|
||||
|
||||
function bug:setup()
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
end
|
||||
|
||||
function bug:teardown()
|
||||
assert_number( self.db:close() )
|
||||
end
|
||||
|
||||
--[===[
|
||||
function bug:test_1()
|
||||
self.db:exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)")
|
||||
|
||||
local query = assert_userdata( self.db:prepare("SELECT id FROM test WHERE value=?") )
|
||||
|
||||
assert_table ( query:bind_values("1") )
|
||||
assert_nil ( query:first_cols() )
|
||||
assert_table ( query:bind_values("2") )
|
||||
assert_nil ( query:first_cols() )
|
||||
end
|
||||
]===]
|
||||
|
||||
function bug:test_nils() -- appeared in lua-5.1 (holes in arrays)
|
||||
local function check(arg1, arg2, arg3, arg4, arg5)
|
||||
assert_equal(1, arg1)
|
||||
assert_equal(2, arg2)
|
||||
assert_nil(arg3)
|
||||
assert_equal(4, arg4)
|
||||
assert_nil(arg5)
|
||||
end
|
||||
|
||||
self.db:create_function("test_nils", 5, function(arg1, arg2, arg3, arg4, arg5)
|
||||
check(arg1, arg2, arg3, arg4, arg5)
|
||||
end, {})
|
||||
|
||||
assert_number( self.db:exec([[ SELECT test_nils(1, 2, NULL, 4, NULL) ]]) )
|
||||
|
||||
for arg1, arg2, arg3, arg4, arg5 in self.db:urows([[ SELECT 1, 2, NULL, 4, NULL ]])
|
||||
do check(arg1, arg2, arg3, arg4, arg5)
|
||||
end
|
||||
|
||||
for row in self.db:rows([[ SELECT 1, 2, NULL, 4, NULL ]])
|
||||
do assert_table( row )
|
||||
check(row[1], row[2], row[3], row[4], row[5])
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------
|
||||
-- Test for collation fun --
|
||||
----------------------------
|
||||
|
||||
colla = lunit.TestCase("Collation Tests")
|
||||
|
||||
function colla:setup()
|
||||
local function collate(s1,s2)
|
||||
-- if p then print("collation callback: ",s1,s2) end
|
||||
s1=s1:lower()
|
||||
s2=s2:lower()
|
||||
if s1==s2 then return 0
|
||||
elseif s1<s2 then return -1
|
||||
else return 1 end
|
||||
end
|
||||
self.db = assert( sqlite3.open_memory() )
|
||||
assert_nil(self.db:create_collation('CINSENS',collate))
|
||||
self.db:exec[[
|
||||
CREATE TABLE test(id INTEGER PRIMARY KEY,content COLLATE CINSENS);
|
||||
INSERT INTO test VALUES(NULL,'hello world');
|
||||
INSERT INTO test VALUES(NULL,'Buenos dias');
|
||||
INSERT INTO test VALUES(NULL,'HELLO WORLD');
|
||||
INSERT INTO test VALUES(NULL,'Guten Tag');
|
||||
INSERT INTO test VALUES(NULL,'HeLlO WoRlD');
|
||||
INSERT INTO test VALUES(NULL,'Bye for now');
|
||||
]]
|
||||
end
|
||||
|
||||
function colla:teardown()
|
||||
assert_number( self.db:close() )
|
||||
end
|
||||
|
||||
function colla:test()
|
||||
--for row in db:nrows('SELECT * FROM test') do
|
||||
-- print(row.id,row.content)
|
||||
--end
|
||||
local n = 0
|
||||
for row in self.db:nrows('SELECT * FROM test WHERE content="hElLo wOrLd"') do
|
||||
-- print(row.id,row.content)
|
||||
assert_equal (row.content:lower(), "hello world")
|
||||
n = n + 1
|
||||
end
|
||||
assert_equal (n, 3)
|
||||
end
|
||||
|
||||
lunit.run()
|
4259
3rdparty/sqlite3/shell.c
vendored
4259
3rdparty/sqlite3/shell.c
vendored
File diff suppressed because it is too large
Load Diff
151716
3rdparty/sqlite3/sqlite3.c
vendored
151716
3rdparty/sqlite3/sqlite3.c
vendored
File diff suppressed because it is too large
Load Diff
7543
3rdparty/sqlite3/sqlite3.h
vendored
7543
3rdparty/sqlite3/sqlite3.h
vendored
File diff suppressed because it is too large
Load Diff
517
3rdparty/sqlite3/sqlite3ext.h
vendored
517
3rdparty/sqlite3/sqlite3ext.h
vendored
@ -1,517 +0,0 @@
|
||||
/*
|
||||
** 2006 June 7
|
||||
**
|
||||
** 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 header file defines the SQLite interface for use by
|
||||
** shared libraries that want to be imported as extensions into
|
||||
** an SQLite instance. Shared libraries that intend to be loaded
|
||||
** as extensions by SQLite should #include this file instead of
|
||||
** sqlite3.h.
|
||||
*/
|
||||
#ifndef _SQLITE3EXT_H_
|
||||
#define _SQLITE3EXT_H_
|
||||
#include "sqlite3.h"
|
||||
|
||||
typedef struct sqlite3_api_routines sqlite3_api_routines;
|
||||
|
||||
/*
|
||||
** The following structure holds pointers to all of the SQLite API
|
||||
** routines.
|
||||
**
|
||||
** WARNING: In order to maintain backwards compatibility, add new
|
||||
** interfaces to the end of this structure only. If you insert new
|
||||
** interfaces in the middle of this structure, then older different
|
||||
** versions of SQLite will not be able to load each other's shared
|
||||
** libraries!
|
||||
*/
|
||||
struct sqlite3_api_routines {
|
||||
void * (*aggregate_context)(sqlite3_context*,int nBytes);
|
||||
int (*aggregate_count)(sqlite3_context*);
|
||||
int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*));
|
||||
int (*bind_double)(sqlite3_stmt*,int,double);
|
||||
int (*bind_int)(sqlite3_stmt*,int,int);
|
||||
int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64);
|
||||
int (*bind_null)(sqlite3_stmt*,int);
|
||||
int (*bind_parameter_count)(sqlite3_stmt*);
|
||||
int (*bind_parameter_index)(sqlite3_stmt*,const char*zName);
|
||||
const char * (*bind_parameter_name)(sqlite3_stmt*,int);
|
||||
int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*));
|
||||
int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*));
|
||||
int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*);
|
||||
int (*busy_handler)(sqlite3*,int(*)(void*,int),void*);
|
||||
int (*busy_timeout)(sqlite3*,int ms);
|
||||
int (*changes)(sqlite3*);
|
||||
int (*close)(sqlite3*);
|
||||
int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
||||
int eTextRep,const char*));
|
||||
int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*,
|
||||
int eTextRep,const void*));
|
||||
const void * (*column_blob)(sqlite3_stmt*,int iCol);
|
||||
int (*column_bytes)(sqlite3_stmt*,int iCol);
|
||||
int (*column_bytes16)(sqlite3_stmt*,int iCol);
|
||||
int (*column_count)(sqlite3_stmt*pStmt);
|
||||
const char * (*column_database_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_database_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_decltype)(sqlite3_stmt*,int i);
|
||||
const void * (*column_decltype16)(sqlite3_stmt*,int);
|
||||
double (*column_double)(sqlite3_stmt*,int iCol);
|
||||
int (*column_int)(sqlite3_stmt*,int iCol);
|
||||
sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol);
|
||||
const char * (*column_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_origin_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_origin_name16)(sqlite3_stmt*,int);
|
||||
const char * (*column_table_name)(sqlite3_stmt*,int);
|
||||
const void * (*column_table_name16)(sqlite3_stmt*,int);
|
||||
const unsigned char * (*column_text)(sqlite3_stmt*,int iCol);
|
||||
const void * (*column_text16)(sqlite3_stmt*,int iCol);
|
||||
int (*column_type)(sqlite3_stmt*,int iCol);
|
||||
sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol);
|
||||
void * (*commit_hook)(sqlite3*,int(*)(void*),void*);
|
||||
int (*complete)(const char*sql);
|
||||
int (*complete16)(const void*sql);
|
||||
int (*create_collation)(sqlite3*,const char*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*));
|
||||
int (*create_collation16)(sqlite3*,const void*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*));
|
||||
int (*create_function)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*));
|
||||
int (*create_function16)(sqlite3*,const void*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*));
|
||||
int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*);
|
||||
int (*data_count)(sqlite3_stmt*pStmt);
|
||||
sqlite3 * (*db_handle)(sqlite3_stmt*);
|
||||
int (*declare_vtab)(sqlite3*,const char*);
|
||||
int (*enable_shared_cache)(int);
|
||||
int (*errcode)(sqlite3*db);
|
||||
const char * (*errmsg)(sqlite3*);
|
||||
const void * (*errmsg16)(sqlite3*);
|
||||
int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**);
|
||||
int (*expired)(sqlite3_stmt*);
|
||||
int (*finalize)(sqlite3_stmt*pStmt);
|
||||
void (*free)(void*);
|
||||
void (*free_table)(char**result);
|
||||
int (*get_autocommit)(sqlite3*);
|
||||
void * (*get_auxdata)(sqlite3_context*,int);
|
||||
int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**);
|
||||
int (*global_recover)(void);
|
||||
void (*interruptx)(sqlite3*);
|
||||
sqlite_int64 (*last_insert_rowid)(sqlite3*);
|
||||
const char * (*libversion)(void);
|
||||
int (*libversion_number)(void);
|
||||
void *(*malloc)(int);
|
||||
char * (*mprintf)(const char*,...);
|
||||
int (*open)(const char*,sqlite3**);
|
||||
int (*open16)(const void*,sqlite3**);
|
||||
int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
|
||||
int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
|
||||
void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
|
||||
void (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
|
||||
void *(*realloc)(void*,int);
|
||||
int (*reset)(sqlite3_stmt*pStmt);
|
||||
void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_double)(sqlite3_context*,double);
|
||||
void (*result_error)(sqlite3_context*,const char*,int);
|
||||
void (*result_error16)(sqlite3_context*,const void*,int);
|
||||
void (*result_int)(sqlite3_context*,int);
|
||||
void (*result_int64)(sqlite3_context*,sqlite_int64);
|
||||
void (*result_null)(sqlite3_context*);
|
||||
void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*));
|
||||
void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*));
|
||||
void (*result_value)(sqlite3_context*,sqlite3_value*);
|
||||
void * (*rollback_hook)(sqlite3*,void(*)(void*),void*);
|
||||
int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*,
|
||||
const char*,const char*),void*);
|
||||
void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*));
|
||||
char * (*snprintf)(int,char*,const char*,...);
|
||||
int (*step)(sqlite3_stmt*);
|
||||
int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*,
|
||||
char const**,char const**,int*,int*,int*);
|
||||
void (*thread_cleanup)(void);
|
||||
int (*total_changes)(sqlite3*);
|
||||
void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*);
|
||||
int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*);
|
||||
void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*,
|
||||
sqlite_int64),void*);
|
||||
void * (*user_data)(sqlite3_context*);
|
||||
const void * (*value_blob)(sqlite3_value*);
|
||||
int (*value_bytes)(sqlite3_value*);
|
||||
int (*value_bytes16)(sqlite3_value*);
|
||||
double (*value_double)(sqlite3_value*);
|
||||
int (*value_int)(sqlite3_value*);
|
||||
sqlite_int64 (*value_int64)(sqlite3_value*);
|
||||
int (*value_numeric_type)(sqlite3_value*);
|
||||
const unsigned char * (*value_text)(sqlite3_value*);
|
||||
const void * (*value_text16)(sqlite3_value*);
|
||||
const void * (*value_text16be)(sqlite3_value*);
|
||||
const void * (*value_text16le)(sqlite3_value*);
|
||||
int (*value_type)(sqlite3_value*);
|
||||
char *(*vmprintf)(const char*,va_list);
|
||||
/* Added ??? */
|
||||
int (*overload_function)(sqlite3*, const char *zFuncName, int nArg);
|
||||
/* Added by 3.3.13 */
|
||||
int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**);
|
||||
int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
|
||||
int (*clear_bindings)(sqlite3_stmt*);
|
||||
/* Added by 3.4.1 */
|
||||
int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*,
|
||||
void (*xDestroy)(void *));
|
||||
/* Added by 3.5.0 */
|
||||
int (*bind_zeroblob)(sqlite3_stmt*,int,int);
|
||||
int (*blob_bytes)(sqlite3_blob*);
|
||||
int (*blob_close)(sqlite3_blob*);
|
||||
int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64,
|
||||
int,sqlite3_blob**);
|
||||
int (*blob_read)(sqlite3_blob*,void*,int,int);
|
||||
int (*blob_write)(sqlite3_blob*,const void*,int,int);
|
||||
int (*create_collation_v2)(sqlite3*,const char*,int,void*,
|
||||
int(*)(void*,int,const void*,int,const void*),
|
||||
void(*)(void*));
|
||||
int (*file_control)(sqlite3*,const char*,int,void*);
|
||||
sqlite3_int64 (*memory_highwater)(int);
|
||||
sqlite3_int64 (*memory_used)(void);
|
||||
sqlite3_mutex *(*mutex_alloc)(int);
|
||||
void (*mutex_enter)(sqlite3_mutex*);
|
||||
void (*mutex_free)(sqlite3_mutex*);
|
||||
void (*mutex_leave)(sqlite3_mutex*);
|
||||
int (*mutex_try)(sqlite3_mutex*);
|
||||
int (*open_v2)(const char*,sqlite3**,int,const char*);
|
||||
int (*release_memory)(int);
|
||||
void (*result_error_nomem)(sqlite3_context*);
|
||||
void (*result_error_toobig)(sqlite3_context*);
|
||||
int (*sleep)(int);
|
||||
void (*soft_heap_limit)(int);
|
||||
sqlite3_vfs *(*vfs_find)(const char*);
|
||||
int (*vfs_register)(sqlite3_vfs*,int);
|
||||
int (*vfs_unregister)(sqlite3_vfs*);
|
||||
int (*xthreadsafe)(void);
|
||||
void (*result_zeroblob)(sqlite3_context*,int);
|
||||
void (*result_error_code)(sqlite3_context*,int);
|
||||
int (*test_control)(int, ...);
|
||||
void (*randomness)(int,void*);
|
||||
sqlite3 *(*context_db_handle)(sqlite3_context*);
|
||||
int (*extended_result_codes)(sqlite3*,int);
|
||||
int (*limit)(sqlite3*,int,int);
|
||||
sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*);
|
||||
const char *(*sql)(sqlite3_stmt*);
|
||||
int (*status)(int,int*,int*,int);
|
||||
int (*backup_finish)(sqlite3_backup*);
|
||||
sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*);
|
||||
int (*backup_pagecount)(sqlite3_backup*);
|
||||
int (*backup_remaining)(sqlite3_backup*);
|
||||
int (*backup_step)(sqlite3_backup*,int);
|
||||
const char *(*compileoption_get)(int);
|
||||
int (*compileoption_used)(const char*);
|
||||
int (*create_function_v2)(sqlite3*,const char*,int,int,void*,
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
|
||||
void (*xFinal)(sqlite3_context*),
|
||||
void(*xDestroy)(void*));
|
||||
int (*db_config)(sqlite3*,int,...);
|
||||
sqlite3_mutex *(*db_mutex)(sqlite3*);
|
||||
int (*db_status)(sqlite3*,int,int*,int*,int);
|
||||
int (*extended_errcode)(sqlite3*);
|
||||
void (*log)(int,const char*,...);
|
||||
sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64);
|
||||
const char *(*sourceid)(void);
|
||||
int (*stmt_status)(sqlite3_stmt*,int,int);
|
||||
int (*strnicmp)(const char*,const char*,int);
|
||||
int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*);
|
||||
int (*wal_autocheckpoint)(sqlite3*,int);
|
||||
int (*wal_checkpoint)(sqlite3*,const char*);
|
||||
void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*);
|
||||
int (*blob_reopen)(sqlite3_blob*,sqlite3_int64);
|
||||
int (*vtab_config)(sqlite3*,int op,...);
|
||||
int (*vtab_on_conflict)(sqlite3*);
|
||||
/* Version 3.7.16 and later */
|
||||
int (*close_v2)(sqlite3*);
|
||||
const char *(*db_filename)(sqlite3*,const char*);
|
||||
int (*db_readonly)(sqlite3*,const char*);
|
||||
int (*db_release_memory)(sqlite3*);
|
||||
const char *(*errstr)(int);
|
||||
int (*stmt_busy)(sqlite3_stmt*);
|
||||
int (*stmt_readonly)(sqlite3_stmt*);
|
||||
int (*stricmp)(const char*,const char*);
|
||||
int (*uri_boolean)(const char*,const char*,int);
|
||||
sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
|
||||
const char *(*uri_parameter)(const char*,const char*);
|
||||
char *(*vsnprintf)(int,char*,const char*,va_list);
|
||||
int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
|
||||
/* Version 3.8.7 and later */
|
||||
int (*auto_extension)(void(*)(void));
|
||||
int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
|
||||
void(*)(void*));
|
||||
int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64,
|
||||
void(*)(void*),unsigned char);
|
||||
int (*cancel_auto_extension)(void(*)(void));
|
||||
int (*load_extension)(sqlite3*,const char*,const char*,char**);
|
||||
void *(*malloc64)(sqlite3_uint64);
|
||||
sqlite3_uint64 (*msize)(void*);
|
||||
void *(*realloc64)(void*,sqlite3_uint64);
|
||||
void (*reset_auto_extension)(void);
|
||||
void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64,
|
||||
void(*)(void*));
|
||||
void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64,
|
||||
void(*)(void*), unsigned char);
|
||||
int (*strglob)(const char*,const char*);
|
||||
};
|
||||
|
||||
/*
|
||||
** The following macros redefine the API routines so that they are
|
||||
** redirected through the global sqlite3_api structure.
|
||||
**
|
||||
** This header file is also used by the loadext.c source file
|
||||
** (part of the main SQLite library - not an extension) so that
|
||||
** it can get access to the sqlite3_api_routines structure
|
||||
** definition. But the main library does not want to redefine
|
||||
** the API. So the redefinition macros are only valid if the
|
||||
** SQLITE_CORE macros is undefined.
|
||||
*/
|
||||
#ifndef SQLITE_CORE
|
||||
#define sqlite3_aggregate_context sqlite3_api->aggregate_context
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_aggregate_count sqlite3_api->aggregate_count
|
||||
#endif
|
||||
#define sqlite3_bind_blob sqlite3_api->bind_blob
|
||||
#define sqlite3_bind_double sqlite3_api->bind_double
|
||||
#define sqlite3_bind_int sqlite3_api->bind_int
|
||||
#define sqlite3_bind_int64 sqlite3_api->bind_int64
|
||||
#define sqlite3_bind_null sqlite3_api->bind_null
|
||||
#define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count
|
||||
#define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index
|
||||
#define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name
|
||||
#define sqlite3_bind_text sqlite3_api->bind_text
|
||||
#define sqlite3_bind_text16 sqlite3_api->bind_text16
|
||||
#define sqlite3_bind_value sqlite3_api->bind_value
|
||||
#define sqlite3_busy_handler sqlite3_api->busy_handler
|
||||
#define sqlite3_busy_timeout sqlite3_api->busy_timeout
|
||||
#define sqlite3_changes sqlite3_api->changes
|
||||
#define sqlite3_close sqlite3_api->close
|
||||
#define sqlite3_collation_needed sqlite3_api->collation_needed
|
||||
#define sqlite3_collation_needed16 sqlite3_api->collation_needed16
|
||||
#define sqlite3_column_blob sqlite3_api->column_blob
|
||||
#define sqlite3_column_bytes sqlite3_api->column_bytes
|
||||
#define sqlite3_column_bytes16 sqlite3_api->column_bytes16
|
||||
#define sqlite3_column_count sqlite3_api->column_count
|
||||
#define sqlite3_column_database_name sqlite3_api->column_database_name
|
||||
#define sqlite3_column_database_name16 sqlite3_api->column_database_name16
|
||||
#define sqlite3_column_decltype sqlite3_api->column_decltype
|
||||
#define sqlite3_column_decltype16 sqlite3_api->column_decltype16
|
||||
#define sqlite3_column_double sqlite3_api->column_double
|
||||
#define sqlite3_column_int sqlite3_api->column_int
|
||||
#define sqlite3_column_int64 sqlite3_api->column_int64
|
||||
#define sqlite3_column_name sqlite3_api->column_name
|
||||
#define sqlite3_column_name16 sqlite3_api->column_name16
|
||||
#define sqlite3_column_origin_name sqlite3_api->column_origin_name
|
||||
#define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16
|
||||
#define sqlite3_column_table_name sqlite3_api->column_table_name
|
||||
#define sqlite3_column_table_name16 sqlite3_api->column_table_name16
|
||||
#define sqlite3_column_text sqlite3_api->column_text
|
||||
#define sqlite3_column_text16 sqlite3_api->column_text16
|
||||
#define sqlite3_column_type sqlite3_api->column_type
|
||||
#define sqlite3_column_value sqlite3_api->column_value
|
||||
#define sqlite3_commit_hook sqlite3_api->commit_hook
|
||||
#define sqlite3_complete sqlite3_api->complete
|
||||
#define sqlite3_complete16 sqlite3_api->complete16
|
||||
#define sqlite3_create_collation sqlite3_api->create_collation
|
||||
#define sqlite3_create_collation16 sqlite3_api->create_collation16
|
||||
#define sqlite3_create_function sqlite3_api->create_function
|
||||
#define sqlite3_create_function16 sqlite3_api->create_function16
|
||||
#define sqlite3_create_module sqlite3_api->create_module
|
||||
#define sqlite3_create_module_v2 sqlite3_api->create_module_v2
|
||||
#define sqlite3_data_count sqlite3_api->data_count
|
||||
#define sqlite3_db_handle sqlite3_api->db_handle
|
||||
#define sqlite3_declare_vtab sqlite3_api->declare_vtab
|
||||
#define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache
|
||||
#define sqlite3_errcode sqlite3_api->errcode
|
||||
#define sqlite3_errmsg sqlite3_api->errmsg
|
||||
#define sqlite3_errmsg16 sqlite3_api->errmsg16
|
||||
#define sqlite3_exec sqlite3_api->exec
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_expired sqlite3_api->expired
|
||||
#endif
|
||||
#define sqlite3_finalize sqlite3_api->finalize
|
||||
#define sqlite3_free sqlite3_api->free
|
||||
#define sqlite3_free_table sqlite3_api->free_table
|
||||
#define sqlite3_get_autocommit sqlite3_api->get_autocommit
|
||||
#define sqlite3_get_auxdata sqlite3_api->get_auxdata
|
||||
#define sqlite3_get_table sqlite3_api->get_table
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_global_recover sqlite3_api->global_recover
|
||||
#endif
|
||||
#define sqlite3_interrupt sqlite3_api->interruptx
|
||||
#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid
|
||||
#define sqlite3_libversion sqlite3_api->libversion
|
||||
#define sqlite3_libversion_number sqlite3_api->libversion_number
|
||||
#define sqlite3_malloc sqlite3_api->malloc
|
||||
#define sqlite3_mprintf sqlite3_api->mprintf
|
||||
#define sqlite3_open sqlite3_api->open
|
||||
#define sqlite3_open16 sqlite3_api->open16
|
||||
#define sqlite3_prepare sqlite3_api->prepare
|
||||
#define sqlite3_prepare16 sqlite3_api->prepare16
|
||||
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
|
||||
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
|
||||
#define sqlite3_profile sqlite3_api->profile
|
||||
#define sqlite3_progress_handler sqlite3_api->progress_handler
|
||||
#define sqlite3_realloc sqlite3_api->realloc
|
||||
#define sqlite3_reset sqlite3_api->reset
|
||||
#define sqlite3_result_blob sqlite3_api->result_blob
|
||||
#define sqlite3_result_double sqlite3_api->result_double
|
||||
#define sqlite3_result_error sqlite3_api->result_error
|
||||
#define sqlite3_result_error16 sqlite3_api->result_error16
|
||||
#define sqlite3_result_int sqlite3_api->result_int
|
||||
#define sqlite3_result_int64 sqlite3_api->result_int64
|
||||
#define sqlite3_result_null sqlite3_api->result_null
|
||||
#define sqlite3_result_text sqlite3_api->result_text
|
||||
#define sqlite3_result_text16 sqlite3_api->result_text16
|
||||
#define sqlite3_result_text16be sqlite3_api->result_text16be
|
||||
#define sqlite3_result_text16le sqlite3_api->result_text16le
|
||||
#define sqlite3_result_value sqlite3_api->result_value
|
||||
#define sqlite3_rollback_hook sqlite3_api->rollback_hook
|
||||
#define sqlite3_set_authorizer sqlite3_api->set_authorizer
|
||||
#define sqlite3_set_auxdata sqlite3_api->set_auxdata
|
||||
#define sqlite3_snprintf sqlite3_api->snprintf
|
||||
#define sqlite3_step sqlite3_api->step
|
||||
#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata
|
||||
#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup
|
||||
#define sqlite3_total_changes sqlite3_api->total_changes
|
||||
#define sqlite3_trace sqlite3_api->trace
|
||||
#ifndef SQLITE_OMIT_DEPRECATED
|
||||
#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings
|
||||
#endif
|
||||
#define sqlite3_update_hook sqlite3_api->update_hook
|
||||
#define sqlite3_user_data sqlite3_api->user_data
|
||||
#define sqlite3_value_blob sqlite3_api->value_blob
|
||||
#define sqlite3_value_bytes sqlite3_api->value_bytes
|
||||
#define sqlite3_value_bytes16 sqlite3_api->value_bytes16
|
||||
#define sqlite3_value_double sqlite3_api->value_double
|
||||
#define sqlite3_value_int sqlite3_api->value_int
|
||||
#define sqlite3_value_int64 sqlite3_api->value_int64
|
||||
#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type
|
||||
#define sqlite3_value_text sqlite3_api->value_text
|
||||
#define sqlite3_value_text16 sqlite3_api->value_text16
|
||||
#define sqlite3_value_text16be sqlite3_api->value_text16be
|
||||
#define sqlite3_value_text16le sqlite3_api->value_text16le
|
||||
#define sqlite3_value_type sqlite3_api->value_type
|
||||
#define sqlite3_vmprintf sqlite3_api->vmprintf
|
||||
#define sqlite3_overload_function sqlite3_api->overload_function
|
||||
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
|
||||
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
|
||||
#define sqlite3_clear_bindings sqlite3_api->clear_bindings
|
||||
#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
|
||||
#define sqlite3_blob_bytes sqlite3_api->blob_bytes
|
||||
#define sqlite3_blob_close sqlite3_api->blob_close
|
||||
#define sqlite3_blob_open sqlite3_api->blob_open
|
||||
#define sqlite3_blob_read sqlite3_api->blob_read
|
||||
#define sqlite3_blob_write sqlite3_api->blob_write
|
||||
#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2
|
||||
#define sqlite3_file_control sqlite3_api->file_control
|
||||
#define sqlite3_memory_highwater sqlite3_api->memory_highwater
|
||||
#define sqlite3_memory_used sqlite3_api->memory_used
|
||||
#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc
|
||||
#define sqlite3_mutex_enter sqlite3_api->mutex_enter
|
||||
#define sqlite3_mutex_free sqlite3_api->mutex_free
|
||||
#define sqlite3_mutex_leave sqlite3_api->mutex_leave
|
||||
#define sqlite3_mutex_try sqlite3_api->mutex_try
|
||||
#define sqlite3_open_v2 sqlite3_api->open_v2
|
||||
#define sqlite3_release_memory sqlite3_api->release_memory
|
||||
#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem
|
||||
#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig
|
||||
#define sqlite3_sleep sqlite3_api->sleep
|
||||
#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit
|
||||
#define sqlite3_vfs_find sqlite3_api->vfs_find
|
||||
#define sqlite3_vfs_register sqlite3_api->vfs_register
|
||||
#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister
|
||||
#define sqlite3_threadsafe sqlite3_api->xthreadsafe
|
||||
#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob
|
||||
#define sqlite3_result_error_code sqlite3_api->result_error_code
|
||||
#define sqlite3_test_control sqlite3_api->test_control
|
||||
#define sqlite3_randomness sqlite3_api->randomness
|
||||
#define sqlite3_context_db_handle sqlite3_api->context_db_handle
|
||||
#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes
|
||||
#define sqlite3_limit sqlite3_api->limit
|
||||
#define sqlite3_next_stmt sqlite3_api->next_stmt
|
||||
#define sqlite3_sql sqlite3_api->sql
|
||||
#define sqlite3_status sqlite3_api->status
|
||||
#define sqlite3_backup_finish sqlite3_api->backup_finish
|
||||
#define sqlite3_backup_init sqlite3_api->backup_init
|
||||
#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount
|
||||
#define sqlite3_backup_remaining sqlite3_api->backup_remaining
|
||||
#define sqlite3_backup_step sqlite3_api->backup_step
|
||||
#define sqlite3_compileoption_get sqlite3_api->compileoption_get
|
||||
#define sqlite3_compileoption_used sqlite3_api->compileoption_used
|
||||
#define sqlite3_create_function_v2 sqlite3_api->create_function_v2
|
||||
#define sqlite3_db_config sqlite3_api->db_config
|
||||
#define sqlite3_db_mutex sqlite3_api->db_mutex
|
||||
#define sqlite3_db_status sqlite3_api->db_status
|
||||
#define sqlite3_extended_errcode sqlite3_api->extended_errcode
|
||||
#define sqlite3_log sqlite3_api->log
|
||||
#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64
|
||||
#define sqlite3_sourceid sqlite3_api->sourceid
|
||||
#define sqlite3_stmt_status sqlite3_api->stmt_status
|
||||
#define sqlite3_strnicmp sqlite3_api->strnicmp
|
||||
#define sqlite3_unlock_notify sqlite3_api->unlock_notify
|
||||
#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint
|
||||
#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint
|
||||
#define sqlite3_wal_hook sqlite3_api->wal_hook
|
||||
#define sqlite3_blob_reopen sqlite3_api->blob_reopen
|
||||
#define sqlite3_vtab_config sqlite3_api->vtab_config
|
||||
#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict
|
||||
/* Version 3.7.16 and later */
|
||||
#define sqlite3_close_v2 sqlite3_api->close_v2
|
||||
#define sqlite3_db_filename sqlite3_api->db_filename
|
||||
#define sqlite3_db_readonly sqlite3_api->db_readonly
|
||||
#define sqlite3_db_release_memory sqlite3_api->db_release_memory
|
||||
#define sqlite3_errstr sqlite3_api->errstr
|
||||
#define sqlite3_stmt_busy sqlite3_api->stmt_busy
|
||||
#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly
|
||||
#define sqlite3_stricmp sqlite3_api->stricmp
|
||||
#define sqlite3_uri_boolean sqlite3_api->uri_boolean
|
||||
#define sqlite3_uri_int64 sqlite3_api->uri_int64
|
||||
#define sqlite3_uri_parameter sqlite3_api->uri_parameter
|
||||
#define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf
|
||||
#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
|
||||
/* Version 3.8.7 and later */
|
||||
#define sqlite3_auto_extension sqlite3_api->auto_extension
|
||||
#define sqlite3_bind_blob64 sqlite3_api->bind_blob64
|
||||
#define sqlite3_bind_text64 sqlite3_api->bind_text64
|
||||
#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension
|
||||
#define sqlite3_load_extension sqlite3_api->load_extension
|
||||
#define sqlite3_malloc64 sqlite3_api->malloc64
|
||||
#define sqlite3_msize sqlite3_api->msize
|
||||
#define sqlite3_realloc64 sqlite3_api->realloc64
|
||||
#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension
|
||||
#define sqlite3_result_blob64 sqlite3_api->result_blob64
|
||||
#define sqlite3_result_text64 sqlite3_api->result_text64
|
||||
#define sqlite3_strglob sqlite3_api->strglob
|
||||
#endif /* SQLITE_CORE */
|
||||
|
||||
#ifndef SQLITE_CORE
|
||||
/* This case when the file really is being compiled as a loadable
|
||||
** extension */
|
||||
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
|
||||
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
|
||||
# define SQLITE_EXTENSION_INIT3 \
|
||||
extern const sqlite3_api_routines *sqlite3_api;
|
||||
#else
|
||||
/* This case when the file is being statically linked into the
|
||||
** application */
|
||||
# define SQLITE_EXTENSION_INIT1 /*no-op*/
|
||||
# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */
|
||||
# define SQLITE_EXTENSION_INIT3 /*no-op*/
|
||||
#endif
|
||||
|
||||
#endif /* _SQLITE3EXT_H_ */
|
5
makefile
5
makefile
@ -58,7 +58,6 @@
|
||||
# USE_SYSTEM_LIB_JPEG = 1
|
||||
# USE_SYSTEM_LIB_FLAC = 1
|
||||
# USE_SYSTEM_LIB_LUA = 1
|
||||
# USE_SYSTEM_LIB_SQLITE3 = 1
|
||||
# USE_SYSTEM_LIB_PORTMIDI = 1
|
||||
# USE_SYSTEM_LIB_PORTAUDIO = 1
|
||||
# USE_SYSTEM_LIB_UV = 1
|
||||
@ -407,10 +406,6 @@ ifdef USE_SYSTEM_LIB_LUA
|
||||
PARAMS += --with-system-lua='$(USE_SYSTEM_LIB_LUA)'
|
||||
endif
|
||||
|
||||
ifdef USE_SYSTEM_LIB_SQLITE3
|
||||
PARAMS += --with-system-sqlite3='$(USE_SYSTEM_LIB_SQLITE3)'
|
||||
endif
|
||||
|
||||
ifdef USE_SYSTEM_LIB_PORTMIDI
|
||||
PARAMS += --with-system-portmidi='$(USE_SYSTEM_LIB_PORTMIDI)'
|
||||
endif
|
||||
|
@ -10,7 +10,6 @@ local extlibs = {
|
||||
zlib = { "z", "3rdparty/zlib" },
|
||||
jpeg = { "jpeg", "3rdparty/libjpeg" },
|
||||
flac = { "FLAC", "3rdparty/libflac/include" },
|
||||
sqlite3 = { "sqlite3", "3rdparty/sqlite3" },
|
||||
portmidi = { "portmidi", "3rdparty/portmidi/pm_common" },
|
||||
portaudio = { "portaudio", "3rdparty/portaudio/include" },
|
||||
lua = { "lua", "3rdparty/lua/src" },
|
||||
@ -38,11 +37,6 @@ newoption {
|
||||
description = 'Use system FLAC library',
|
||||
}
|
||||
|
||||
newoption {
|
||||
trigger = 'with-system-sqlite3',
|
||||
description = 'Use system SQLite library',
|
||||
}
|
||||
|
||||
newoption {
|
||||
trigger = 'with-system-portmidi',
|
||||
description = 'Use system PortMidi library',
|
||||
|
@ -439,7 +439,7 @@ project "lua"
|
||||
|
||||
-- uncomment the options below to
|
||||
-- compile using c++. Do the same
|
||||
-- in lsqlite3.
|
||||
-- in lualibs.
|
||||
-- In addition comment out the "extern "C""
|
||||
-- in lua.hpp and do the same in luaengine.c line 47
|
||||
--options {
|
||||
@ -558,74 +558,13 @@ project "lualibs"
|
||||
includedirs {
|
||||
ext_includedir("lua"),
|
||||
ext_includedir("zlib"),
|
||||
ext_includedir("sqlite3"),
|
||||
}
|
||||
|
||||
files {
|
||||
MAME_DIR .. "3rdparty/lsqlite3/lsqlite3.c",
|
||||
MAME_DIR .. "3rdparty/lua-zlib/lua_zlib.c",
|
||||
MAME_DIR .. "3rdparty/luafilesystem/src/lfs.c",
|
||||
}
|
||||
|
||||
--------------------------------------------------
|
||||
-- SQLite3 library objects
|
||||
--------------------------------------------------
|
||||
|
||||
if not _OPTIONS["with-system-sqlite3"] then
|
||||
project "sqlite3"
|
||||
uuid "5cb3d495-57ed-461c-81e5-80dc0857517d"
|
||||
kind "StaticLib"
|
||||
|
||||
configuration { "vs*" }
|
||||
buildoptions {
|
||||
"/wd4244", -- warning C4244: 'argument' : conversion from 'xxx' to 'xxx', possible loss of data
|
||||
"/wd4127", -- warning C4127: conditional expression is constant
|
||||
"/wd4232", -- warning C4232: nonstandard extension used : 'xxx' : address of dllimport 'xxx' is not static, identity not guaranteed
|
||||
"/wd4100", -- warning C4100: 'xxx' : unreferenced formal parameter
|
||||
"/wd4706", -- warning C4706: assignment within conditional expression
|
||||
}
|
||||
if _OPTIONS["vs"]=="intel-15" then
|
||||
buildoptions {
|
||||
"/Qwd869", -- remark #869: parameter "xxx" was never referenced
|
||||
"/Qwd2557", -- remark #2557: comparison between signed and unsigned operands
|
||||
}
|
||||
end
|
||||
configuration { "pnacl" }
|
||||
defines {
|
||||
"SQLITE_OMIT_LOAD_EXTENSION",
|
||||
}
|
||||
configuration { "vs2015" }
|
||||
buildoptions {
|
||||
"/wd4456", -- warning C4456: declaration of 'xxx' hides previous local declaration
|
||||
}
|
||||
|
||||
|
||||
configuration { "gmake" }
|
||||
buildoptions_c {
|
||||
"-Wno-bad-function-cast",
|
||||
"-Wno-undef",
|
||||
}
|
||||
|
||||
local version = str_to_version(_OPTIONS["gcc_version"])
|
||||
if _OPTIONS["gcc"]~=nil and not string.find(_OPTIONS["gcc"], "clang") then
|
||||
if (version >= 40800) then
|
||||
buildoptions_c {
|
||||
"-Wno-array-bounds",
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
configuration { }
|
||||
|
||||
files {
|
||||
MAME_DIR .. "3rdparty/sqlite3/sqlite3.c",
|
||||
}
|
||||
else
|
||||
links {
|
||||
ext_lib("sqlite3"),
|
||||
}
|
||||
end
|
||||
|
||||
--------------------------------------------------
|
||||
-- portmidi library objects
|
||||
--------------------------------------------------
|
||||
@ -878,155 +817,155 @@ end
|
||||
--------------------------------------------------
|
||||
-- PortAudio library objects
|
||||
--------------------------------------------------
|
||||
|
||||
if not _OPTIONS["with-system-portaudio"] then
|
||||
project "portaudio"
|
||||
uuid "0755c5f5-eccf-47f3-98a9-df67018a94d4"
|
||||
kind "StaticLib"
|
||||
|
||||
configuration { "vs*" }
|
||||
buildoptions {
|
||||
"/wd4245", -- warning C4245: 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
|
||||
"/wd4244", -- warning C4244: 'argument' : conversion from 'xxx' to 'xxx', possible loss of data
|
||||
"/wd4100", -- warning C4100: 'xxx' : unreferenced formal parameter
|
||||
"/wd4389", -- warning C4389: 'operator' : signed/unsigned mismatch
|
||||
"/wd4189", -- warning C4189: 'xxx' : local variable is initialized but not referenced
|
||||
"/wd4127", -- warning C4127: conditional expression is constant
|
||||
}
|
||||
if _OPTIONS["vs"]=="intel-15" then
|
||||
buildoptions {
|
||||
"/Qwd869", -- remark #869: parameter "xxx" was never referenced
|
||||
"/Qwd1478", -- warning #1478: function "xxx" (declared at line yyy of "zzz") was declared deprecated
|
||||
"/Qwd2544", -- message #2544: empty dependent statement in if-statement
|
||||
"/Qwd1879", -- warning #1879: unimplemented pragma ignored
|
||||
}
|
||||
end
|
||||
configuration { "vs2015" }
|
||||
buildoptions {
|
||||
"/wd4456", -- warning C4456: declaration of 'xxx' hides previous local declaration
|
||||
}
|
||||
|
||||
configuration { "gmake" }
|
||||
buildoptions_c {
|
||||
"-Wno-strict-prototypes",
|
||||
"-Wno-bad-function-cast",
|
||||
"-Wno-undef",
|
||||
"-Wno-missing-braces",
|
||||
"-Wno-unused-variable",
|
||||
"-Wno-unused-value",
|
||||
"-Wno-unused-function",
|
||||
"-Wno-unknown-pragmas",
|
||||
}
|
||||
|
||||
local version = str_to_version(_OPTIONS["gcc_version"])
|
||||
if (_OPTIONS["gcc"]~=nil) then
|
||||
if string.find(_OPTIONS["gcc"], "clang") or string.find(_OPTIONS["gcc"], "android") then
|
||||
buildoptions_c {
|
||||
"-Wno-unknown-warning-option",
|
||||
"-Wno-absolute-value",
|
||||
"-Wno-unused-but-set-variable",
|
||||
"-Wno-maybe-uninitialized",
|
||||
"-Wno-sometimes-uninitialized",
|
||||
}
|
||||
else
|
||||
if (version >= 40600) then
|
||||
buildoptions_c {
|
||||
"-Wno-unused-but-set-variable",
|
||||
"-Wno-maybe-uninitialized",
|
||||
"-Wno-sometimes-uninitialized",
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
configuration { "vs*" }
|
||||
buildoptions {
|
||||
"/wd4204", -- warning C4204: nonstandard extension used : non-constant aggregate initializer
|
||||
"/wd4701", -- warning C4701: potentially uninitialized local variable 'xxx' used
|
||||
}
|
||||
|
||||
configuration { }
|
||||
|
||||
includedirs {
|
||||
MAME_DIR .. "3rdparty/portaudio/include",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common",
|
||||
}
|
||||
|
||||
files {
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_allocation.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_converters.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_cpuload.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_dither.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_debugprint.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_front.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_process.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_stream.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_trace.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/skeleton/pa_hostapi_skeleton.c",
|
||||
}
|
||||
|
||||
if _OPTIONS["targetos"]=="windows" then
|
||||
defines {
|
||||
"PA_USE_DS=1",
|
||||
"PA_USE_WDMKS=1",
|
||||
"PA_USE_WMME=1",
|
||||
}
|
||||
includedirs {
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/win",
|
||||
}
|
||||
|
||||
configuration { }
|
||||
files {
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_util.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_waveformat.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_hostapis.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_wdmks_utils.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_coinitialize.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/dsound/pa_win_ds.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/dsound/pa_win_ds_dynlink.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/wdmks/pa_win_wdmks.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_ringbuffer.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c",
|
||||
}
|
||||
|
||||
end
|
||||
if _OPTIONS["targetos"]=="linux" then
|
||||
defines {
|
||||
"PA_USE_ALSA=1",
|
||||
"PA_USE_OSS=1",
|
||||
"HAVE_LINUX_SOUNDCARD_H",
|
||||
}
|
||||
includedirs {
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/unix",
|
||||
}
|
||||
files {
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_util.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/alsa/pa_linux_alsa.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/oss/pa_unix_oss.c",
|
||||
}
|
||||
end
|
||||
if _OPTIONS["targetos"]=="macosx" then
|
||||
defines {
|
||||
"PA_USE_COREAUDIO=1",
|
||||
}
|
||||
includedirs {
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/unix",
|
||||
}
|
||||
files {
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_util.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core_utilities.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core_blocking.c",
|
||||
MAME_DIR .. "3rdparty/portaudio/src/common/pa_ringbuffer.c",
|
||||
}
|
||||
end
|
||||
|
||||
else
|
||||
links {
|
||||
ext_lib("portaudio"),
|
||||
}
|
||||
end
|
||||
--
|
||||
--if not _OPTIONS["with-system-portaudio"] then
|
||||
--project "portaudio"
|
||||
-- uuid "0755c5f5-eccf-47f3-98a9-df67018a94d4"
|
||||
-- kind "StaticLib"
|
||||
--
|
||||
-- configuration { "vs*" }
|
||||
-- buildoptions {
|
||||
-- "/wd4245", -- warning C4245: 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
|
||||
-- "/wd4244", -- warning C4244: 'argument' : conversion from 'xxx' to 'xxx', possible loss of data
|
||||
-- "/wd4100", -- warning C4100: 'xxx' : unreferenced formal parameter
|
||||
-- "/wd4389", -- warning C4389: 'operator' : signed/unsigned mismatch
|
||||
-- "/wd4189", -- warning C4189: 'xxx' : local variable is initialized but not referenced
|
||||
-- "/wd4127", -- warning C4127: conditional expression is constant
|
||||
-- }
|
||||
--if _OPTIONS["vs"]=="intel-15" then
|
||||
-- buildoptions {
|
||||
-- "/Qwd869", -- remark #869: parameter "xxx" was never referenced
|
||||
-- "/Qwd1478", -- warning #1478: function "xxx" (declared at line yyy of "zzz") was declared deprecated
|
||||
-- "/Qwd2544", -- message #2544: empty dependent statement in if-statement
|
||||
-- "/Qwd1879", -- warning #1879: unimplemented pragma ignored
|
||||
-- }
|
||||
--end
|
||||
-- configuration { "vs2015" }
|
||||
-- buildoptions {
|
||||
-- "/wd4456", -- warning C4456: declaration of 'xxx' hides previous local declaration
|
||||
-- }
|
||||
--
|
||||
-- configuration { "gmake" }
|
||||
-- buildoptions_c {
|
||||
-- "-Wno-strict-prototypes",
|
||||
-- "-Wno-bad-function-cast",
|
||||
-- "-Wno-undef",
|
||||
-- "-Wno-missing-braces",
|
||||
-- "-Wno-unused-variable",
|
||||
-- "-Wno-unused-value",
|
||||
-- "-Wno-unused-function",
|
||||
-- "-Wno-unknown-pragmas",
|
||||
-- }
|
||||
--
|
||||
-- local version = str_to_version(_OPTIONS["gcc_version"])
|
||||
-- if (_OPTIONS["gcc"]~=nil) then
|
||||
-- if string.find(_OPTIONS["gcc"], "clang") or string.find(_OPTIONS["gcc"], "android") then
|
||||
-- buildoptions_c {
|
||||
-- "-Wno-unknown-warning-option",
|
||||
-- "-Wno-absolute-value",
|
||||
-- "-Wno-unused-but-set-variable",
|
||||
-- "-Wno-maybe-uninitialized",
|
||||
-- "-Wno-sometimes-uninitialized",
|
||||
-- }
|
||||
-- else
|
||||
-- if (version >= 40600) then
|
||||
-- buildoptions_c {
|
||||
-- "-Wno-unused-but-set-variable",
|
||||
-- "-Wno-maybe-uninitialized",
|
||||
-- "-Wno-sometimes-uninitialized",
|
||||
-- }
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- configuration { "vs*" }
|
||||
-- buildoptions {
|
||||
-- "/wd4204", -- warning C4204: nonstandard extension used : non-constant aggregate initializer
|
||||
-- "/wd4701", -- warning C4701: potentially uninitialized local variable 'xxx' used
|
||||
-- }
|
||||
--
|
||||
-- configuration { }
|
||||
--
|
||||
-- includedirs {
|
||||
-- MAME_DIR .. "3rdparty/portaudio/include",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common",
|
||||
-- }
|
||||
--
|
||||
-- files {
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_allocation.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_converters.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_cpuload.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_dither.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_debugprint.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_front.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_process.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_stream.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_trace.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/skeleton/pa_hostapi_skeleton.c",
|
||||
-- }
|
||||
--
|
||||
-- if _OPTIONS["targetos"]=="windows" then
|
||||
-- defines {
|
||||
-- "PA_USE_DS=1",
|
||||
-- "PA_USE_WDMKS=1",
|
||||
-- "PA_USE_WMME=1",
|
||||
-- }
|
||||
-- includedirs {
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/win",
|
||||
-- }
|
||||
--
|
||||
-- configuration { }
|
||||
-- files {
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_util.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_waveformat.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_hostapis.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_wdmks_utils.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_coinitialize.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/dsound/pa_win_ds.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/dsound/pa_win_ds_dynlink.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/wdmks/pa_win_wdmks.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_ringbuffer.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c",
|
||||
-- }
|
||||
--
|
||||
-- end
|
||||
-- if _OPTIONS["targetos"]=="linux" then
|
||||
-- defines {
|
||||
-- "PA_USE_ALSA=1",
|
||||
-- "PA_USE_OSS=1",
|
||||
-- "HAVE_LINUX_SOUNDCARD_H",
|
||||
-- }
|
||||
-- includedirs {
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/unix",
|
||||
-- }
|
||||
-- files {
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_util.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/alsa/pa_linux_alsa.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/oss/pa_unix_oss.c",
|
||||
-- }
|
||||
-- end
|
||||
-- if _OPTIONS["targetos"]=="macosx" then
|
||||
-- defines {
|
||||
-- "PA_USE_COREAUDIO=1",
|
||||
-- }
|
||||
-- includedirs {
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/unix",
|
||||
-- }
|
||||
-- files {
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_util.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core_utilities.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core_blocking.c",
|
||||
-- MAME_DIR .. "3rdparty/portaudio/src/common/pa_ringbuffer.c",
|
||||
-- }
|
||||
-- end
|
||||
--
|
||||
--else
|
||||
--links {
|
||||
-- ext_lib("portaudio"),
|
||||
--}
|
||||
--end
|
||||
|
||||
--------------------------------------------------
|
||||
-- libuv library objects
|
||||
@ -1232,29 +1171,7 @@ project "uv"
|
||||
}
|
||||
end
|
||||
end
|
||||
--------------------------------------------------
|
||||
-- HTTP parser library objects
|
||||
--------------------------------------------------
|
||||
|
||||
project "http-parser"
|
||||
uuid "90c6ba59-bdb2-4fee-8b44-57601d690e14"
|
||||
kind "StaticLib"
|
||||
|
||||
configuration { }
|
||||
|
||||
files {
|
||||
MAME_DIR .. "3rdparty/http-parser/http_parser.c",
|
||||
}
|
||||
if (_OPTIONS["SHADOW_CHECK"]=="1") then
|
||||
removebuildoptions {
|
||||
"-Wshadow"
|
||||
}
|
||||
end
|
||||
|
||||
else
|
||||
links {
|
||||
ext_lib("uv"),
|
||||
}
|
||||
end
|
||||
--------------------------------------------------
|
||||
-- SDL2 library
|
||||
|
@ -231,13 +231,11 @@ end
|
||||
if _OPTIONS["USE_LIBUV"]=="1" then
|
||||
links {
|
||||
ext_lib("uv"),
|
||||
"http-parser",
|
||||
}
|
||||
end
|
||||
links {
|
||||
ext_lib("zlib"),
|
||||
ext_lib("flac"),
|
||||
ext_lib("sqlite3"),
|
||||
}
|
||||
|
||||
if _OPTIONS["NO_USE_MIDI"]~="1" then
|
||||
|
@ -52,7 +52,6 @@ const char *const lua_engine::tname_ioport = "lua.ioport";
|
||||
lua_engine* lua_engine::luaThis = nullptr;
|
||||
|
||||
extern "C" {
|
||||
int luaopen_lsqlite3(lua_State *L);
|
||||
int luaopen_zlib(lua_State *L);
|
||||
int luaopen_lfs(lua_State *L);
|
||||
}
|
||||
@ -1711,9 +1710,6 @@ lua_engine::lua_engine()
|
||||
lua_pushcfunction(m_lua_state, luaopen_zlib);
|
||||
lua_setfield(m_lua_state, -2, "zlib");
|
||||
|
||||
lua_pushcfunction(m_lua_state, luaopen_lsqlite3);
|
||||
lua_setfield(m_lua_state, -2, "lsqlite3");
|
||||
|
||||
lua_pushcfunction(m_lua_state, luaopen_lfs);
|
||||
lua_setfield(m_lua_state, -2, "lfs");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user