cpdo  Hex Artifact Content

Artifact 0b580bb934db513d5fc3374bf27c98a0239437f8:

Wiki page [cpdo_sqlite3] by stephan 2016-01-07 21:24:52.
0000: 44 20 32 30 31 36 2d 30 31 2d 30 37 54 32 31 3a  D 2016-01-07T21:
0010: 32 34 3a 35 32 2e 33 31 30 0a 4c 20 63 70 64 6f  24:52.310.L cpdo
0020: 5f 73 71 6c 69 74 65 33 0a 50 20 65 32 34 66 30  _sqlite3.P e24f0
0030: 37 38 34 38 33 63 39 38 65 62 34 32 37 33 30 30  78483c98eb427300
0040: 63 33 36 64 39 32 37 34 33 32 30 34 39 64 63 33  c36d927432049dc3
0050: 37 35 61 0a 55 20 73 74 65 70 68 61 6e 0a 57 20  75a.U stephan.W 
0060: 32 31 30 36 0a 3c 73 74 72 6f 6e 67 3e 41 43 48  2106.<strong>ACH
0070: 54 55 4e 47 3a 20 54 48 45 20 43 50 44 4f 20 57  TUNG: THE CPDO W
0080: 49 4b 49 20 49 53 20 4e 4f 57 20 28 41 53 20 4f  IKI IS NOW (AS O
0090: 46 20 32 30 31 31 2d 4d 61 79 2d 31 37 29 20 4d  F 2011-May-17) M
00a0: 41 49 4e 54 41 49 4e 45 44 20 4f 4e 20 41 20 44  AINTAINED ON A D
00b0: 45 44 49 43 41 54 45 44 20 57 49 4b 49 20 53 49  EDICATED WIKI SI
00c0: 54 45 3a 3c 2f 73 74 72 6f 6e 67 3e 20 5b 68 74  TE:</strong> [ht
00d0: 74 70 3a 2f 2f 77 68 69 6b 69 2e 77 61 6e 64 65  tp://whiki.wande
00e0: 72 69 6e 67 68 6f 72 73 65 2e 6e 65 74 2f 77 69  ringhorse.net/wi
00f0: 6b 69 73 2f 63 70 64 6f 2f 3f 70 61 67 65 3d 63  kis/cpdo/?page=c
0100: 70 64 6f 5f 73 71 6c 69 74 65 33 5d 0d 0a 0d 0a  pdo_sqlite3]....
0110: 54 68 65 20 73 71 6c 69 74 65 33 20 64 72 69 76  The sqlite3 driv
0120: 65 72 20 62 69 6e 64 69 6e 67 20 69 73 20 62 61  er binding is ba
0130: 73 69 63 61 6c 6c 79 20 74 68 65 20 72 65 66 65  sically the refe
0140: 72 65 6e 63 65 20 69 6d 70 6c 65 6d 65 6e 74 61  rence implementa
0150: 74 69 6f 6e 2e 20 49 74 20 73 75 70 70 6f 72 74  tion. It support
0160: 73 20 74 68 65 20 63 70 64 6f 20 69 6e 74 65 72  s the cpdo inter
0170: 66 61 63 65 20 72 65 71 75 69 72 65 6d 65 6e 74  face requirement
0180: 73 20 74 6f 20 74 68 65 20 6c 65 74 74 65 72 20  s to the letter 
0190: 61 6e 64 20 73 75 70 70 6f 72 74 73 20 61 6c 6c  and supports all
01a0: 20 6f 66 20 74 68 65 20 6f 70 74 69 6f 6e 61 6c   of the optional
01b0: 20 66 65 61 74 75 72 65 73 2e 0d 0a 0d 0a 54 68   features.....Th
01c0: 65 20 5b 44 53 4e 5d 20 66 6f 72 6d 61 74 20 66  e [DSN] format f
01d0: 6f 72 20 74 68 69 73 20 64 72 69 76 65 72 20 69  or this driver i
01e0: 73 20 3c 74 74 3e 22 73 71 6c 69 74 65 33 3a 66  s <tt>"sqlite3:f
01f0: 69 6c 65 6e 61 6d 65 22 3c 2f 74 74 3e 2c 20 77  ilename"</tt>, w
0200: 68 65 72 65 20 66 69 6c 65 6e 61 6d 65 20 6d 75  here filename mu
0210: 73 74 20 62 65 20 61 20 72 65 6c 61 74 69 76 65  st be a relative
0220: 20 6f 72 20 61 62 73 6f 6c 75 74 65 20 70 61 74   or absolute pat
0230: 68 20 64 6f 20 61 20 64 61 74 61 62 61 73 65 20  h do a database 
0240: 66 69 6c 65 20 6f 72 20 74 68 65 20 73 70 65 63  file or the spec
0250: 69 61 6c 20 6e 61 6d 65 20 3c 74 74 3e 3a 6d 65  ial name <tt>:me
0260: 6d 6f 72 79 3a 3c 2f 74 74 3e 20 66 6f 72 20 61  mory:</tt> for a
0270: 6e 20 69 6e 2d 6d 65 6d 6f 72 79 20 64 61 74 61  n in-memory data
0280: 62 61 73 65 2e 20 54 68 65 20 64 61 74 61 62 61  base. The databa
0290: 73 65 20 77 69 6c 6c 20 62 65 20 63 72 65 61 74  se will be creat
02a0: 65 64 20 69 66 20 69 74 20 64 6f 65 73 20 6e 6f  ed if it does no
02b0: 74 20 79 65 74 20 65 78 69 73 74 20 28 61 6e 64  t yet exist (and
02c0: 20 22 63 6f 6e 6e 65 63 74 69 6e 67 22 20 77 69   "connecting" wi
02d0: 6c 6c 20 66 61 69 6c 20 69 66 20 69 74 20 63 61  ll fail if it ca
02e0: 6e 6e 6f 74 20 62 65 20 63 72 65 61 74 65 64 29  nnot be created)
02f0: 2e 20 54 68 69 73 20 64 72 69 76 65 72 20 69 67  . This driver ig
0300: 6e 6f 72 65 73 20 61 6e 79 20 75 73 65 72 6e 61  nores any userna
0310: 6d 65 2f 70 61 73 73 77 6f 72 64 20 70 72 6f 76  me/password prov
0320: 69 64 65 64 20 66 6f 72 20 63 6f 6e 6e 65 63 74  ided for connect
0330: 69 6e 67 2e 0d 0a 0d 0a 3c 62 3e 52 65 71 75 69  ing.....<b>Requi
0340: 72 65 64 20 73 71 6c 69 74 65 33 20 56 65 72 73  red sqlite3 Vers
0350: 69 6f 6e 3a 3c 2f 62 3e 20 74 68 65 20 6f 6c 64  ion:</b> the old
0360: 65 73 74 20 76 65 72 73 69 6f 6e 20 69 20 68 61  est version i ha
0370: 76 65 20 74 65 73 74 65 64 20 77 61 73 20 33 2e  ve tested was 3.
0380: 33 2e 36 20 28 72 65 6c 65 61 73 65 64 20 69 6e  3.6 (released in
0390: 20 4a 75 6e 65 20 32 30 30 36 29 2e 20 4e 6f 72   June 2006). Nor
03a0: 6d 61 6c 6c 79 20 69 20 64 65 76 65 6c 6f 70 20  mally i develop 
03b0: 75 73 69 6e 67 20 77 68 61 74 65 76 65 72 20 76  using whatever v
03c0: 65 72 73 69 6f 6e 20 69 73 20 6f 6e 20 6d 79 20  ersion is on my 
03d0: 55 62 75 6e 74 75 20 62 6f 78 65 73 20 28 77 68  Ubuntu boxes (wh
03e0: 69 63 68 20 72 75 6e 20 73 79 73 74 65 6d 20 75  ich run system u
03f0: 70 64 61 74 65 73 20 65 76 65 72 79 20 66 65 77  pdates every few
0400: 20 64 61 79 73 29 2c 20 61 6e 64 20 6f 63 63 61   days), and occa
0410: 73 69 6f 6e 61 6c 6c 79 20 28 62 75 74 20 6e 6f  sionally (but no
0420: 74 20 6f 66 74 65 6e 29 20 74 72 79 20 6f 75 74  t often) try out
0430: 20 6f 6c 64 65 72 20 76 65 72 73 69 6f 6e 73 2e   older versions.
0440: 0d 0a 0d 0a 0d 0a 3c 73 74 72 6f 6e 67 3e 54 4f  ......<strong>TO
0450: 44 4f 73 3a 3c 2f 73 74 72 6f 6e 67 3e 0d 0a 0d  DOs:</strong>...
0460: 0a 20 20 20 2a 20 20 41 64 64 20 44 53 4e 20 61  .   *  Add DSN a
0470: 74 74 72 69 62 75 74 65 20 22 66 61 69 6c 69 66  ttribute "failif
0480: 6e 6f 74 65 78 69 73 74 73 3d 62 6f 6f 6c 65 61  notexists=boolea
0490: 6e 22 20 28 6f 72 20 73 6f 6d 65 74 68 69 6e 67  n" (or something
04a0: 20 6c 69 6b 65 20 74 68 61 74 29 20 73 6f 20 74   like that) so t
04b0: 68 65 20 63 61 6c 6c 65 72 20 63 61 6e 20 72 65  he caller can re
04c0: 71 75 69 72 65 20 74 68 61 74 20 74 68 65 20 44  quire that the D
04d0: 42 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 73  B already exists
04e0: 2e 20 42 79 20 64 65 66 61 75 6c 74 20 73 71 6c  . By default sql
04f0: 69 74 65 33 20 63 72 65 61 74 65 73 20 74 68 65  ite3 creates the
0500: 20 64 62 20 69 66 20 69 74 20 64 6f 65 73 20 6e   db if it does n
0510: 6f 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 74  ot already exist
0520: 2e 0d 0a 0d 0a 0d 0a 3c 68 31 3e 4e 6f 74 65 73  .......<h1>Notes
0530: 20 61 62 6f 75 74 20 4f 76 65 72 68 65 61 64 3c   about Overhead<
0540: 2f 68 31 3e 0d 0a 0d 0a 54 68 65 20 6f 76 65 72  /h1>....The over
0550: 68 65 61 64 20 69 6d 70 6f 73 65 64 20 62 79 20  head imposed by 
0560: 74 68 69 73 20 64 72 69 76 65 72 2c 20 6f 76 65  this driver, ove
0570: 72 20 75 73 69 6e 67 20 73 71 6c 69 74 65 33 20  r using sqlite3 
0580: 64 69 72 65 63 74 6c 79 2c 20 69 73 20 6d 69 6e  directly, is min
0590: 69 6d 61 6c 2e 0d 0a 0d 0a 69 20 68 61 76 65 20  imal.....i have 
05a0: 74 77 6f 20 6e 65 61 72 6c 79 2d 69 64 65 6e 74  two nearly-ident
05b0: 69 63 61 6c 20 74 65 73 74 20 61 70 70 73 20 69  ical test apps i
05c0: 6e 20 6f 6e 65 20 70 72 6f 6a 65 63 74 20 77 68  n one project wh
05d0: 69 63 68 20 64 69 66 66 65 72 20 6f 6e 6c 79 20  ich differ only 
05e0: 69 6e 20 74 68 65 69 72 20 64 62 20 64 72 69 76  in their db driv
05f0: 65 72 3a 20 6f 6e 65 20 75 73 65 73 20 63 70 64  er: one uses cpd
0600: 6f 20 28 77 69 74 68 20 73 71 6c 69 74 65 33 20  o (with sqlite3 
0610: 61 73 20 74 68 65 20 62 61 63 6b 2d 65 6e 64 29  as the back-end)
0620: 20 61 6e 64 20 6f 6e 65 20 75 73 65 73 20 74 68   and one uses th
0630: 65 20 73 71 6c 69 74 65 33 20 41 50 49 20 64 69  e sqlite3 API di
0640: 72 65 63 74 6c 79 2e 20 46 6f 72 20 74 68 61 74  rectly. For that
0650: 20 70 61 72 74 69 63 75 6c 61 72 20 74 65 73 74   particular test
0660: 20 61 70 70 20 28 69 74 27 73 20 76 65 72 79 20   app (it's very 
0670: 73 6d 61 6c 6c 29 2c 20 74 68 65 20 74 6f 74 61  small), the tota
0680: 6c 20 6d 65 6d 6f 72 79 20 63 6f 73 74 73 20 77  l memory costs w
0690: 65 72 65 3a 0d 0a 0d 0a 20 20 20 2a 20 20 73 71  ere:....   *  sq
06a0: 6c 69 74 65 33 3a 20 33 38 39 20 61 6c 6c 6f 63  lite3: 389 alloc
06b0: 61 74 69 6f 6e 73 20 74 6f 74 61 6c 69 6e 67 20  ations totaling 
06c0: 32 31 32 34 38 30 20 62 79 74 65 73 2e 0d 0a 20  212480 bytes... 
06d0: 20 20 2a 20 20 63 70 64 6f 2f 73 71 6c 69 74 65    *  cpdo/sqlite
06e0: 33 3a 20 34 30 30 20 61 6c 6c 6f 63 61 74 69 6f  3: 400 allocatio
06f0: 6e 73 20 28 64 69 66 66 3d 2b 31 31 29 20 74 6f  ns (diff=+11) to
0700: 74 61 6c 69 6e 67 20 32 31 32 38 30 38 20 62 79  taling 212808 by
0710: 74 65 73 20 28 64 69 66 66 3d 2b 33 32 38 29 2e  tes (diff=+328).
0720: 0d 0a 0d 0a 54 68 65 20 6d 61 6a 6f 72 69 74 79  ....The majority
0730: 20 6f 66 20 74 68 61 74 20 6d 65 6d 6f 72 79 20   of that memory 
0740: 28 73 6f 6d 65 77 68 65 72 65 20 69 6e 20 74 68  (somewhere in th
0750: 65 20 6e 65 69 67 68 62 6f 72 68 6f 6f 64 20 6f  e neighborhood o
0760: 66 20 32 30 30 6b 62 29 20 69 73 20 61 6c 6c 6f  f 200kb) is allo
0770: 63 61 74 65 64 20 62 79 20 73 71 6c 69 74 65 33  cated by sqlite3
0780: 20 69 74 73 65 6c 66 2c 20 62 75 74 20 74 68 65   itself, but the
0790: 20 4a 53 4f 4e 20 6c 69 62 72 61 72 79 20 75 73   JSON library us
07a0: 65 64 20 62 79 20 74 68 65 20 74 65 73 74 20 61  ed by the test a
07b0: 70 70 73 20 69 73 20 74 68 65 20 73 6f 75 72 63  pps is the sourc
07c0: 65 20 66 6f 72 20 6d 61 6e 79 20 6f 66 20 74 68  e for many of th
07d0: 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 28 62  e allocations (b
07e0: 75 74 20 6f 6e 6c 79 20 61 20 66 65 77 20 6b 62  ut only a few kb
07f0: 20 6f 66 20 6d 65 6d 6f 72 79 29 2e 0d 0a 0d 0a   of memory).....
0800: 54 68 65 20 22 65 78 74 72 61 22 20 61 6c 6c 6f  The "extra" allo
0810: 63 61 74 69 6f 6e 73 20 77 65 20 73 65 65 20 69  cations we see i
0820: 6e 20 74 68 65 20 63 70 64 6f 2d 75 73 69 6e 67  n the cpdo-using
0830: 20 61 70 70 20 61 72 65 20 70 72 69 6d 61 72 69   app are primari
0840: 6c 79 20 69 6e 20 74 68 65 20 66 6f 72 6d 20 6f  ly in the form o
0850: 66 20 74 68 65 20 63 70 64 6f 2d 6c 65 76 65 6c  f the cpdo-level
0860: 20 77 72 61 70 70 65 72 20 63 6c 61 73 73 65 73   wrapper classes
0870: 20 66 6f 72 20 74 68 65 20 75 6e 64 65 72 6c 79   for the underly
0880: 69 6e 67 20 64 62 20 61 6e 64 20 73 74 61 74 65  ing db and state
0890: 6d 65 6e 74 20 68 61 6e 64 6c 65 73 2e 0d 0a 0a  ment handles....
08a0: 5a 20 65 30 61 30 35 63 37 37 66 65 34 35 36 33  Z e0a05c77fe4563
08b0: 30 37 37 65 37 32 35 65 62 32 61 39 33 33 34 62  077e725eb2a9334b
08c0: 31 61 0a                                         1a.