Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / libraries / sqlite / sqlite3-aos4.c
blob427a095fb6c2dade27843f35c88ec484c099b4ef
1 // Preferences-aos4.c
2 // $Date$
3 // $Revision$
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>
14 #include <stdarg.h>
16 #include "sqlite3_base.h"
17 #include "LibSQLite3.h"
18 #include "sqlite3.h"
20 #include <defs.h>
22 int _start(void)
24 return -1;
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);
36 /* OS4.0 Library */
38 /* ------------------- OS4 Manager Interface ------------------------ */
39 static const APTR managerfunctable[] =
41 (APTR)Obtainlib,
42 (APTR)Releaselib,
43 (APTR)NULL,
44 (APTR)NULL,
45 (APTR)Openlib,
46 (APTR)Closelib,
47 (APTR)Expungelib,
48 (APTR)NULL,
49 (APTR)-1
52 static const struct TagItem managertags[] =
54 {MIT_Name, (ULONG)"__library"},
55 {MIT_VectorTable, (ULONG)managerfunctable},
56 {MIT_Version, 1},
57 {TAG_DONE, 0}
60 /* ---------------------- OS4 Main Interface ------------------------ */
61 static APTR functable[] =
63 Obtainlib,
64 Releaselib,
65 NULL,
66 NULL,
67 LIBSQLite3Close,
68 LIBSQLite3Exec,
69 LIBSQLite3Changes,
70 LIBSQLite3TotalChanges,
71 LIBSQLite3Interrupt,
72 LIBSQLite3Complete,
73 LIBSQLite3BusyHandler,
74 LIBSQLite3BusyTimeout,
75 LIBSQLite3GetTable,
76 LIBSQLite3FreeTable,
77 LIBSQLite3Free,
78 LIBSQLite3Trace,
79 LIBSQLite3ProgressHandler,
80 LIBSQLite3CommitHook,
81 LIBSQLite3Open,
82 LIBSQLite3Errcode,
83 LIBSQLite3Errmsg,
84 LIBSQLite3Prepare,
85 LIBSQLite3BindBlob,
86 LIBSQLite3BindInt,
87 LIBSQLite3BindNull,
88 LIBSQLite3BindText,
89 LIBSQLite3BindValue,
90 LIBSQLite3BindParameterCount,
91 LIBSQLite3BindParameterName,
92 LIBSQLite3BindParameterIndex,
93 LIBSQLite3ClearBindings,
94 LIBSQLite3ColumnCount,
95 LIBSQLite3ColumnName,
96 LIBSQLite3ColumnDecltype,
97 LIBSQLite3Step,
98 LIBSQLite3DataCount,
99 LIBSQLite3ColumnBlob,
100 LIBSQLite3ColumnBytes,
101 LIBSQLite3ColumnInt,
102 LIBSQLite3ColumnText,
103 LIBSQLite3ColumnType,
104 LIBSQLite3Finalize,
105 LIBSQLite3Reset,
106 LIBSQLite3AggregateCount,
107 LIBSQLite3ValueBlob,
108 LIBSQLite3ValueBytes,
109 LIBSQLite3ValueInt,
110 LIBSQLite3ValueText,
111 LIBSQLite3ValueType,
112 LIBSQLite3Aggregate_context,
113 LIBSQLite3UserData,
114 LIBSQLite3GetAuxdata,
115 LIBSQLite3SetAuxdata,
116 LIBSQLite3ResultBlob,
117 LIBSQLite3ResultError,
118 LIBSQLite3ResultInt,
119 LIBSQLite3ResultNull,
120 LIBSQLite3ResultText,
121 LIBSQLite3ResultValue,
122 LIBSQLite3CreateCollation,
123 LIBSQLite3CollationNeeded,
124 LIBSQLite3Sleep,
125 LIBSQLite3Expired,
126 LIBSQLite3TransferBindings,
127 LIBSQLite3GlobalRecover,
128 LIBSQLite3GetAutocommit,
129 LIBSQLite3DbHandle,
131 // new functions in V41
132 LIBSQLite3RollbackHook,
133 LIBSQLite3EnableSharedCache,
134 LIBSQLite3ReleaseMemory,
135 LIBSQLite3SoftHeapLimit,
136 LIBSQLite3ThreadCleanup,
138 // new function in V42
139 LIBSQLite3PrepareV2,
141 // new function in V43
142 LIBSQLite3CreateFunction,
143 LIBSQLite3CreateModule,
144 LIBSQLite3DeclareVtab,
145 LIBSQLite3OverloadFunction,
146 LIBSQLite3BlobOpen,
147 LIBSQLite3BlobClose,
148 LIBSQLite3BlobBytes,
149 LIBSQLite3BlobRead,
150 LIBSQLite3BlobWrite,
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
165 LIBSQLite3ConfigV,
166 LIBSQLlite3DbConfigV,
167 LIBSQLite3VfsFind,
168 LIBSQLite3VfsRegister,
169 LIBSQLite3VfsUnregister,
170 LIBSQLite3FileControl,
171 LIBSQLite3Status,
172 LIBSQLite3DbStatus,
174 (APTR) -1
177 static const struct TagItem maintags[] =
179 {MIT_Name, (ULONG)"main"},
180 {MIT_VectorTable, (ULONG)functable},
181 {MIT_Version, 1},
182 {TAG_DONE, 0}
185 /* Init table used in library initialization. */
186 static const ULONG interfaces[] =
188 (ULONG)managertags,
189 (ULONG)maintags,
190 (ULONG)0
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},
199 {TAG_DONE, 0}
203 /* The ROM tag */
204 struct Resident ALIGNED romtag =
206 RTC_MATCHWORD,
207 &romtag,
208 &romtag + 1,
209 RTF_NATIVE | RTF_AUTOINIT,
210 LIB_VERSION,
211 NT_LIBRARY,
213 libName,
214 libIdString,
215 inittab
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;
226 IExec = pIExec;
227 SQLite3LibBase->sql3_LibNode.lib_Revision = LIB_REVISION;
228 SQLite3LibBase->sql3_SegList = (struct SegList *)seglist;
230 if (!SQLite3Init(SQLite3LibBase))
232 Expungelib(Self);
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;
256 return (BPTR)NULL;
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");
271 Closelib(Self);
272 return NULL;
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);
294 return (BPTR)NULL;
297 static ULONG Obtainlib(struct LibraryManagerInterface *Self)
299 return(Self->Data.RefCount++);
302 static ULONG Releaselib(struct LibraryManagerInterface *Self)
304 return(Self->Data.RefCount--);