<s>
Gadfly	B-Language
is	O
a	O
relational	B-Application
database	I-Application
management	I-Application
system	I-Application
written	O
in	O
Python	B-Language
.	O
</s>
<s>
Gadfly	B-Language
is	O
a	O
collection	O
of	O
Python	B-Language
modules	O
that	O
provides	O
relational	O
database	O
functionality	O
entirely	O
implemented	O
in	O
Python	B-Language
.	O
</s>
<s>
It	O
supports	O
a	O
subset	O
of	O
the	O
standard	O
RDBMS	O
Structured	B-Language
Query	I-Language
Language	I-Language
(	O
SQL	B-Language
)	O
.	O
</s>
<s>
Gadfly	B-Language
runs	O
wherever	O
Python	B-Language
runs	O
and	O
supports	O
client/server	O
on	O
any	O
platform	O
that	O
supports	O
the	O
standard	O
Python	B-Language
socket	B-Protocol
interface	O
.	O
</s>
<s>
The	O
file	O
formats	O
used	O
by	O
Gadfly	B-Language
for	O
storage	O
are	O
cross-platform	B-Operating_System
—	O
a	O
gadfly	B-Language
database	O
directory	O
can	O
be	O
moved	O
from	O
Windows	B-Application
95	I-Application
to	O
Linux	B-Application
using	O
a	O
binary	O
copying	O
mechanism	O
and	O
gadfly	B-Language
will	O
read	O
and	O
run	O
the	O
database	O
.	O
</s>
<s>
It	O
supports	O
persistent	O
databases	O
consisting	O
of	O
a	O
collection	O
of	O
structured	O
tables	O
with	O
indices	O
,	O
and	O
a	O
large	O
subset	O
of	O
SQL	B-Language
for	O
accessing	O
and	O
modifying	O
those	O
tables	O
.	O
</s>
<s>
It	O
supports	O
a	O
log-based	O
recovery	O
protocol	O
which	O
allows	O
committed	O
operations	O
of	O
a	O
database	O
to	O
be	O
recovered	O
even	O
if	O
the	O
database	O
was	O
not	O
shut	O
down	O
in	O
a	O
proper	O
manner	O
(	O
i.e.	O
,	O
in	O
the	O
event	O
of	O
a	O
CPU	B-General_Concept
or	O
software	O
crash	O
,	O
[	O
but	O
not	O
in	O
the	O
event	O
of	O
a	O
disk	O
crash ]	O
)	O
.	O
</s>
<s>
It	O
also	O
supports	O
a	O
TCP/IP	B-Protocol
Client/Server	O
mode	O
where	O
remote	O
clients	O
can	O
access	O
a	O
Gadfly	B-Language
database	O
over	O
a	O
TCP/IP	B-Protocol
network	I-Protocol
(	O
such	O
as	O
the	O
Internet	O
)	O
subject	O
to	O
configurable	O
security	O
mechanisms	O
.	O
</s>
<s>
Since	O
Gadfly	B-Language
depends	O
intimately	O
on	O
the	O
kwParsing	O
package	O
it	O
is	O
distributed	O
as	O
part	O
of	O
the	O
kwParsing	O
package	O
,	O
under	O
the	O
same	O
copyright	O
.	O
</s>
<s>
Gadfly	B-Language
allows	O
Python	B-Language
programs	I-Language
to	O
store	O
,	O
retrieve	O
and	O
query	O
tabular	O
data	O
without	O
having	O
to	O
rely	O
on	O
any	O
external	O
database	O
engine	O
or	O
package	O
.	O
</s>
<s>
It	O
provides	O
an	O
in-memory	O
relational	O
database	O
style	O
engine	O
for	O
Python	B-Language
programs	I-Language
,	O
complete	O
with	O
a	O
notion	O
of	O
a	O
"	O
committed	O
,	O
recoverable	O
transaction	B-General_Concept
"	O
and	O
"	O
aborts	O
"	O
.	O
</s>
<s>
The	O
main	O
"	O
gadfly	B-Language
"	O
module	O
attempts	O
to	O
faithfully	O
adhere	O
to	O
Greg	O
Stein	O
's	O
Python	B-Language
Database	O
API	B-Application
,	O
as	O
discussed	O
and	O
certified	O
by	O
the	O
Python	B-Language
DB-SIG	O
.	O
</s>
<s>
Multiple	O
processes	O
can	O
access	O
a	O
Gadfly	B-Language
database	O
when	O
accesses	O
are	O
arbitrated	O
by	O
a	O
TCP/IP	B-Protocol
Gadfly	B-Language
server	B-Application
process	O
.	O
</s>
<s>
Unlike	O
most	O
Python/database	O
-engine	O
interfaces	O
Gadfly	B-Language
databases	O
must	O
be	O
created	O
using	O
Python	B-Language
.	O
</s>
<s>
This	O
has	O
the	O
effect	O
of	O
clobbering	B-General_Concept
any	O
existing	O
Gadfly	B-Language
database	O
called	O
"	O
mydatabase	O
"	O
in	O
the	O
directory	O
"	O
mydirectory	O
"	O
.	O
</s>
<s>
Gadfly	B-Language
will	O
not	O
allow	O
a	O
start	O
up	O
the	O
same	O
connection	O
twice	O
,	O
however	O
.	O
</s>
<s>
The	O
first	O
"	O
import	O
gadfly	B-Language
"	O
reads	O
in	O
and	O
initializes	O
some	O
rather	O
large	O
data	O
structures	O
used	O
for	O
parsing	B-Language
SQL	B-Language
,	O
and	O
thus	O
may	O
take	O
longer	O
than	O
other	O
module	O
imports	O
.	O
</s>
<s>
During	O
active	O
use	O
a	O
log	B-Application
file	I-Application
appears	O
in	O
the	O
active	O
directory	O
as	O
well	O
,	O
and	O
if	O
the	O
process	O
crashes	O
this	O
log	B-Application
file	I-Application
is	O
used	O
to	O
recover	O
committed	O
operations	O
.	O
</s>
<s>
At	O
this	O
point	O
Gadfly	B-Language
supports	O
quite	O
a	O
lot	O
of	O
the	O
SQL	B-Language
semantics	O
requested	O
in	O
the	O
ODBC	O
2.0	O
specification	O
.	O
</s>
<s>
SQL	B-Language
statements	O
supported	O
include	O
the	O
SELECT	O
:	O
</s>
<s>
The	O
actual	O
implementation	O
in	O
gadfly	B-Language
is	O
much	O
better	O
than	O
the	O
intuitive	O
reading	O
,	O
particularly	O
at	O
steps	O
1	O
and	O
2	O
(	O
which	O
are	O
combined	O
via	O
optimizing	O
transformations	O
and	O
hash	O
join	O
algorithms	O
)	O
.	O
</s>
<s>
Data	O
types	O
currently	O
"	O
supported	O
"	O
are	O
integer	O
,	O
float	B-Algorithm
,	O
and	O
varchar	B-Language
.	O
</s>
<s>
At	O
present	O
tuples	O
,	O
complexes	O
,	O
or	O
anything	O
else	O
can	O
be	O
put	O
into	O
a	O
column	O
specified	O
as	O
"	O
VARCHAR	B-Language
"	O
.	O
</s>
<s>
Gadfly	B-Language
also	O
supports	O
the	O
searched	O
DELETE	O
and	O
UPDATE	O
;	O
INSERT	O
VALUES	O
and	O
INSERT	O
subselect	O
;	O
CREATE/DROP	O
INDEX	O
,	O
and	O
DROP	O
TABLE	O
.	O
</s>
<s>
SQL	B-Language
is	O
case	O
insensitive	O
.	O
</s>
<s>
Dynamic	O
values	O
allow	O
the	O
cursor	O
to	O
use	O
the	O
same	O
parsed	B-Language
expression	O
many	O
times	O
for	O
a	O
similar	O
operation	O
.	O
</s>
<s>
Above	O
the	O
insertstat	O
is	O
parsed	B-Language
and	O
bound	O
to	O
the	O
database	O
only	O
once	O
.	O
</s>
<s>
Since	O
the	O
dynamic	O
substitution	O
eliminates	O
the	O
need	O
for	O
parsing	B-Language
and	O
binding	O
(	O
expensive	O
operations	O
!	O
)	O
</s>
<s>
If	O
several	O
similar	O
queries	O
are	O
repeated	O
multiple	O
times	O
,	O
each	O
query	O
"	O
template	O
string	O
"	O
is	O
associated	O
with	O
a	O
unique	O
cursor	O
object	O
so	O
that	O
each	O
template	O
must	O
be	O
parsed	B-Language
and	O
bound	O
only	O
once	O
.	O
</s>
<s>
Some	O
relatively	O
complex	O
queries	O
from	O
the	O
test	O
suite	O
run	O
2	O
to	O
3	O
times	O
faster	O
after	O
they	O
have	O
been	O
parsed	B-Language
and	O
bound	O
,	O
even	O
without	O
the	O
kjbuckets	O
builtin	O
.	O
</s>
<s>
It	O
would	O
be	O
even	O
faster	O
if	O
the	O
cursor	O
had	O
previously	O
executed	O
the	O
stat	O
with	O
different	O
data	O
(	O
since	O
then	O
no	O
parsing	B-Language
or	O
binding	O
would	O
occur	O
)	O
.	O
</s>
<s>
By	O
default	O
a	O
gadfly	B-Language
database	O
automatically	O
includes	O
"	O
introspective	O
"	O
tables	O
which	O
allow	O
a	O
gadfly	B-Language
query	O
to	O
"	O
query	O
the	O
shape	O
of	O
the	O
database	O
"	O
—	O
for	O
example	O
to	O
view	O
table	O
names	O
and	O
names	O
of	O
rows	O
in	O
tables	O
:	O
</s>
<s>
Here	O
DUAL	O
is	O
a	O
standard	O
one	O
row/one	O
column	O
test	O
table	O
(	O
from	O
the	O
Oracle	B-General_Concept
tradition	O
)	O
and	O
the	O
other	O
tables	O
provide	O
information	O
about	O
the	O
database	O
schema	O
:	O
</s>
<s>
The	O
SQL	B-Language
grammar	O
is	O
described	O
in	O
grammar.py,	O
the	O
binding	O
of	O
the	O
grammar	O
constructs	O
to	O
semantic	O
objects	O
is	O
performed	O
in	O
bindings.py,	O
the	O
semantic	O
objects	O
and	O
their	O
execution	O
strategies	O
is	O
defined	O
in	O
semantics.py	O
.	O
</s>
<s>
The	O
semantics	O
use	O
a	O
lot	O
of	O
classical	O
and	O
non-classical	O
logic	O
(	O
cylindric	O
logic	O
)	O
as	O
well	O
as	O
optimization	O
heuristics	O
to	O
define	O
a	O
relatively	O
efficient	O
and	O
correct	O
implementation	O
of	O
SQL	B-Language
.	O
</s>
<s>
The	O
most	O
basic	O
data	O
structures	O
of	O
the	O
implementation	O
are	O
given	O
in	O
either	O
kjbuckets0.py	O
or	O
the	O
faster	O
kjbucketsmodule.c	O
,	O
which	O
implement	O
the	O
same	O
data	O
type	O
signatures	O
in	O
Python	B-Language
and	O
in	O
a	O
C	O
extension	O
to	O
Python	B-Language
respectively	O
.	O
</s>
<s>
The	O
SQL	B-Language
parser	O
also	O
requires	O
the	O
kwParsing	O
parser	O
generation	O
package	O
,	O
which	O
consists	O
of	O
a	O
number	O
of	O
additional	O
python	B-Language
modules	O
.	O
</s>
<s>
With	O
gfplus	O
a	O
gadfly	B-Language
database	O
can	O
be	O
interactively	O
manipulated	O
with	O
SQL	B-Language
commands	O
.	O
</s>
<s>
The	O
tool	O
works	O
similar	O
to	O
Oracle	B-General_Concept
's	O
SQL*Plus	B-Application
.	O
</s>
<s>
Because	O
it	O
lacks	O
true	O
concurrency	B-Operating_System
control	I-Operating_System
and	O
file-system	O
based	O
indexing	O
it	O
is	O
not	O
appropriate	O
for	O
very	O
large	O
multiprocess	O
transaction-based	O
systems	O
.	O
</s>
