6 #include <exec/interfaces.h>
7 #include <exec/exectags.h>
8 #include <exec/resident.h>
9 #include <exec/emulation.h>
11 #include <proto/exec.h>
12 #include <interfaces/sqlite3.h>
16 #include "sqlite3_base.h"
17 #include "LibSQLite3.h"
27 extern CONST_APTR VecTable68K
[];
29 static struct Library
*Initlib(struct Library
*libbase
, BPTR seglist
, struct ExecIFace
*pIExec
);
30 static BPTR
Expungelib(struct LibraryManagerInterface
*Self
);
31 static struct LibraryHeader
*Openlib(struct LibraryManagerInterface
*Self
, ULONG version
);
32 static BPTR
Closelib(struct LibraryManagerInterface
*Self
);
33 static ULONG
Obtainlib(struct LibraryManagerInterface
*Self
);
34 static ULONG
Releaselib(struct LibraryManagerInterface
*Self
);
38 /* ------------------- OS4 Manager Interface ------------------------ */
39 static const APTR managerfunctable
[] =
52 static const struct TagItem managertags
[] =
54 {MIT_Name
, (ULONG
)"__library"},
55 {MIT_VectorTable
, (ULONG
)managerfunctable
},
60 /* ---------------------- OS4 Main Interface ------------------------ */
61 static APTR functable
[] =
70 LIBSQLite3TotalChanges
,
73 LIBSQLite3BusyHandler
,
74 LIBSQLite3BusyTimeout
,
79 LIBSQLite3ProgressHandler
,
90 LIBSQLite3BindParameterCount
,
91 LIBSQLite3BindParameterName
,
92 LIBSQLite3BindParameterIndex
,
93 LIBSQLite3ClearBindings
,
94 LIBSQLite3ColumnCount
,
96 LIBSQLite3ColumnDecltype
,
100 LIBSQLite3ColumnBytes
,
102 LIBSQLite3ColumnText
,
103 LIBSQLite3ColumnType
,
106 LIBSQLite3AggregateCount
,
108 LIBSQLite3ValueBytes
,
112 LIBSQLite3Aggregate_context
,
114 LIBSQLite3GetAuxdata
,
115 LIBSQLite3SetAuxdata
,
116 LIBSQLite3ResultBlob
,
117 LIBSQLite3ResultError
,
119 LIBSQLite3ResultNull
,
120 LIBSQLite3ResultText
,
121 LIBSQLite3ResultValue
,
122 LIBSQLite3CreateCollation
,
123 LIBSQLite3CollationNeeded
,
126 LIBSQLite3TransferBindings
,
127 LIBSQLite3GlobalRecover
,
128 LIBSQLite3GetAutocommit
,
131 // new functions in V41
132 LIBSQLite3RollbackHook
,
133 LIBSQLite3EnableSharedCache
,
134 LIBSQLite3ReleaseMemory
,
135 LIBSQLite3SoftHeapLimit
,
136 LIBSQLite3ThreadCleanup
,
138 // new function in V42
141 // new function in V43
142 LIBSQLite3CreateFunction
,
143 LIBSQLite3CreateModule
,
144 LIBSQLite3DeclareVtab
,
145 LIBSQLite3OverloadFunction
,
151 LIBSQLite3ExtendedResultCodes
,
152 LIBSQLite3BindZeroBlob
,
153 LIBSQLite3ColumnDatabaseName
,
154 LIBSQLite3ColumnTableName
,
155 LIBSQLite3ColumnOriginName
,
156 LIBSQLite3ColumnValue
,
157 LIBSQLite3CreateCollationV2
,
158 LIBSQLite3LibVersion
,
159 LIBSQLite3LibversionNumber
,
160 LIBSQLite3ResultErrorToobig
,
161 LIBSQLite3ResultZeroBlob
,
162 LIBSQLite3ValueNumericType
,
164 // new function in V44
166 LIBSQLlite3DbConfigV
,
168 LIBSQLite3VfsRegister
,
169 LIBSQLite3VfsUnregister
,
170 LIBSQLite3FileControl
,
177 static const struct TagItem maintags
[] =
179 {MIT_Name
, (ULONG
)"main"},
180 {MIT_VectorTable
, (ULONG
)functable
},
185 /* Init table used in library initialization. */
186 static const ULONG interfaces
[] =
193 static const struct TagItem inittab
[] =
195 {CLT_DataSize
, (ULONG
)sizeof(struct SQLite3Base
)},
196 {CLT_Interfaces
, (ULONG
) interfaces
},
197 {CLT_Vector68K
, (ULONG
)VecTable68K
},
198 {CLT_InitFunc
, (ULONG
) Initlib
},
204 struct Resident ALIGNED romtag
=
209 RTF_NATIVE
| RTF_AUTOINIT
,
218 /* ------------------- OS4 Manager Functions ------------------------ */
219 static struct Library
* Initlib(struct Library
*libbase
, BPTR seglist
, struct ExecIFace
*pIExec
)
221 struct SQLite3Base
*SQLite3LibBase
= (struct SQLite3Base
*) libbase
;
222 struct ExtendedLibrary
*ExtLib
= (struct ExtendedLibrary
*) ((ULONG
)libbase
+ libbase
->lib_PosSize
);
223 struct LibraryManagerInterface
*Self
= (struct LibraryManagerInterface
*) ExtLib
->ILibrary
;
225 SysBase
= (struct ExecBase
*)pIExec
->Data
.LibBase
;
227 SQLite3LibBase
->sql3_LibNode
.lib_Revision
= LIB_REVISION
;
228 SQLite3LibBase
->sql3_SegList
= (struct SegList
*)seglist
;
230 if (!SQLite3Init(SQLite3LibBase
))
233 SQLite3LibBase
= NULL
;
236 return SQLite3LibBase
? &SQLite3LibBase
->sql3_LibNode
: NULL
;
239 static BPTR
Expungelib(struct LibraryManagerInterface
*Self
)
241 struct SQLite3Base
*SQLite3LibBase
= (struct SQLite3Base
*) Self
->Data
.LibBase
;
243 if (0 == SQLite3LibBase
->sql3_LibNode
.lib_OpenCnt
)
245 struct SegList
*libseglist
= SQLite3LibBase
->sql3_SegList
;
247 Remove((struct Node
*) SQLite3LibBase
);
248 SQLite3Cleanup(SQLite3LibBase
);
249 DeleteLibrary((struct Library
*)SQLite3LibBase
);
251 return (BPTR
)libseglist
;
254 SQLite3LibBase
->sql3_LibNode
.lib_Flags
|= LIBF_DELEXP
;
259 static struct LibraryHeader
*Openlib(struct LibraryManagerInterface
*Self
, ULONG version
)
261 struct SQLite3Base
*SQLite3LibBase
= (struct SQLite3Base
*) Self
->Data
.LibBase
;
263 SQLite3LibBase
->sql3_LibNode
.lib_OpenCnt
++;
264 SQLite3LibBase
->sql3_LibNode
.lib_Flags
&= ~LIBF_DELEXP
;
266 if (!SQLite3LibBase
->sql3_Initialized
)
268 if (!SQLite3Open(SQLite3LibBase
))
270 KPrintF("SQLite3Open failed\n");
274 SQLite3LibBase
->sql3_Initialized
= TRUE
;
277 return (struct LibraryHeader
*)SQLite3LibBase
;
280 static BPTR
Closelib(struct LibraryManagerInterface
*Self
)
282 struct SQLite3Base
*SQLite3LibBase
= (struct SQLite3Base
*) Self
->Data
.LibBase
;
284 SQLite3LibBase
->sql3_LibNode
.lib_OpenCnt
--;
286 if (0 == SQLite3LibBase->sql3_LibNode.lib_OpenCnt)
288 if (SQLite3LibBase->sql3_LibNode.lib_Flags & LIBF_DELEXP)
290 return Expungelib(Self);
297 static ULONG
Obtainlib(struct LibraryManagerInterface
*Self
)
299 return(Self
->Data
.RefCount
++);
302 static ULONG
Releaselib(struct LibraryManagerInterface
*Self
)
304 return(Self
->Data
.RefCount
--);