Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / db / mdb / public / mdb.h
blobffd479c5711df7286c486bd078d1fc6de4754388
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Blake Ross (blake@blakeross.com)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef _MDB_
40 #define _MDB_ 1
42 #include "nscore.h"
43 #include "nsISupports.h"
44 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
46 // { %%%%% begin scalar typedefs %%%%%
47 typedef unsigned char mdb_u1; // make sure this is one byte
48 typedef unsigned short mdb_u2; // make sure this is two bytes
49 typedef short mdb_i2; // make sure this is two bytes
50 typedef PRUint32 mdb_u4; // make sure this is four bytes
51 typedef PRInt32 mdb_i4; // make sure this is four bytes
52 typedef PRWord mdb_ip; // make sure sizeof(mdb_ip) == sizeof(void*)
54 typedef mdb_u1 mdb_bool; // unsigned byte with zero=false, nonzero=true
56 /* canonical boolean constants provided only for code clarity: */
57 #define mdbBool_kTrue ((mdb_bool) 1) /* actually any nonzero means true */
58 #define mdbBool_kFalse ((mdb_bool) 0) /* only zero means false */
60 typedef mdb_u4 mdb_id; // unsigned object identity in a scope
61 typedef mdb_id mdb_rid; // unsigned row identity inside scope
62 typedef mdb_id mdb_tid; // unsigned table identity inside scope
63 typedef mdb_u4 mdb_token; // unsigned token for atomized string
64 typedef mdb_token mdb_scope; // token used to id scope for rows
65 typedef mdb_token mdb_kind; // token used to id kind for tables
66 typedef mdb_token mdb_column; // token used to id columns for rows
67 typedef mdb_token mdb_cscode; // token used to id charset names
68 typedef mdb_u4 mdb_seed; // unsigned collection change counter
69 typedef mdb_u4 mdb_count; // unsigned collection member count
70 typedef mdb_u4 mdb_size; // unsigned physical media size
71 typedef mdb_u4 mdb_fill; // unsigned logical content size
72 typedef mdb_u4 mdb_more; // more available bytes for larger buffer
74 #define mdbId_kNone ((mdb_id) -1) /* never a valid Mork object ID */
76 typedef mdb_u4 mdb_percent; // 0..100, with values >100 same as 100
78 typedef mdb_u1 mdb_priority; // 0..9, for a total of ten different values
80 // temporary substitute for NS_RESULT, for mdb.h standalone compilation:
81 typedef nsresult mdb_err; // equivalent to NS_RESULT
83 // sequence position is signed; negative is useful to mean "before first":
84 typedef mdb_i4 mdb_pos; // signed zero-based ordinal collection position
86 #define mdbPos_kBeforeFirst ((mdb_pos) -1) /* any negative is before zero */
88 // order is also signed, so we can use three states for comparison order:
89 typedef mdb_i4 mdb_order; // neg:lessthan, zero:equalto, pos:greaterthan
91 typedef mdb_order (* mdbAny_Order)(const void* inA, const void* inB,
92 const void* inClosure);
94 // } %%%%% end scalar typedefs %%%%%
96 // { %%%%% begin C structs %%%%%
98 #ifndef mdbScopeStringSet_typedef
99 typedef struct mdbScopeStringSet mdbScopeStringSet;
100 #define mdbScopeStringSet_typedef 1
101 #endif
103 /*| mdbScopeStringSet: a set of null-terminated C strings that enumerate some
104 **| names of row scopes, so that row scopes intended for use by an application
105 **| can be declared by an app when trying to open or create a database file.
106 **| (We use strings and not tokens because we cannot know the tokens for any
107 **| particular db without having first opened the db.) The goal is to inform
108 **| a db runtime that scopes not appearing in this list can be given relatively
109 **| short shrift in runtime representation, with the expectation that other
110 **| scopes will not actually be used. However, a db should still be prepared
111 **| to handle accessing row scopes not in this list, rather than raising errors.
112 **| But it could be quite expensive to access a row scope not on the list.
113 **| Note a zero count for the string set means no such string set is being
114 **| specified, and that a db should handle all row scopes efficiently.
115 **| (It does NOT mean an app plans to use no content whatsoever.)
117 #ifndef mdbScopeStringSet_struct
118 #define mdbScopeStringSet_struct 1
119 struct mdbScopeStringSet { // vector of scopes for use in db opening policy
120 // when mScopeStringSet_Count is zero, this means no scope constraints
121 mdb_count mScopeStringSet_Count; // number of strings in vector below
122 const char** mScopeStringSet_Strings; // null-ended ascii scope strings
124 #endif /*mdbScopeStringSet_struct*/
126 #ifndef mdbOpenPolicy_typedef
127 typedef struct mdbOpenPolicy mdbOpenPolicy;
128 #define mdbOpenPolicy_typedef 1
129 #endif
131 #ifndef mdbOpenPolicy_struct
132 #define mdbOpenPolicy_struct 1
133 struct mdbOpenPolicy { // policies affecting db usage for ports and stores
134 mdbScopeStringSet mOpenPolicy_ScopePlan; // predeclare scope usage plan
135 mdb_bool mOpenPolicy_MaxLazy; // nonzero: do least work
136 mdb_bool mOpenPolicy_MinMemory; // nonzero: use least memory
138 #endif /*mdbOpenPolicy_struct*/
140 #ifndef mdbTokenSet_typedef
141 typedef struct mdbTokenSet mdbTokenSet;
142 #define mdbTokenSet_typedef 1
143 #endif
145 #ifndef mdbTokenSet_struct
146 #define mdbTokenSet_struct 1
147 struct mdbTokenSet { // array for a set of tokens, and actual slots used
148 mdb_count mTokenSet_Count; // number of token slots in the array
149 mdb_fill mTokenSet_Fill; // the subset of count slots actually used
150 mdb_more mTokenSet_More; // more tokens available for bigger array
151 mdb_token* mTokenSet_Tokens; // array of count mdb_token instances
153 #endif /*mdbTokenSet_struct*/
155 #ifndef mdbUsagePolicy_typedef
156 typedef struct mdbUsagePolicy mdbUsagePolicy;
157 #define mdbUsagePolicy_typedef 1
158 #endif
160 /*| mdbUsagePolicy: another version of mdbOpenPolicy which uses tokens instead
161 **| of scope strings, because usage policies can be constructed for use with a
162 **| db that is already open, while an open policy must be constructed before a
163 **| db has yet been opened.
165 #ifndef mdbUsagePolicy_struct
166 #define mdbUsagePolicy_struct 1
167 struct mdbUsagePolicy { // policies affecting db usage for ports and stores
168 mdbTokenSet mUsagePolicy_ScopePlan; // current scope usage plan
169 mdb_bool mUsagePolicy_MaxLazy; // nonzero: do least work
170 mdb_bool mUsagePolicy_MinMemory; // nonzero: use least memory
172 #endif /*mdbUsagePolicy_struct*/
174 #ifndef mdbOid_typedef
175 typedef struct mdbOid mdbOid;
176 #define mdbOid_typedef 1
177 #endif
179 #ifndef mdbOid_struct
180 #define mdbOid_struct 1
181 struct mdbOid { // identity of some row or table inside a database
182 mdb_scope mOid_Scope; // scope token for an id's namespace
183 mdb_id mOid_Id; // identity of object inside scope namespace
185 #endif /*mdbOid_struct*/
187 #ifndef mdbRange_typedef
188 typedef struct mdbRange mdbRange;
189 #define mdbRange_typedef 1
190 #endif
192 #ifndef mdbRange_struct
193 #define mdbRange_struct 1
194 struct mdbRange { // range of row positions in a table
195 mdb_pos mRange_FirstPos; // position of first row
196 mdb_pos mRange_LastPos; // position of last row
198 #endif /*mdbRange_struct*/
200 #ifndef mdbColumnSet_typedef
201 typedef struct mdbColumnSet mdbColumnSet;
202 #define mdbColumnSet_typedef 1
203 #endif
205 #ifndef mdbColumnSet_struct
206 #define mdbColumnSet_struct 1
207 struct mdbColumnSet { // array of column tokens (just the same as mdbTokenSet)
208 mdb_count mColumnSet_Count; // number of columns
209 mdb_column* mColumnSet_Columns; // count mdb_column instances
211 #endif /*mdbColumnSet_struct*/
213 #ifndef mdbYarn_typedef
214 typedef struct mdbYarn mdbYarn;
215 #define mdbYarn_typedef 1
216 #endif
218 #ifdef MDB_BEGIN_C_LINKAGE_define
219 #define MDB_BEGIN_C_LINKAGE_define 1
220 #define MDB_BEGIN_C_LINKAGE extern "C" {
221 #define MDB_END_C_LINKAGE }
222 #endif /*MDB_BEGIN_C_LINKAGE_define*/
224 /*| mdbYarn_mGrow: an abstract API for growing the size of a mdbYarn
225 **| instance. With respect to a specific API that requires a caller
226 **| to supply a string (mdbYarn) that a callee fills with content
227 **| that might exceed the specified size, mdbYarn_mGrow is a caller-
228 **| supplied means of letting a callee attempt to increase the string
229 **| size to become large enough to receive all content available.
231 **|| Grow(): a method for requesting that a yarn instance be made
232 **| larger in size. Note that such requests need not be honored, and
233 **| need not be honored in full if only partial size growth is desired.
234 **| (Note that no nsIMdbEnv instance is passed as argument, although one
235 **| might be needed in some circumstances. So if an nsIMdbEnv is needed,
236 **| a reference to one might be held inside a mdbYarn member slot.)
238 **|| self: a yarn instance to be grown. Presumably this yarn is
239 **| the instance which holds the mYarn_Grow method pointer. Yarn
240 **| instancesshould only be passed to grow methods which they were
241 **| specifically designed to fit, as indicated by the mYarn_Grow slot.
243 **|| inNewSize: the new desired value for slot mYarn_Size in self.
244 **| If mYarn_Size is already this big, then nothing should be done.
245 **| If inNewSize is larger than seems feasible or desirable to honor,
246 **| then any size restriction policy can be used to grow to some size
247 **| greater than mYarn_Size. (Grow() might even grow to a size
248 **| greater than inNewSize in order to make the increase in size seem
249 **| worthwhile, rather than growing in many smaller steps over time.)
251 typedef void (* mdbYarn_mGrow)(mdbYarn* self, mdb_size inNewSize);
252 // mdbYarn_mGrow methods must be declared with C linkage in C++
254 /*| mdbYarn: a variable length "string" of arbitrary binary bytes,
255 **| whose length is mYarn_Fill, inside a buffer mYarn_Buf that has
256 **| at most mYarn_Size byte of physical space.
258 **|| mYarn_Buf: a pointer to space containing content. This slot
259 **| might never be nil when mYarn_Size is nonzero, but checks for nil
260 **| are recommended anyway.
261 **| (Implementations of mdbYarn_mGrow methods should take care to
262 **| ensure the existence of a replacement before dropping old Bufs.)
263 **| Content in Buf can be anything in any format, but the mYarn_Form
264 **| implies the actual format by some caller-to-callee convention.
265 **| mYarn_Form==0 implies US-ASCII iso-8859-1 Latin1 string content.
267 **|| mYarn_Size: the physical size of Buf in bytes. Note that if one
268 **| intends to terminate a string with a null byte, that it must not
269 **| be written at or after mYarn_Buf[mYarn_Size] because this is after
270 **| the last byte in the physical buffer space. Size can be zero,
271 **| which means the string has no content whatsoever; note that when
272 **| Size is zero, this is a suitable reason for Buf==nil as well.
274 **|| mYarn_Fill: the logical content in Buf in bytes, where Fill must
275 **| never exceed mYarn_Size. Note that yarn strings might not have a
276 **| terminating null byte (since they might not even be C strings), but
277 **| when they do, such terminating nulls are considered part of content
278 **| and therefore Fill will count such null bytes. So an "empty" C
279 **| string will have Fill==1, because content includes one null byte.
280 **| Fill does not mean "length" when applied to C strings for this
281 **| reason. However, clients using yarns to hold C strings can infer
282 **| that length is equal to Fill-1 (but should take care to handle the
283 **| case where Fill==0). To be paranoid, one can always copy to a
284 **| destination with size exceeding Fill, and place a redundant null
285 **| byte in the Fill position when this simplifies matters.
287 **|| mYarn_Form: a designation of content format within mYarn_Buf.
288 **| The semantics of this slot are the least well defined, since the
289 **| actual meaning is context dependent, to the extent that callers
290 **| and callees must agree on format encoding conventions when such
291 **| are not standardized in many computing contexts. However, in the
292 **| context of a specific mdb database, mYarn_Form is a token for an
293 **| atomized string in that database that typically names a preferred
294 **| mime type charset designation. If and when mdbYarn is used for
295 **| other purposes away from the mdb interface, folks can use another
296 **| convention system for encoding content formats. However, in all
297 **| contexts is it useful to maintain the convention that Form==0
298 **| implies Buf contains US-ASCII iso-8859-1 Latin1 string content.
300 **|| mYarn_Grow: either a mdbYarn_mGrow method, or else nil. When
301 **| a mdbYarn_mGrow method is provided, this method can be used to
302 **| request a yarn buf size increase. A caller who constructs the
303 **| original mdbYarn instance decides whether a grow method is necessary
304 **| or desirable, and uses only grow methods suitable for the buffering
305 **| nature of a specific mdbYarn instance. (For example, Buf might be a
306 **| staticly allocated string space which switches to something heap-based
307 **| when grown, and subsequent calls to grow the yarn must distinguish the
308 **| original static string from heap allocated space, etc.) Note that the
309 **| method stored in mYarn_Grow can change, and this might be a common way
310 **| to track memory managent changes in policy for mYarn_Buf.
312 #ifndef mdbYarn_struct
313 #define mdbYarn_struct 1
314 struct mdbYarn { // buffer with caller space allocation semantics
315 void* mYarn_Buf; // space for holding any binary content
316 mdb_fill mYarn_Fill; // logical content in Buf in bytes
317 mdb_size mYarn_Size; // physical size of Buf in bytes
318 mdb_more mYarn_More; // more available bytes if Buf is bigger
319 mdb_cscode mYarn_Form; // charset format encoding
320 mdbYarn_mGrow mYarn_Grow; // optional method to grow mYarn_Buf
322 // Subclasses might add further slots after mYarn_Grow in order to
323 // maintain bookkeeping needs, such as state info about mYarn_Buf.
325 #endif /*mdbYarn_struct*/
327 // } %%%%% end C structs %%%%%
329 // { %%%%% begin class forward defines %%%%%
330 class nsIMdbEnv;
331 class nsIMdbObject;
332 class nsIMdbErrorHook;
333 class nsIMdbCompare;
334 class nsIMdbThumb;
335 class nsIMdbFactory;
336 class nsIMdbFile;
337 class nsIMdbPort;
338 class nsIMdbStore;
339 class nsIMdbCursor;
340 class nsIMdbPortTableCursor;
341 class nsIMdbCollection;
342 class nsIMdbTable;
343 class nsIMdbTableRowCursor;
344 class nsIMdbRow;
345 class nsIMdbRowCellCursor;
346 class nsIMdbBlob;
347 class nsIMdbCell;
348 class nsIMdbSorting;
349 // } %%%%% end class forward defines %%%%%
352 // { %%%%% begin C++ abstract class interfaces %%%%%
354 /*| nsIMdbObject: base class for all message db class interfaces
356 **|| factory: all nsIMdbObjects from the same code suite have the same factory
358 **|| refcounting: both strong and weak references, to ensure strong refs are
359 **| acyclic, while weak refs can cause cycles. CloseMdbObject() is
360 **| called when (strong) use counts hit zero, but clients can call this close
361 **| method early for some reason, if absolutely necessary even though it will
362 **| thwart the other uses of the same object. Note that implementations must
363 **| cope with close methods being called arbitrary numbers of times. The COM
364 **| calls to AddRef() and release ref map directly to strong use ref calls,
365 **| but the total ref count for COM objects is the sum of weak & strong refs.
368 #define NS_IMDBOBJECT_IID_STR "5533ea4b-14c3-4bef-ac60-22f9e9a49084"
370 #define NS_IMDBOBJECT_IID \
371 {0x5533ea4b, 0x14c3, 0x4bef, \
372 { 0xac, 0x60, 0x22, 0xf9, 0xe9, 0xa4, 0x90, 0x84}}
374 class nsIMdbObject : public nsISupports { // msg db base class
375 public:
377 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBOBJECT_IID)
378 // { ===== begin nsIMdbObject methods =====
380 // { ----- begin attribute methods -----
381 NS_IMETHOD IsFrozenMdbObject(nsIMdbEnv* ev, mdb_bool* outIsReadonly) = 0;
382 // same as nsIMdbPort::GetIsPortReadonly() when this object is inside a port.
383 // } ----- end attribute methods -----
385 // { ----- begin factory methods -----
386 NS_IMETHOD GetMdbFactory(nsIMdbEnv* ev, nsIMdbFactory** acqFactory) = 0;
387 // } ----- end factory methods -----
389 // { ----- begin ref counting for well-behaved cyclic graphs -----
390 NS_IMETHOD GetWeakRefCount(nsIMdbEnv* ev, // weak refs
391 mdb_count* outCount) = 0;
392 NS_IMETHOD GetStrongRefCount(nsIMdbEnv* ev, // strong refs
393 mdb_count* outCount) = 0;
395 NS_IMETHOD AddWeakRef(nsIMdbEnv* ev) = 0;
396 NS_IMETHOD AddStrongRef(nsIMdbEnv* ev) = 0;
398 NS_IMETHOD CutWeakRef(nsIMdbEnv* ev) = 0;
399 NS_IMETHOD CutStrongRef(nsIMdbEnv* ev) = 0;
401 NS_IMETHOD CloseMdbObject(nsIMdbEnv* ev) = 0; // called at strong refs zero
402 NS_IMETHOD IsOpenMdbObject(nsIMdbEnv* ev, mdb_bool* outOpen) = 0;
403 // } ----- end ref counting -----
405 // } ===== end nsIMdbObject methods =====
408 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbObject, NS_IMDBOBJECT_IID)
410 /*| nsIMdbErrorHook: a base class for clients of this API to subclass, in order
411 **| to provide a callback installable in nsIMdbEnv for error notifications. If
412 **| apps that subclass nsIMdbErrorHook wish to maintain a reference to the env
413 **| that contains the hook, then this should be a weak ref to avoid cycles.
415 **|| OnError: when nsIMdbEnv has an error condition that causes the total count
416 **| of errors to increase, then nsIMdbEnv should call OnError() to report the
417 **| error in some fashion when an instance of nsIMdbErrorHook is installed. The
418 **| variety of string flavors is currently due to the uncertainty here in the
419 **| nsIMdbBlob and nsIMdbCell interfaces. (Note that overloading by using the
420 **| same method name is not necessary here, and potentially less clear.)
422 class nsIMdbErrorHook : public nsISupports{ // env callback handler to report errors
423 public:
425 // { ===== begin error methods =====
426 NS_IMETHOD OnErrorString(nsIMdbEnv* ev, const char* inAscii) = 0;
427 NS_IMETHOD OnErrorYarn(nsIMdbEnv* ev, const mdbYarn* inYarn) = 0;
428 // } ===== end error methods =====
430 // { ===== begin warning methods =====
431 NS_IMETHOD OnWarningString(nsIMdbEnv* ev, const char* inAscii) = 0;
432 NS_IMETHOD OnWarningYarn(nsIMdbEnv* ev, const mdbYarn* inYarn) = 0;
433 // } ===== end warning methods =====
435 // { ===== begin abort hint methods =====
436 NS_IMETHOD OnAbortHintString(nsIMdbEnv* ev, const char* inAscii) = 0;
437 NS_IMETHOD OnAbortHintYarn(nsIMdbEnv* ev, const mdbYarn* inYarn) = 0;
438 // } ===== end abort hint methods =====
441 /*| nsIMdbCompare: a caller-supplied yarn comparison interface. When two yarns
442 **| are compared to each other with Order(), this method should return a signed
443 **| long integer denoting relation R between the 1st and 2nd yarn instances
444 **| such that (First R Second), where negative is less than, zero is equal to,
445 **| and positive is greater than. Note that both yarns are readonly, and the
446 **| Order() method should make no attempt to modify the yarn content.
448 class nsIMdbCompare { // caller-supplied yarn comparison
449 public:
451 // { ===== begin nsIMdbCompare methods =====
452 NS_IMETHOD Order(nsIMdbEnv* ev, // compare first to second yarn
453 const mdbYarn* inFirst, // first yarn in comparison
454 const mdbYarn* inSecond, // second yarn in comparison
455 mdb_order* outOrder) = 0; // negative="<", zero="=", positive=">"
457 NS_IMETHOD AddStrongRef(nsIMdbEnv* ev) = 0; // does nothing
458 NS_IMETHOD CutStrongRef(nsIMdbEnv* ev) = 0; // does nothing
459 // } ===== end nsIMdbCompare methods =====
463 /*| nsIMdbHeap: abstract memory allocation interface.
465 **|| Alloc: return a block at least inSize bytes in size with alignment
466 **| suitable for any native type (such as long integers). When no such
467 **| block can be allocated, failure is indicated by a null address in
468 **| addition to reporting an error in the environment.
470 **|| Free: deallocate a block allocated or resized earlier by the same
471 **| heap instance. If the inBlock parameter is nil, the heap should do
472 **| nothing (and crashing is strongly discouraged).
474 class nsIMdbHeap { // caller-supplied memory management interface
475 public:
476 // { ===== begin nsIMdbHeap methods =====
477 NS_IMETHOD Alloc(nsIMdbEnv* ev, // allocate a piece of memory
478 mdb_size inSize, // requested byte size of new memory block
479 void** outBlock) = 0; // memory block of inSize bytes, or nil
481 NS_IMETHOD Free(nsIMdbEnv* ev, // free block from Alloc or Resize()
482 void* ioBlock) = 0; // block to be destroyed/deallocated
484 NS_IMETHOD HeapAddStrongRef(nsIMdbEnv* ev) = 0;
485 NS_IMETHOD HeapCutStrongRef(nsIMdbEnv* ev) = 0;
487 // } ===== end nsIMdbHeap methods =====
490 /*| nsIMdbCPlusHeap: Alloc() with global ::new(), Free() with global ::delete().
491 **| Resize() is done by ::new() followed by ::delete().
493 class nsIMdbCPlusHeap { // caller-supplied memory management interface
494 public:
495 // { ===== begin nsIMdbHeap methods =====
496 NS_IMETHOD Alloc(nsIMdbEnv* ev, // allocate a piece of memory
497 mdb_size inSize, // requested size of new memory block
498 void** outBlock); // memory block of inSize bytes, or nil
500 NS_IMETHOD Free(nsIMdbEnv* ev, // free block allocated earlier by Alloc()
501 void* inBlock);
503 NS_IMETHOD HeapAddStrongRef(nsIMdbEnv* ev);
504 NS_IMETHOD HeapCutStrongRef(nsIMdbEnv* ev);
505 // } ===== end nsIMdbHeap methods =====
508 /*| nsIMdbThumb:
512 #define NS_IMDBTHUMB_IID_STR "6d3ad7c1-a809-4e74-8577-49fa9a4562fa"
514 #define NS_IMDBTHUMB_IID \
515 {0x6d3ad7c1, 0xa809, 0x4e74, \
516 { 0x85, 0x77, 0x49, 0xfa, 0x9a, 0x45, 0x62, 0xfa}}
519 class nsIMdbThumb : public nsISupports { // closure for repeating incremental method
520 public:
521 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBTHUMB_IID)
523 // { ===== begin nsIMdbThumb methods =====
524 NS_IMETHOD GetProgress(nsIMdbEnv* ev,
525 mdb_count* outTotal, // total somethings to do in operation
526 mdb_count* outCurrent, // subportion of total completed so far
527 mdb_bool* outDone, // is operation finished?
528 mdb_bool* outBroken // is operation irreparably dead and broken?
529 ) = 0;
531 NS_IMETHOD DoMore(nsIMdbEnv* ev,
532 mdb_count* outTotal, // total somethings to do in operation
533 mdb_count* outCurrent, // subportion of total completed so far
534 mdb_bool* outDone, // is operation finished?
535 mdb_bool* outBroken // is operation irreparably dead and broken?
536 ) = 0;
538 NS_IMETHOD CancelAndBreakThumb( // cancel pending operation
539 nsIMdbEnv* ev) = 0;
540 // } ===== end nsIMdbThumb methods =====
543 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbThumb, NS_IMDBTHUMB_IID)
545 /*| nsIMdbEnv: a context parameter used when calling most abstract db methods.
546 **| The main purpose of such an object is to permit a database implementation
547 **| to avoid the use of globals to share information between various parts of
548 **| the implementation behind the abstract db interface. An environment acts
549 **| like a session object for a given calling thread, and callers should use
550 **| at least one different nsIMdbEnv instance for each thread calling the API.
551 **| While the database implementation might not be threaded, it is highly
552 **| desirable that the db be thread-safe if calling threads use distinct
553 **| instances of nsIMdbEnv. Callers can stop at one nsIMdbEnv per thread, or they
554 **| might decide to make on nsIMdbEnv instance for every nsIMdbPort opened, so that
555 **| error information is segregated by database instance. Callers create
556 **| instances of nsIMdbEnv by calling the MakeEnv() method in nsIMdbFactory.
558 **|| tracing: an environment might support some kind of tracing, and this
559 **| boolean attribute permits such activity to be enabled or disabled.
561 **|| errors: when a call to the abstract db interface returns, a caller might
562 **| check the number of outstanding errors to see whether the operation did
563 **| actually succeed. Each nsIMdbEnv should have all its errors cleared by a
564 **| call to ClearErrors() before making each call to the abstract db API,
565 **| because outstanding errors might disable further database actions. (This
566 **| is not done inside the db interface, because the db cannot in general know
567 **| when a call originates from inside or outside -- only the app knows this.)
569 **|| error hook: callers can install an instance of nsIMdbErrorHook to receive
570 **| error notifications whenever the error count increases. The hook can
571 **| be uninstalled by passing a null pointer.
575 #define NS_IMDBENV_IID_STR "a765e46b-efb6-41e6-b75b-c5d6bd710594"
577 #define NS_IMDBENV_IID \
578 {0xa765e46b, 0xefb6, 0x41e6, \
579 { 0xb7, 0x5b, 0xc5, 0xd6, 0xbd, 0x71, 0x05, 0x94}}
581 class nsIMdbEnv : public nsISupports { // db specific context parameter
582 public:
584 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBENV_IID)
585 // { ===== begin nsIMdbEnv methods =====
587 // { ----- begin attribute methods -----
588 NS_IMETHOD GetErrorCount(mdb_count* outCount,
589 mdb_bool* outShouldAbort) = 0;
590 NS_IMETHOD GetWarningCount(mdb_count* outCount,
591 mdb_bool* outShouldAbort) = 0;
593 NS_IMETHOD GetEnvBeVerbose(mdb_bool* outBeVerbose) = 0;
594 NS_IMETHOD SetEnvBeVerbose(mdb_bool inBeVerbose) = 0;
596 NS_IMETHOD GetDoTrace(mdb_bool* outDoTrace) = 0;
597 NS_IMETHOD SetDoTrace(mdb_bool inDoTrace) = 0;
599 NS_IMETHOD GetAutoClear(mdb_bool* outAutoClear) = 0;
600 NS_IMETHOD SetAutoClear(mdb_bool inAutoClear) = 0;
602 NS_IMETHOD GetErrorHook(nsIMdbErrorHook** acqErrorHook) = 0;
603 NS_IMETHOD SetErrorHook(
604 nsIMdbErrorHook* ioErrorHook) = 0; // becomes referenced
606 NS_IMETHOD GetHeap(nsIMdbHeap** acqHeap) = 0;
607 NS_IMETHOD SetHeap(
608 nsIMdbHeap* ioHeap) = 0; // becomes referenced
609 // } ----- end attribute methods -----
611 NS_IMETHOD ClearErrors() = 0; // clear errors beore re-entering db API
612 NS_IMETHOD ClearWarnings() = 0; // clear warnings
613 NS_IMETHOD ClearErrorsAndWarnings() = 0; // clear both errors & warnings
614 // } ===== end nsIMdbEnv methods =====
617 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbEnv, NS_IMDBENV_IID)
619 /*| nsIMdbFactory: the main entry points to the abstract db interface. A DLL
620 **| that supports this mdb interface need only have a single exported method
621 **| that will return an instance of nsIMdbFactory, so that further methods in
622 **| the suite can be accessed from objects returned by nsIMdbFactory methods.
624 **|| mdbYarn: note all nsIMdbFactory subclasses must guarantee null
625 **| termination of all strings written into mdbYarn instances, as long as
626 **| mYarn_Size and mYarn_Buf are nonzero. Even truncated string values must
627 **| be null terminated. This is more strict behavior than mdbYarn requires,
628 **| but it is part of the nsIMdbFactory interface.
630 **|| envs: an environment instance is required as per-thread context for
631 **| most of the db method calls, so nsIMdbFactory creates such instances.
633 **|| rows: callers must be able to create row instances that are independent
634 **| of storage space that is part of the db content graph. Many interfaces
635 **| for data exchange have strictly copy semantics, so that a row instance
636 **| has no specific identity inside the db content model, and the text in
637 **| cells are an independenty copy of unexposed content inside the db model.
638 **| Callers are expected to maintain one or more row instances as a buffer
639 **| for staging cell content copied into or out of a table inside the db.
640 **| Callers are urged to use an instance of nsIMdbRow created by the nsIMdbFactory
641 **| code suite, because reading and writing might be much more efficient than
642 **| when using a hand-rolled nsIMdbRow subclass with no relation to the suite.
644 **|| ports: a port is a readonly interface to a specific database file. Most
645 **| of the methods to access a db file are suitable for a readonly interface,
646 **| so a port is the basic minimum for accessing content. This makes it
647 **| possible to read other external formats for import purposes, without
648 **| needing the code or competence necessary to write every such format. So
649 **| we can write generic import code just once, as long as every format can
650 **| show a face based on nsIMdbPort. (However, same suite import can be faster.)
651 **| Given a file name and the first 512 bytes of a file, a factory can say if
652 **| a port can be opened by this factory. Presumably an app maintains chains
653 **| of factories for different suites, and asks each in turn about opening a
654 **| a prospective file for reading (as a port) or writing (as a store). I'm
655 **| not ready to tackle issues of format fidelity and factory chain ordering.
657 **|| stores: a store is a mutable interface to a specific database file, and
658 **| includes the port interface plus any methods particular to writing, which
659 **| are few in number. Presumably the set of files that can be opened as
660 **| stores is a subset of the set of files that can be opened as ports. A
661 **| new store can be created with CreateNewFileStore() by supplying a new
662 **| file name which does not yet exist (callers are always responsible for
663 **| destroying any existing files before calling this method).
666 #define NS_IMDBFACTORY_IID_STR "2b80395c-b91e-4990-b1a7-023e99ab14e9"
668 #define NS_IMDBFACTORY_IID \
669 {0xf04aa4ab, 0x1fe, 0x4115, \
670 { 0xa4, 0xa5, 0x68, 0x19, 0xdf, 0xf1, 0x10, 0x3d}}
673 class nsIMdbFactory : public nsISupports { // suite entry points
674 public:
676 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBFACTORY_IID)
677 // { ===== begin nsIMdbFactory methods =====
679 // { ----- begin file methods -----
680 NS_IMETHOD OpenOldFile(nsIMdbEnv* ev, nsIMdbHeap* ioHeap,
681 const char* inFilePath,
682 mdb_bool inFrozen, nsIMdbFile** acqFile) = 0;
683 // Choose some subclass of nsIMdbFile to instantiate, in order to read
684 // (and write if not frozen) the file known by inFilePath. The file
685 // returned should be open and ready for use, and presumably positioned
686 // at the first byte position of the file. The exact manner in which
687 // files must be opened is considered a subclass specific detail, and
688 // other portions or Mork source code don't want to know how it's done.
690 NS_IMETHOD CreateNewFile(nsIMdbEnv* ev, nsIMdbHeap* ioHeap,
691 const char* inFilePath,
692 nsIMdbFile** acqFile) = 0;
693 // Choose some subclass of nsIMdbFile to instantiate, in order to read
694 // (and write if not frozen) the file known by inFilePath. The file
695 // returned should be created and ready for use, and presumably positioned
696 // at the first byte position of the file. The exact manner in which
697 // files must be opened is considered a subclass specific detail, and
698 // other portions or Mork source code don't want to know how it's done.
699 // } ----- end file methods -----
701 // { ----- begin env methods -----
702 NS_IMETHOD MakeEnv(nsIMdbHeap* ioHeap, nsIMdbEnv** acqEnv) = 0; // acquire new env
703 // ioHeap can be nil, causing a MakeHeap() style heap instance to be used
704 // } ----- end env methods -----
706 // { ----- begin heap methods -----
707 NS_IMETHOD MakeHeap(nsIMdbEnv* ev, nsIMdbHeap** acqHeap) = 0; // acquire new heap
708 // } ----- end heap methods -----
710 // { ----- begin compare methods -----
711 NS_IMETHOD MakeCompare(nsIMdbEnv* ev, nsIMdbCompare** acqCompare) = 0; // ASCII
712 // } ----- end compare methods -----
714 // { ----- begin row methods -----
715 NS_IMETHOD MakeRow(nsIMdbEnv* ev, nsIMdbHeap* ioHeap, nsIMdbRow** acqRow) = 0; // new row
716 // ioHeap can be nil, causing the heap associated with ev to be used
717 // } ----- end row methods -----
719 // { ----- begin port methods -----
720 NS_IMETHOD CanOpenFilePort(
721 nsIMdbEnv* ev, // context
722 // const char* inFilePath, // the file to investigate
723 // const mdbYarn* inFirst512Bytes,
724 nsIMdbFile* ioFile, // db abstract file interface
725 mdb_bool* outCanOpen, // whether OpenFilePort() might succeed
726 mdbYarn* outFormatVersion) = 0; // informal file format description
728 NS_IMETHOD OpenFilePort(
729 nsIMdbEnv* ev, // context
730 nsIMdbHeap* ioHeap, // can be nil to cause ev's heap attribute to be used
731 // const char* inFilePath, // the file to open for readonly import
732 nsIMdbFile* ioFile, // db abstract file interface
733 const mdbOpenPolicy* inOpenPolicy, // runtime policies for using db
734 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental port open
735 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
736 // then call nsIMdbFactory::ThumbToOpenPort() to get the port instance.
738 NS_IMETHOD ThumbToOpenPort( // redeeming a completed thumb from OpenFilePort()
739 nsIMdbEnv* ev, // context
740 nsIMdbThumb* ioThumb, // thumb from OpenFilePort() with done status
741 nsIMdbPort** acqPort) = 0; // acquire new port object
742 // } ----- end port methods -----
744 // { ----- begin store methods -----
745 NS_IMETHOD CanOpenFileStore(
746 nsIMdbEnv* ev, // context
747 // const char* inFilePath, // the file to investigate
748 // const mdbYarn* inFirst512Bytes,
749 nsIMdbFile* ioFile, // db abstract file interface
750 mdb_bool* outCanOpenAsStore, // whether OpenFileStore() might succeed
751 mdb_bool* outCanOpenAsPort, // whether OpenFilePort() might succeed
752 mdbYarn* outFormatVersion) = 0; // informal file format description
754 NS_IMETHOD OpenFileStore( // open an existing database
755 nsIMdbEnv* ev, // context
756 nsIMdbHeap* ioHeap, // can be nil to cause ev's heap attribute to be used
757 // const char* inFilePath, // the file to open for general db usage
758 nsIMdbFile* ioFile, // db abstract file interface
759 const mdbOpenPolicy* inOpenPolicy, // runtime policies for using db
760 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental store open
761 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
762 // then call nsIMdbFactory::ThumbToOpenStore() to get the store instance.
764 NS_IMETHOD
765 ThumbToOpenStore( // redeem completed thumb from OpenFileStore()
766 nsIMdbEnv* ev, // context
767 nsIMdbThumb* ioThumb, // thumb from OpenFileStore() with done status
768 nsIMdbStore** acqStore) = 0; // acquire new db store object
770 NS_IMETHOD CreateNewFileStore( // create a new db with minimal content
771 nsIMdbEnv* ev, // context
772 nsIMdbHeap* ioHeap, // can be nil to cause ev's heap attribute to be used
773 // const char* inFilePath, // name of file which should not yet exist
774 nsIMdbFile* ioFile, // db abstract file interface
775 const mdbOpenPolicy* inOpenPolicy, // runtime policies for using db
776 nsIMdbStore** acqStore) = 0; // acquire new db store object
777 // } ----- end store methods -----
779 // } ===== end nsIMdbFactory methods =====
782 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbFactory, NS_IMDBFACTORY_IID)
784 extern "C" nsIMdbFactory* MakeMdbFactory();
786 /*| nsIMdbFile: abstract file interface resembling the original morkFile
787 **| abstract interface (which was in turn modeled on the file interface
788 **| from public domain IronDoc). The design of this file interface is
789 **| complicated by the fact that some DB's will not find this interface
790 **| adequate for all runtime requirements (even though this file API is
791 **| enough to implement text-based DB's like Mork). For this reason,
792 **| more methods have been added to let a DB library force the file to
793 **| become closed so the DB can reopen the file in some other manner.
794 **| Folks are encouraged to suggest ways to tune this interface to suit
795 **| DB's that cannot manage to pull their maneuvers even given this API.
797 **|| Tell: get the current i/o position in file
799 **|| Seek: change the current i/o position in file
801 **|| Eof: return file's total length in bytes
803 **|| Read: input inSize bytes into outBuf, returning actual transfer size
805 **|| Get: read starting at specific file offset (e.g. Seek(); Read();)
807 **|| Write: output inSize bytes from inBuf, returning actual transfer size
809 **|| Put: write starting at specific file offset (e.g. Seek(); Write();)
811 **|| Flush: if written bytes are buffered, push them to final destination
813 **|| Path: get file path in some string representation. This is intended
814 **| either to support the display of file name in a user presentation, or
815 **| to support the closing and reopening of the file when the DB needs more
816 **| exotic file access than is presented by the nsIMdbFile interface.
818 **|| Steal: tell this file to close any associated i/o stream in the file
819 **| system, because the file ioThief intends to reopen the file in order
820 **| to provide the MDB implementation with more exotic file access than is
821 **| offered by the nsIMdbFile alone. Presumably the thief knows enough
822 **| from Path() in order to know which file to reopen. If Steal() is
823 **| successful, this file should probably delegate all future calls to
824 **| the nsIMdbFile interface down to the thief files, so that even after
825 **| the file has been stolen, it can still be read, written, or forcibly
826 **| closed (by a call to CloseMdbObject()).
828 **|| Thief: acquire and return thief passed to an earlier call to Steal().
831 #define NS_IMDBFILE_IID_STR "f04aa4ab-1fe7-4115-a4a5-6819dff1103d"
833 #define NS_IMDBFILE_IID \
834 {0xf04aa4ab, 0x1fe, 0x4115, \
835 { 0xa4, 0xa5, 0x68, 0x19, 0xdf, 0xf1, 0x10, 0x3d}}
837 class nsIMdbFile : public nsISupports { // minimal file interface
838 public:
840 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBFILE_IID)
841 // { ===== begin nsIMdbFile methods =====
843 // { ----- begin pos methods -----
844 NS_IMETHOD Tell(nsIMdbEnv* ev, mdb_pos* outPos) const = 0;
845 NS_IMETHOD Seek(nsIMdbEnv* ev, mdb_pos inPos, mdb_pos *outPos) = 0;
846 NS_IMETHOD Eof(nsIMdbEnv* ev, mdb_pos* outPos) = 0;
847 // } ----- end pos methods -----
849 // { ----- begin read methods -----
850 NS_IMETHOD Read(nsIMdbEnv* ev, void* outBuf, mdb_size inSize,
851 mdb_size* outActualSize) = 0;
852 NS_IMETHOD Get(nsIMdbEnv* ev, void* outBuf, mdb_size inSize,
853 mdb_pos inPos, mdb_size* outActualSize) = 0;
854 // } ----- end read methods -----
856 // { ----- begin write methods -----
857 NS_IMETHOD Write(nsIMdbEnv* ev, const void* inBuf, mdb_size inSize,
858 mdb_size* outActualSize) = 0;
859 NS_IMETHOD Put(nsIMdbEnv* ev, const void* inBuf, mdb_size inSize,
860 mdb_pos inPos, mdb_size* outActualSize) = 0;
861 NS_IMETHOD Flush(nsIMdbEnv* ev) = 0;
862 // } ----- end attribute methods -----
864 // { ----- begin path methods -----
865 NS_IMETHOD Path(nsIMdbEnv* ev, mdbYarn* outFilePath) = 0;
866 // } ----- end path methods -----
868 // { ----- begin replacement methods -----
869 NS_IMETHOD Steal(nsIMdbEnv* ev, nsIMdbFile* ioThief) = 0;
870 NS_IMETHOD Thief(nsIMdbEnv* ev, nsIMdbFile** acqThief) = 0;
871 // } ----- end replacement methods -----
873 // { ----- begin versioning methods -----
874 NS_IMETHOD BecomeTrunk(nsIMdbEnv* ev) = 0;
875 // If this file is a file version branch created by calling AcquireBud(),
876 // BecomeTrunk() causes this file's content to replace the original
877 // file's content, typically by assuming the original file's identity.
878 // This default implementation of BecomeTrunk() does nothing, and this
879 // is appropriate behavior for files which are not branches, and is
880 // also the right behavior for files returned from AcquireBud() which are
881 // in fact the original file that has been truncated down to zero length.
883 NS_IMETHOD AcquireBud(nsIMdbEnv* ev, nsIMdbHeap* ioHeap,
884 nsIMdbFile** acqBud) = 0; // acquired file for new version of content
885 // AcquireBud() starts a new "branch" version of the file, empty of content,
886 // so that a new version of the file can be written. This new file
887 // can later be told to BecomeTrunk() the original file, so the branch
888 // created by budding the file will replace the original file. Some
889 // file subclasses might initially take the unsafe but expedient
890 // approach of simply truncating this file down to zero length, and
891 // then returning the same morkFile pointer as this, with an extra
892 // reference count increment. Note that the caller of AcquireBud() is
893 // expected to eventually call CutStrongRef() on the returned file
894 // in order to release the strong reference. High quality versions
895 // of morkFile subclasses will create entirely new files which later
896 // are renamed to become the old file, so that better transactional
897 // behavior is exhibited by the file, so crashes protect old files.
898 // Note that AcquireBud() is an illegal operation on readonly files.
899 // } ----- end versioning methods -----
901 // } ===== end nsIMdbFile methods =====
904 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbFile, NS_IMDBFILE_IID)
906 /*| nsIMdbPort: a readonly interface to a specific database file. The mutable
907 **| nsIMdbStore interface is a subclass that includes writing behavior, but
908 **| most of the needed db methods appear in the readonly nsIMdbPort interface.
910 **|| mdbYarn: note all nsIMdbPort and nsIMdbStore subclasses must guarantee null
911 **| termination of all strings written into mdbYarn instances, as long as
912 **| mYarn_Size and mYarn_Buf are nonzero. Even truncated string values must
913 **| be null terminated. This is more strict behavior than mdbYarn requires,
914 **| but it is part of the nsIMdbPort and nsIMdbStore interface.
916 **|| attributes: methods are provided to distinguish a readonly port from a
917 **| mutable store, and whether a mutable store actually has any dirty content.
919 **|| filepath: the file path used to open the port from the nsIMdbFactory can be
920 **| queried and discovered by GetPortFilePath(), which includes format info.
922 **|| export: a port can write itself in other formats, with perhaps a typical
923 **| emphasis on text interchange formats used by other systems. A port can be
924 **| queried to determine its preferred export interchange format, and a port
925 **| can be queried to see whether a specific export format is supported. And
926 **| actually exporting a port requires a new destination file name and format.
928 **|| tokens: a port supports queries about atomized strings to map tokens to
929 **| strings or strings to token integers. (All atomized strings must be in
930 **| US-ASCII iso-8859-1 Latin1 charset encoding.) When a port is actually a
931 **| mutable store and a string has not yet been atomized, then StringToToken()
932 **| will actually do so and modify the store. The QueryToken() method will not
933 **| atomize a string if it has not already been atomized yet, even in stores.
935 **|| tables: other than string tokens, all port content is presented through
936 **| tables, which are ordered collections of rows. Tables are identified by
937 **| row scope and table kind, which might or might not be unique in a port,
938 **| depending on app convention. When tables are effectively unique, then
939 **| queries for specific scope and kind pairs will find those tables. To see
940 **| all tables that match specific row scope and table kind patterns, even in
941 **| the presence of duplicates, every port supports a GetPortTableCursor()
942 **| method that returns an iterator over all matching tables. Table kind is
943 **| considered scoped inside row scope, so passing a zero for table kind will
944 **| find all table kinds for some nonzero row scope. Passing a zero for row
945 **| scope will iterate over all tables in the port, in some undefined order.
946 **| (A new table can be added to a port using nsIMdbStore::NewTable(), even when
947 **| the requested scope and kind combination is already used by other tables.)
949 **|| memory: callers can request that a database use less memory footprint in
950 **| several flavors, from an inconsequential idle flavor to a rather drastic
951 **| panic flavor. Callers might perform an idle purge very frequently if desired
952 **| with very little cost, since only normally scheduled memory management will
953 **| be conducted, such as freeing resources for objects scheduled to be dropped.
954 **| Callers should perform session memory purges infrequently because they might
955 **| involve costly scanning of data structures to removed cached content, and
956 **| session purges are recommended only when a caller experiences memory crunch.
957 **| Callers should only rarely perform a panic purge, in response to dire memory
958 **| straits, since this is likely to make db operations much more expensive
959 **| than they would be otherwise. A panic purge asks a database to free as much
960 **| memory as possible while staying effective and operational, because a caller
961 **| thinks application failure might otherwise occur. (Apps might better close
962 **| an open db, so panic purges only make sense when a db is urgently needed.)
964 class nsIMdbPort : public nsISupports {
965 public:
967 // { ===== begin nsIMdbPort methods =====
969 // { ----- begin attribute methods -----
970 NS_IMETHOD GetIsPortReadonly(nsIMdbEnv* ev, mdb_bool* outBool) = 0;
971 NS_IMETHOD GetIsStore(nsIMdbEnv* ev, mdb_bool* outBool) = 0;
972 NS_IMETHOD GetIsStoreAndDirty(nsIMdbEnv* ev, mdb_bool* outBool) = 0;
974 NS_IMETHOD GetUsagePolicy(nsIMdbEnv* ev,
975 mdbUsagePolicy* ioUsagePolicy) = 0;
977 NS_IMETHOD SetUsagePolicy(nsIMdbEnv* ev,
978 const mdbUsagePolicy* inUsagePolicy) = 0;
979 // } ----- end attribute methods -----
981 // { ----- begin memory policy methods -----
982 NS_IMETHOD IdleMemoryPurge( // do memory management already scheduled
983 nsIMdbEnv* ev, // context
984 mdb_size* outEstimatedBytesFreed) = 0; // approximate bytes actually freed
986 NS_IMETHOD SessionMemoryPurge( // request specific footprint decrease
987 nsIMdbEnv* ev, // context
988 mdb_size inDesiredBytesFreed, // approximate number of bytes wanted
989 mdb_size* outEstimatedBytesFreed) = 0; // approximate bytes actually freed
991 NS_IMETHOD PanicMemoryPurge( // desperately free all possible memory
992 nsIMdbEnv* ev, // context
993 mdb_size* outEstimatedBytesFreed) = 0; // approximate bytes actually freed
994 // } ----- end memory policy methods -----
996 // { ----- begin filepath methods -----
997 NS_IMETHOD GetPortFilePath(
998 nsIMdbEnv* ev, // context
999 mdbYarn* outFilePath, // name of file holding port content
1000 mdbYarn* outFormatVersion) = 0; // file format description
1002 NS_IMETHOD GetPortFile(
1003 nsIMdbEnv* ev, // context
1004 nsIMdbFile** acqFile) = 0; // acquire file used by port or store
1005 // } ----- end filepath methods -----
1007 // { ----- begin export methods -----
1008 NS_IMETHOD BestExportFormat( // determine preferred export format
1009 nsIMdbEnv* ev, // context
1010 mdbYarn* outFormatVersion) = 0; // file format description
1012 // some tentative suggested import/export formats
1013 // "ns:msg:db:port:format:ldif:ns4.0:passthrough" // necessary
1014 // "ns:msg:db:port:format:ldif:ns4.5:utf8" // necessary
1015 // "ns:msg:db:port:format:ldif:ns4.5:tabbed"
1016 // "ns:msg:db:port:format:ldif:ns4.5:binary" // necessary
1017 // "ns:msg:db:port:format:html:ns3.0:addressbook" // necessary
1018 // "ns:msg:db:port:format:html:display:verbose"
1019 // "ns:msg:db:port:format:html:display:concise"
1020 // "ns:msg:db:port:format:mork:zany:verbose" // necessary
1021 // "ns:msg:db:port:format:mork:zany:atomized" // necessary
1022 // "ns:msg:db:port:format:rdf:xml"
1023 // "ns:msg:db:port:format:xml:mork"
1024 // "ns:msg:db:port:format:xml:display:verbose"
1025 // "ns:msg:db:port:format:xml:display:concise"
1026 // "ns:msg:db:port:format:xml:print:verbose" // recommended
1027 // "ns:msg:db:port:format:xml:print:concise"
1029 NS_IMETHOD
1030 CanExportToFormat( // can export content in given specific format?
1031 nsIMdbEnv* ev, // context
1032 const char* inFormatVersion, // file format description
1033 mdb_bool* outCanExport) = 0; // whether ExportSource() might succeed
1035 NS_IMETHOD ExportToFormat( // export content in given specific format
1036 nsIMdbEnv* ev, // context
1037 // const char* inFilePath, // the file to receive exported content
1038 nsIMdbFile* ioFile, // destination abstract file interface
1039 const char* inFormatVersion, // file format description
1040 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental export
1041 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
1042 // then the export will be finished.
1044 // } ----- end export methods -----
1046 // { ----- begin token methods -----
1047 NS_IMETHOD TokenToString( // return a string name for an integer token
1048 nsIMdbEnv* ev, // context
1049 mdb_token inToken, // token for inTokenName inside this port
1050 mdbYarn* outTokenName) = 0; // the type of table to access
1052 NS_IMETHOD StringToToken( // return an integer token for scope name
1053 nsIMdbEnv* ev, // context
1054 const char* inTokenName, // Latin1 string to tokenize if possible
1055 mdb_token* outToken) = 0; // token for inTokenName inside this port
1057 // String token zero is never used and never supported. If the port
1058 // is a mutable store, then StringToToken() to create a new
1059 // association of inTokenName with a new integer token if possible.
1060 // But a readonly port will return zero for an unknown scope name.
1062 NS_IMETHOD QueryToken( // like StringToToken(), but without adding
1063 nsIMdbEnv* ev, // context
1064 const char* inTokenName, // Latin1 string to tokenize if possible
1065 mdb_token* outToken) = 0; // token for inTokenName inside this port
1067 // QueryToken() will return a string token if one already exists,
1068 // but unlike StringToToken(), will not assign a new token if not
1069 // already in use.
1071 // } ----- end token methods -----
1073 // { ----- begin row methods -----
1074 NS_IMETHOD HasRow( // contains a row with the specified oid?
1075 nsIMdbEnv* ev, // context
1076 const mdbOid* inOid, // hypothetical row oid
1077 mdb_bool* outHasRow) = 0; // whether GetRow() might succeed
1079 NS_IMETHOD GetRowRefCount( // get number of tables that contain a row
1080 nsIMdbEnv* ev, // context
1081 const mdbOid* inOid, // hypothetical row oid
1082 mdb_count* outRefCount) = 0; // number of tables containing inRowKey
1084 NS_IMETHOD GetRow( // access one row with specific oid
1085 nsIMdbEnv* ev, // context
1086 const mdbOid* inOid, // hypothetical row oid
1087 nsIMdbRow** acqRow) = 0; // acquire specific row (or null)
1089 // NS_IMETHOD
1090 // GetPortRowCursor( // get cursor for all rows in specific scope
1091 // nsIMdbEnv* ev, // context
1092 // mdb_scope inRowScope, // row scope for row ids
1093 // nsIMdbPortRowCursor** acqCursor) = 0; // all such rows in the port
1095 NS_IMETHOD FindRow(nsIMdbEnv* ev, // search for row with matching cell
1096 mdb_scope inRowScope, // row scope for row ids
1097 mdb_column inColumn, // the column to search (and maintain an index)
1098 const mdbYarn* inTargetCellValue, // cell value for which to search
1099 mdbOid* outRowOid, // out row oid on match (or {0,-1} for no match)
1100 nsIMdbRow** acqRow) = 0; // acquire matching row (or nil for no match)
1101 // can be null if you only want the oid
1102 // FindRow() searches for one row that has a cell in column inColumn with
1103 // a contained value with the same form (i.e. charset) and is byte-wise
1104 // identical to the blob described by yarn inTargetCellValue. Both content
1105 // and form of the yarn must be an exact match to find a matching row.
1107 // (In other words, both a yarn's blob bytes and form are significant. The
1108 // form is not expected to vary in columns used for identity anyway. This
1109 // is intended to make the cost of FindRow() cheaper for MDB implementors,
1110 // since any cell value atomization performed internally must necessarily
1111 // make yarn form significant in order to avoid data loss in atomization.)
1113 // FindRow() can lazily create an index on attribute inColumn for all rows
1114 // with that attribute in row space scope inRowScope, so that subsequent
1115 // calls to FindRow() will perform faster. Such an index might or might
1116 // not be persistent (but this seems desirable if it is cheap to do so).
1117 // Note that lazy index creation in readonly DBs is not very feasible.
1119 // This FindRow() interface assumes that attribute inColumn is effectively
1120 // an alternative means of unique identification for a row in a rowspace,
1121 // so correct behavior is only guaranteed when no duplicates for this col
1122 // appear in the given set of rows. (If more than one row has the same cell
1123 // value in this column, no more than one will be found; and cutting one of
1124 // two duplicate rows can cause the index to assume no other such row lives
1125 // in the row space, so future calls return nil for negative search results
1126 // even though some duplicate row might still live within the rowspace.)
1128 // In other words, the FindRow() implementation is allowed to assume simple
1129 // hash tables mapping unqiue column keys to associated row values will be
1130 // sufficient, where any duplication is not recorded because only one copy
1131 // of a given key need be remembered. Implementors are not required to sort
1132 // all rows by the specified column.
1133 // } ----- end row methods -----
1135 // { ----- begin table methods -----
1136 NS_IMETHOD HasTable( // supports a table with the specified oid?
1137 nsIMdbEnv* ev, // context
1138 const mdbOid* inOid, // hypothetical table oid
1139 mdb_bool* outHasTable) = 0; // whether GetTable() might succeed
1141 NS_IMETHOD GetTable( // access one table with specific oid
1142 nsIMdbEnv* ev, // context
1143 const mdbOid* inOid, // hypothetical table oid
1144 nsIMdbTable** acqTable) = 0; // acquire specific table (or null)
1146 NS_IMETHOD HasTableKind( // supports a table of the specified type?
1147 nsIMdbEnv* ev, // context
1148 mdb_scope inRowScope, // rid scope for row ids
1149 mdb_kind inTableKind, // the type of table to access
1150 mdb_count* outTableCount, // current number of such tables
1151 mdb_bool* outSupportsTable) = 0; // whether GetTableKind() might succeed
1153 // row scopes to be supported include the following suggestions:
1154 // "ns:msg:db:row:scope:address:cards:all"
1155 // "ns:msg:db:row:scope:mail:messages:all"
1156 // "ns:msg:db:row:scope:news:articles:all"
1158 // table kinds to be supported include the following suggestions:
1159 // "ns:msg:db:table:kind:address:cards:main"
1160 // "ns:msg:db:table:kind:address:lists:all"
1161 // "ns:msg:db:table:kind:address:list"
1162 // "ns:msg:db:table:kind:news:threads:all"
1163 // "ns:msg:db:table:kind:news:thread"
1164 // "ns:msg:db:table:kind:mail:threads:all"
1165 // "ns:msg:db:table:kind:mail:thread"
1167 NS_IMETHOD GetTableKind( // access one (random) table of specific type
1168 nsIMdbEnv* ev, // context
1169 mdb_scope inRowScope, // row scope for row ids
1170 mdb_kind inTableKind, // the type of table to access
1171 mdb_count* outTableCount, // current number of such tables
1172 mdb_bool* outMustBeUnique, // whether port can hold only one of these
1173 nsIMdbTable** acqTable) = 0; // acquire scoped collection of rows
1175 NS_IMETHOD
1176 GetPortTableCursor( // get cursor for all tables of specific type
1177 nsIMdbEnv* ev, // context
1178 mdb_scope inRowScope, // row scope for row ids
1179 mdb_kind inTableKind, // the type of table to access
1180 nsIMdbPortTableCursor** acqCursor) = 0; // all such tables in the port
1181 // } ----- end table methods -----
1184 // { ----- begin commit methods -----
1186 NS_IMETHOD ShouldCompress( // store wastes at least inPercentWaste?
1187 nsIMdbEnv* ev, // context
1188 mdb_percent inPercentWaste, // 0..100 percent file size waste threshold
1189 mdb_percent* outActualWaste, // 0..100 percent of file actually wasted
1190 mdb_bool* outShould) = 0; // true when about inPercentWaste% is wasted
1191 // ShouldCompress() returns true if the store can determine that the file
1192 // will shrink by an estimated percentage of inPercentWaste% (or more) if
1193 // CompressCommit() is called, because that percentage of the file seems
1194 // to be recoverable free space. The granularity is only in terms of
1195 // percentage points, and any value over 100 is considered equal to 100.
1197 // If a store only has an approximate idea how much space might be saved
1198 // during a compress, then a best guess should be made. For example, the
1199 // Mork implementation might keep track of how much file space began with
1200 // text content before the first updating transaction, and then consider
1201 // all content following the start of the first transaction as potentially
1202 // wasted space if it is all updates and not just new content. (This is
1203 // a safe assumption in the sense that behavior will stabilize on a low
1204 // estimate of wastage after a commit removes all transaction updates.)
1206 // Some db formats might attempt to keep a very accurate reckoning of free
1207 // space size, so a very accurate determination can be made. But other db
1208 // formats might have difficulty determining size of free space, and might
1209 // require some lengthy calculation to answer. This is the reason for
1210 // passing in the percentage threshold of interest, so that such lengthy
1211 // computations can terminate early as soon as at least inPercentWaste is
1212 // found, so that the entire file need not be groveled when unnecessary.
1213 // However, we hope implementations will always favor fast but imprecise
1214 // heuristic answers instead of extremely slow but very precise answers.
1216 // If the outActualWaste parameter is non-nil, it will be used to return
1217 // the actual estimated space wasted as a percentage of file size. (This
1218 // parameter is provided so callers need not call repeatedly with altered
1219 // inPercentWaste values to isolate the actual wastage figure.) Note the
1220 // actual wastage figure returned can exactly equal inPercentWaste even
1221 // when this grossly underestimates the real figure involved, if the db
1222 // finds it very expensive to determine the extent of wastage after it is
1223 // known to at least exceed inPercentWaste. Note we expect that whenever
1224 // outShould returns true, that outActualWaste returns >= inPercentWaste.
1226 // The effect of different inPercentWaste values is not very uniform over
1227 // the permitted range. For example, 50 represents 50% wastage, or a file
1228 // that is about double what it should be ideally. But 99 represents 99%
1229 // wastage, or a file that is about ninety-nine times as big as it should
1230 // be ideally. In the smaller direction, 25 represents 25% wastage, or
1231 // a file that is only 33% larger than it should be ideally.
1233 // Callers can determine what policy they want to use for considering when
1234 // a file holds too much wasted space, and express this as a percentage
1235 // of total file size to pass as in the inPercentWaste parameter. A zero
1236 // likely returns always trivially true, and 100 always trivially false.
1237 // The great majority of callers are expected to use values from 25 to 75,
1238 // since most plausible thresholds for compressing might fall between the
1239 // extremes of 133% of ideal size and 400% of ideal size. (Presumably the
1240 // larger a file gets, the more important the percentage waste involved, so
1241 // a sliding scale for compress thresholds might use smaller numbers for
1242 // much bigger file sizes.)
1244 // } ----- end commit methods -----
1246 // } ===== end nsIMdbPort methods =====
1249 /*| nsIMdbStore: a mutable interface to a specific database file.
1251 **|| tables: one can force a new table to exist in a store with NewTable()
1252 **| and nonzero values for both row scope and table kind. (If one wishes only
1253 **| one table of a certain kind, then one might look for it first using the
1254 **| GetTableKind() method). One can pass inMustBeUnique to force future
1255 **| users of this store to be unable to create other tables with the same pair
1256 **| of scope and kind attributes. When inMustBeUnique is true, and the table
1257 **| with the given scope and kind pair already exists, then the existing one
1258 **| is returned instead of making a new table. Similarly, if one passes false
1259 **| for inMustBeUnique, but the table kind has already been marked unique by a
1260 **| previous user of the store, then the existing unique table is returned.
1262 **|| import: all or some of another port's content can be imported by calling
1263 **| AddPortContent() with a row scope identifying the extent of content to
1264 **| be imported. A zero row scope will import everything. A nonzero row
1265 **| scope will only import tables with a matching row scope. Note that one
1266 **| must somehow find a way to negotiate possible conflicts between existing
1267 **| row content and imported row content, and this involves a specific kind of
1268 **| definition for row identity involving either row IDs or unique attributes,
1269 **| or some combination of these two. At the moment I am just going to wave
1270 **| my hands, and say the default behavior is to assign all new row identities
1271 **| to all imported content, which will result in no merging of content; this
1272 **| must change later because it is unacceptable in some contexts.
1274 **|| commits: to manage modifications in a mutable store, very few methods are
1275 **| really needed to indicate global policy choices that are independent of
1276 **| the actual modifications that happen in objects at the level of tables,
1277 **| rows, and cells, etc. The most important policy to specify is which sets
1278 **| of changes are considered associated in a manner such that they should be
1279 **| applied together atomically to a given store. We call each such group of
1280 **| changes a transaction. We handle three different grades of transaction,
1281 **| but they differ only in semantic significance to the application, and are
1282 **| not intended to nest. (If small transactions were nested inside large
1283 **| transactions, that would imply that a single large transaction must be
1284 **| atomic over all the contained small transactions; but actually we intend
1285 **| smalls transaction never be undone once commited due to, say, aborting a
1286 **| transaction of greater significance.) The small, large, and session level
1287 **| commits have equal granularity, and differ only in risk of loss from the
1288 **| perspective of an application. Small commits characterize changes that
1289 **| can be lost with relatively small risk, so small transactions can delay
1290 **| until later if they are expensive or impractical to commit. Large commits
1291 **| involve changes that would probably inconvenience users if lost, so the
1292 **| need to pay costs of writing is rather greater than with small commits.
1293 **| Session commits are last ditch attempts to save outstanding changes before
1294 **| stopping the use of a particular database, so there will be no later point
1295 **| in time to save changes that have been delayed due to possible high cost.
1296 **| If large commits are never delayed, then a session commit has about the
1297 **| same performance effect as another large commit; but if small and large
1298 **| commits are always delayed, then a session commit is likely to be rather
1299 **| expensive as a runtime cost compared to any earlier database usage.
1301 **|| aborts: the only way to abort changes to a store is by closing the store.
1302 **| So there is no specific method for causing any abort. Stores must discard
1303 **| all changes made that are uncommited when a store is closed. This design
1304 **| choice makes the implementations of tables, rows, and cells much less
1305 **| complex because they need not maintain a record of undobable changes. When
1306 **| a store is closed, presumably this precipitates the closure of all tables,
1307 **| rows, and cells in the store as well. So an application can revert the
1308 **| state of a store in the user interface by quietly closing and reopening a
1309 **| store, because this will discard uncommited changes and show old content.
1310 **| This implies an app that closes a store will need to send a "scramble"
1311 **| event notification to any views that depend on old discarded content.
1314 #define NS_IMDBSTORE_IID_STR "726618d3-f15b-49b9-9f4a-efcc9db53d0d"
1316 #define NS_IMDBSTORE_IID \
1317 {0x726618d3, 0xf15b, 0x49b9, \
1318 {0x9f, 0x4a, 0xef, 0xcc, 0x9d, 0xb5, 0x3d, 0x0d}}
1320 class nsIMdbStore : public nsIMdbPort {
1321 public:
1322 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBSTORE_IID)
1324 // { ===== begin nsIMdbStore methods =====
1326 // { ----- begin table methods -----
1327 NS_IMETHOD NewTable( // make one new table of specific type
1328 nsIMdbEnv* ev, // context
1329 mdb_scope inRowScope, // row scope for row ids
1330 mdb_kind inTableKind, // the type of table to access
1331 mdb_bool inMustBeUnique, // whether store can hold only one of these
1332 const mdbOid* inOptionalMetaRowOid, // can be nil to avoid specifying
1333 nsIMdbTable** acqTable) = 0; // acquire scoped collection of rows
1335 NS_IMETHOD NewTableWithOid( // make one new table of specific type
1336 nsIMdbEnv* ev, // context
1337 const mdbOid* inOid, // caller assigned oid
1338 mdb_kind inTableKind, // the type of table to access
1339 mdb_bool inMustBeUnique, // whether store can hold only one of these
1340 const mdbOid* inOptionalMetaRowOid, // can be nil to avoid specifying
1341 nsIMdbTable** acqTable) = 0; // acquire scoped collection of rows
1342 // } ----- end table methods -----
1344 // { ----- begin row scope methods -----
1345 NS_IMETHOD RowScopeHasAssignedIds(nsIMdbEnv* ev,
1346 mdb_scope inRowScope, // row scope for row ids
1347 mdb_bool* outCallerAssigned, // nonzero if caller assigned specified
1348 mdb_bool* outStoreAssigned) = 0; // nonzero if store db assigned specified
1350 NS_IMETHOD SetCallerAssignedIds(nsIMdbEnv* ev,
1351 mdb_scope inRowScope, // row scope for row ids
1352 mdb_bool* outCallerAssigned, // nonzero if caller assigned specified
1353 mdb_bool* outStoreAssigned) = 0; // nonzero if store db assigned specified
1355 NS_IMETHOD SetStoreAssignedIds(nsIMdbEnv* ev,
1356 mdb_scope inRowScope, // row scope for row ids
1357 mdb_bool* outCallerAssigned, // nonzero if caller assigned specified
1358 mdb_bool* outStoreAssigned) = 0; // nonzero if store db assigned specified
1359 // } ----- end row scope methods -----
1361 // { ----- begin row methods -----
1362 NS_IMETHOD NewRowWithOid(nsIMdbEnv* ev, // new row w/ caller assigned oid
1363 const mdbOid* inOid, // caller assigned oid
1364 nsIMdbRow** acqRow) = 0; // create new row
1366 NS_IMETHOD NewRow(nsIMdbEnv* ev, // new row with db assigned oid
1367 mdb_scope inRowScope, // row scope for row ids
1368 nsIMdbRow** acqRow) = 0; // create new row
1369 // Note this row must be added to some table or cell child before the
1370 // store is closed in order to make this row persist across sesssions.
1372 // } ----- end row methods -----
1374 // { ----- begin inport/export methods -----
1375 NS_IMETHOD ImportContent( // import content from port
1376 nsIMdbEnv* ev, // context
1377 mdb_scope inRowScope, // scope for rows (or zero for all?)
1378 nsIMdbPort* ioPort, // the port with content to add to store
1379 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental import
1380 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
1381 // then the import will be finished.
1383 NS_IMETHOD ImportFile( // import content from port
1384 nsIMdbEnv* ev, // context
1385 nsIMdbFile* ioFile, // the file with content to add to store
1386 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental import
1387 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
1388 // then the import will be finished.
1389 // } ----- end inport/export methods -----
1391 // { ----- begin hinting methods -----
1392 NS_IMETHOD
1393 ShareAtomColumnsHint( // advise re shared column content atomizing
1394 nsIMdbEnv* ev, // context
1395 mdb_scope inScopeHint, // zero, or suggested shared namespace
1396 const mdbColumnSet* inColumnSet) = 0; // cols desired tokenized together
1398 NS_IMETHOD
1399 AvoidAtomColumnsHint( // advise column with poor atomizing prospects
1400 nsIMdbEnv* ev, // context
1401 const mdbColumnSet* inColumnSet) = 0; // cols with poor atomizing prospects
1402 // } ----- end hinting methods -----
1404 // { ----- begin commit methods -----
1405 NS_IMETHOD SmallCommit( // save minor changes if convenient and uncostly
1406 nsIMdbEnv* ev) = 0; // context
1408 NS_IMETHOD LargeCommit( // save important changes if at all possible
1409 nsIMdbEnv* ev, // context
1410 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental commit
1411 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
1412 // then the commit will be finished. Note the store is effectively write
1413 // locked until commit is finished or canceled through the thumb instance.
1414 // Until the commit is done, the store will report it has readonly status.
1416 NS_IMETHOD SessionCommit( // save all changes if large commits delayed
1417 nsIMdbEnv* ev, // context
1418 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental commit
1419 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
1420 // then the commit will be finished. Note the store is effectively write
1421 // locked until commit is finished or canceled through the thumb instance.
1422 // Until the commit is done, the store will report it has readonly status.
1424 NS_IMETHOD
1425 CompressCommit( // commit and make db physically smaller if possible
1426 nsIMdbEnv* ev, // context
1427 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental commit
1428 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
1429 // then the commit will be finished. Note the store is effectively write
1430 // locked until commit is finished or canceled through the thumb instance.
1431 // Until the commit is done, the store will report it has readonly status.
1433 // } ----- end commit methods -----
1435 // } ===== end nsIMdbStore methods =====
1438 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbStore, NS_IMDBSTORE_IID)
1440 /*| nsIMdbCursor: base cursor class for iterating row cells and table rows
1442 **|| count: the number of elements in the collection (table or row)
1444 **|| seed: the change count in the underlying collection, which is synced
1445 **| with the collection when the iteration position is set, and henceforth
1446 **| acts to show whether the iter has lost collection synchronization, in
1447 **| case it matters to clients whether any change happens during iteration.
1449 **|| pos: the position of the current element in the collection. Negative
1450 **| means a position logically before the first element. A positive value
1451 **| equal to count (or larger) implies a position after the last element.
1452 **| To iterate over all elements, set the position to negative, so subsequent
1453 **| calls to any 'next' method will access the first collection element.
1455 **|| doFailOnSeedOutOfSync: whether a cursor should return an error if the
1456 **| cursor's snapshot of a table's seed becomes stale with respect the table's
1457 **| current seed value (which implies the iteration is less than total) in
1458 **| between to cursor calls that actually access collection content. By
1459 **| default, a cursor should assume this attribute is false until specified,
1460 **| so that iterations quietly try to re-sync when they loose coherence.
1463 #define NS_IMDBCURSOR_IID_STR "a0c37337-6ebc-474c-90db-e65ea0b850aa"
1465 #define NS_IMDBCURSOR_IID \
1466 {0xa0c37337, 0x6ebc, 0x474c, \
1467 {0x90, 0xdb, 0xe6, 0x5e, 0xa0, 0xb8, 0x50, 0xaa}}
1469 class nsIMdbCursor : public nsISupports { // collection iterator
1470 public:
1472 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBCURSOR_IID)
1473 // { ===== begin nsIMdbCursor methods =====
1475 // { ----- begin attribute methods -----
1476 NS_IMETHOD GetCount(nsIMdbEnv* ev, mdb_count* outCount) = 0; // readonly
1477 NS_IMETHOD GetSeed(nsIMdbEnv* ev, mdb_seed* outSeed) = 0; // readonly
1479 NS_IMETHOD SetPos(nsIMdbEnv* ev, mdb_pos inPos) = 0; // mutable
1480 NS_IMETHOD GetPos(nsIMdbEnv* ev, mdb_pos* outPos) = 0;
1482 NS_IMETHOD SetDoFailOnSeedOutOfSync(nsIMdbEnv* ev, mdb_bool inFail) = 0;
1483 NS_IMETHOD GetDoFailOnSeedOutOfSync(nsIMdbEnv* ev, mdb_bool* outFail) = 0;
1484 // } ----- end attribute methods -----
1486 // } ===== end nsIMdbCursor methods =====
1489 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbCursor, NS_IMDBCURSOR_IID)
1491 #define NS_IMDBPORTTABLECURSOR_IID_STR = "f181a41e-933d-49b3-af93-20d3634b8b78"
1493 #define NS_IMDBPORTTABLECURSOR_IID \
1494 {0xf181a41e, 0x933d, 0x49b3, \
1495 {0xaf, 0x93, 0x20, 0xd3, 0x63, 0x4b, 0x8b, 0x78}}
1497 /*| nsIMdbPortTableCursor: cursor class for iterating port tables
1499 **|| port: the cursor is associated with a specific port, which can be
1500 **| set to a different port (which resets the position to -1 so the
1501 **| next table acquired is the first in the port.
1504 class nsIMdbPortTableCursor : public nsISupports { // table collection iterator
1505 public:
1507 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBPORTTABLECURSOR_IID)
1508 // { ===== begin nsIMdbPortTableCursor methods =====
1510 // { ----- begin attribute methods -----
1511 NS_IMETHOD SetPort(nsIMdbEnv* ev, nsIMdbPort* ioPort) = 0; // sets pos to -1
1512 NS_IMETHOD GetPort(nsIMdbEnv* ev, nsIMdbPort** acqPort) = 0;
1514 NS_IMETHOD SetRowScope(nsIMdbEnv* ev, // sets pos to -1
1515 mdb_scope inRowScope) = 0;
1516 NS_IMETHOD GetRowScope(nsIMdbEnv* ev, mdb_scope* outRowScope) = 0;
1517 // setting row scope to zero iterates over all row scopes in port
1519 NS_IMETHOD SetTableKind(nsIMdbEnv* ev, // sets pos to -1
1520 mdb_kind inTableKind) = 0;
1521 NS_IMETHOD GetTableKind(nsIMdbEnv* ev, mdb_kind* outTableKind) = 0;
1522 // setting table kind to zero iterates over all table kinds in row scope
1523 // } ----- end attribute methods -----
1525 // { ----- begin table iteration methods -----
1526 NS_IMETHOD NextTable( // get table at next position in the db
1527 nsIMdbEnv* ev, // context
1528 nsIMdbTable** acqTable) = 0; // the next table in the iteration
1529 // } ----- end table iteration methods -----
1531 // } ===== end nsIMdbPortTableCursor methods =====
1534 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbPortTableCursor,
1535 NS_IMDBPORTTABLECURSOR_IID)
1537 /*| nsIMdbCollection: an object that collects a set of other objects as members.
1538 **| The main purpose of this base class is to unify the perceived semantics
1539 **| of tables and rows where their collection behavior is similar. This helps
1540 **| isolate the mechanics of collection behavior from the other semantics that
1541 **| are more characteristic of rows and tables.
1543 **|| count: the number of objects in a collection is the member count. (Some
1544 **| collection interfaces call this attribute the 'size', but that can be a
1545 **| little ambiguous, and counting actual members is harder to confuse.)
1547 **|| seed: the seed of a collection is a counter for changes in membership in
1548 **| a specific collection. This seed should change when members are added to
1549 **| or removed from a collection, but not when a member changes internal state.
1550 **| The seed should also change whenever the internal collection of members has
1551 **| a complex state change that reorders member positions (say by sorting) that
1552 **| would affect the nature of an iteration over that collection of members.
1553 **| The purpose of a seed is to inform any outstanding collection cursors that
1554 **| they might be stale, without incurring the cost of broadcasting an event
1555 **| notification to such cursors, which would need more data structure support.
1556 **| Presumably a cursor in a particular mdb code suite has much more direct
1557 **| access to a collection seed member slot that this abstract COM interface,
1558 **| so this information is intended more for clients outside mdb that want to
1559 **| make inferences similar to those made by the collection cursors. The seed
1560 **| value as an integer magnitude is not very important, and callers should not
1561 **| assume meaningful information can be derived from an integer value beyond
1562 **| whether it is equal or different from a previous inspection. A seed uses
1563 **| integers of many bits in order to make the odds of wrapping and becoming
1564 **| equal to an earlier seed value have probability that is vanishingly small.
1566 **|| port: every collection is associated with a specific database instance.
1568 **|| cursor: a subclass of nsIMdbCursor suitable for this specific collection
1569 **| subclass. The ability to GetCursor() from the base nsIMdbCollection class
1570 **| is not really as useful as getting a more specifically typed cursor more
1571 **| directly from the base class without any casting involved. So including
1572 **| this method here is more for conceptual illustration.
1574 **|| oid: every collection has an identity that persists from session to
1575 **| session. Implementations are probably able to distinguish row IDs from
1576 **| table IDs, but we don't specify anything official in this regard. A
1577 **| collection has the same identity for the lifetime of the collection,
1578 **| unless identity is swapped with another collection by means of a call to
1579 **| BecomeContent(), which is considered a way to swap a new representation
1580 **| for an old well-known object. (Even so, only content appears to change,
1581 **| while the identity seems to stay the same.)
1583 **|| become: developers can effectively cause two objects to swap identities,
1584 **| in order to effect a complete swap between what persistent content is
1585 **| represented by two oids. The caller should consider this a content swap,
1586 **| and not identity wap, because identities will seem to stay the same while
1587 **| only content changes. However, implementations will likely do this
1588 **| internally by swapping identities. Callers must swap content only
1589 **| between objects of similar type, such as a row with another row, and a
1590 **| table with another table, because implementations need not support
1591 **| cross-object swapping because it might break object name spaces.
1593 **|| dropping: when a caller expects a row or table will no longer be used, the
1594 **| caller can tell the collection to 'drop activity', which means the runtime
1595 **| object can have it's internal representation purged to save memory or any
1596 **| other resource that is being consumed by the collection's representation.
1597 **| This has no effect on the collection's persistent content or semantics,
1598 **| and is only considered a runtime effect. After a collection drops
1599 **| activity, the object should still be as usable as before (because it has
1600 **| NOT been closed), but further usage can be expensive to re-instate because
1601 **| it might involve reallocating space and/or re-reading disk space. But
1602 **| since this future usage is not expected, the caller does not expect to
1603 **| pay the extra expense. An implementation can choose to implement
1604 **| 'dropping activity' in different ways, or even not at all if this
1605 **| operation is not really feasible. Callers cannot ask objects whether they
1606 **| are 'dropped' or not, so this should be transparent. (Note that
1607 **| implementors might fear callers do not really know whether future
1608 **| usage will occur, and therefore might delay the act of dropping until
1609 **| the near future, until seeing whether the object is used again
1610 **| immediately elsewhere. Such use soon after the drop request might cause
1611 **| the drop to be cancelled.)
1613 class nsIMdbCollection : public nsISupports { // sequence of objects
1614 public:
1616 // { ===== begin nsIMdbCollection methods =====
1618 // { ----- begin attribute methods -----
1619 NS_IMETHOD GetSeed(nsIMdbEnv* ev,
1620 mdb_seed* outSeed) = 0; // member change count
1621 NS_IMETHOD GetCount(nsIMdbEnv* ev,
1622 mdb_count* outCount) = 0; // member count
1624 NS_IMETHOD GetPort(nsIMdbEnv* ev,
1625 nsIMdbPort** acqPort) = 0; // collection container
1626 // } ----- end attribute methods -----
1628 // { ----- begin cursor methods -----
1629 NS_IMETHOD GetCursor( // make a cursor starting iter at inMemberPos
1630 nsIMdbEnv* ev, // context
1631 mdb_pos inMemberPos, // zero-based ordinal pos of member in collection
1632 nsIMdbCursor** acqCursor) = 0; // acquire new cursor instance
1633 // } ----- end cursor methods -----
1635 // { ----- begin ID methods -----
1636 NS_IMETHOD GetOid(nsIMdbEnv* ev,
1637 mdbOid* outOid) = 0; // read object identity
1638 NS_IMETHOD BecomeContent(nsIMdbEnv* ev,
1639 const mdbOid* inOid) = 0; // exchange content
1640 // } ----- end ID methods -----
1642 // { ----- begin activity dropping methods -----
1643 NS_IMETHOD DropActivity( // tell collection usage no longer expected
1644 nsIMdbEnv* ev) = 0;
1645 // } ----- end activity dropping methods -----
1647 // } ===== end nsIMdbCollection methods =====
1650 /*| nsIMdbTable: an ordered collection of rows
1652 **|| row scope: an integer token for an atomized string in this database
1653 **| that names a space for row IDs. This attribute of a table is intended
1654 **| as guidance metainformation that helps with searching a database for
1655 **| tables that operate on collections of rows of the specific type. By
1656 **| convention, a table with a specific row scope is expected to focus on
1657 **| containing rows that belong to that scope, however exceptions are easily
1658 **| allowed because all rows in a table are known by both row ID and scope.
1659 **| (A table with zero row scope is never allowed because this would make it
1660 **| ambiguous to use a zero row scope when iterating over tables in a port to
1661 **| indicate that all row scopes should be seen by a cursor.)
1663 **|| table kind: an integer token for an atomized string in this database
1664 **| that names a kind of table as a subset of the associated row scope. This
1665 **| attribute is intended as guidance metainformation to clarify the role of
1666 **| this table with respect to other tables in the same row scope, and this
1667 **| also helps search for such tables in a database. By convention, a table
1668 **| with a specific table kind has a consistent role for containing rows with
1669 **| respect to other collections of such rows in the same row scope. Also by
1670 **| convention, at least one table in a row scope has a table kind purporting
1671 **| to contain ALL the rows that belong in that row scope, so that at least
1672 **| one table exists that allows all rows in a scope to be interated over.
1673 **| (A table with zero table kind is never allowed because this would make it
1674 **| ambiguous to use a zero table kind when iterating over tables in a port to
1675 **| indicate that all table kinds in a row scope should be seen by a cursor.)
1677 **|| port: every table is considered part of some port that contains the
1678 **| table, so that closing the containing port will cause the table to be
1679 **| indirectly closed as well. We make it easy to get the containing port for
1680 **| a table, because the port supports important semantic interfaces that will
1681 **| affect how content in table is presented; the most important port context
1682 **| that affects a table is specified by the set of token to string mappings
1683 **| that affect all tokens used throughout the database, and which drive the
1684 **| meanings of row scope, table kind, cell columns, etc.
1686 **|| cursor: a cursor that iterates over the rows in this table, where rows
1687 **| have zero-based index positions from zero to count-1. Making a cursor
1688 **| with negative position will next iterate over the first row in the table.
1690 **|| position: given any position from zero to count-1, a table will return
1691 **| the row ID and row scope for the row at that position. (One can use the
1692 **| GetRowAllCells() method to read that row, or else use a row cursor to both
1693 **| get the row at some position and read its content at the same time.) The
1694 **| position depends on whether a table is sorted, and upon the actual sort.
1695 **| Note that moving a row's position is only possible in unsorted tables.
1697 **|| row set: every table contains a collection of rows, where a member row is
1698 **| referenced by the table using the row ID and row scope for the row. No
1699 **| single table owns a given row instance, because rows are effectively ref-
1700 **| counted and destroyed only when the last table removes a reference to that
1701 **| particular row. (But a row can be emptied of all content no matter how
1702 **| many refs exist, and this might be the next best thing to destruction.)
1703 **| Once a row exists in a least one table (after NewRow() is called), then it
1704 **| can be added to any other table by calling AddRow(), or removed from any
1705 **| table by calling CutRow(), or queried as a member by calling HasRow(). A
1706 **| row can only be added to a table once, and further additions do nothing and
1707 **| complain not at all. Cutting a row from a table only does something when
1708 **| the row was actually a member, and otherwise does nothing silently.
1710 **|| row ref count: one can query the number of tables (and/or cells)
1711 **| containing a row as a member or a child.
1713 **|| row content: one can access or modify the cell content in a table's row
1714 **| by moving content to or from an instance of nsIMdbRow. Note that nsIMdbRow
1715 **| never represents the actual row inside a table, and this is the reason
1716 **| why nsIMdbRow instances do not have row IDs or row scopes. So an instance
1717 **| of nsIMdbRow always and only contains a snapshot of some or all content in
1718 **| past, present, or future persistent row inside a table. This means that
1719 **| reading and writing rows in tables has strictly copy semantics, and we
1720 **| currently do not plan any exceptions for specific performance reasons.
1722 **|| sorting: note all rows are assumed sorted by row ID as a secondary
1723 **| sort following the primary column sort, when table rows are sorted.
1725 **|| indexes:
1729 #define NS_IMDBTABLE_IID_STR = "fe11bc98-d02b-4128-9fac-87042fdf9639"
1731 #define NS_IMDBTABLE_IID \
1732 {0xfe11bc98, 0xd02b, 0x4128, \
1733 {0x9f, 0xac, 0x87, 0x04, 0x2f, 0xdf, 0x96, 0x39}}
1735 class nsIMdbTable : public nsIMdbCollection { // a collection of rows
1736 public:
1738 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBTABLE_IID)
1739 // { ===== begin nsIMdbTable methods =====
1741 // { ----- begin meta attribute methods -----
1742 NS_IMETHOD SetTablePriority(nsIMdbEnv* ev, mdb_priority inPrio) = 0;
1743 NS_IMETHOD GetTablePriority(nsIMdbEnv* ev, mdb_priority* outPrio) = 0;
1745 NS_IMETHOD GetTableBeVerbose(nsIMdbEnv* ev, mdb_bool* outBeVerbose) = 0;
1746 NS_IMETHOD SetTableBeVerbose(nsIMdbEnv* ev, mdb_bool inBeVerbose) = 0;
1748 NS_IMETHOD GetTableIsUnique(nsIMdbEnv* ev, mdb_bool* outIsUnique) = 0;
1750 NS_IMETHOD GetTableKind(nsIMdbEnv* ev, mdb_kind* outTableKind) = 0;
1751 NS_IMETHOD GetRowScope(nsIMdbEnv* ev, mdb_scope* outRowScope) = 0;
1753 NS_IMETHOD GetMetaRow(
1754 nsIMdbEnv* ev, // context
1755 const mdbOid* inOptionalMetaRowOid, // can be nil to avoid specifying
1756 mdbOid* outOid, // output meta row oid, can be nil to suppress output
1757 nsIMdbRow** acqRow) = 0; // acquire table's unique singleton meta row
1758 // The purpose of a meta row is to support the persistent recording of
1759 // meta info about a table as cells put into the distinguished meta row.
1760 // Each table has exactly one meta row, which is not considered a member
1761 // of the collection of rows inside the table. The only way to tell
1762 // whether a row is a meta row is by the fact that it is returned by this
1763 // GetMetaRow() method from some table. Otherwise nothing distinguishes
1764 // a meta row from any other row. A meta row can be used anyplace that
1765 // any other row can be used, and can even be put into other tables (or
1766 // the same table) as a table member, if this is useful for some reason.
1767 // The first attempt to access a table's meta row using GetMetaRow() will
1768 // cause the meta row to be created if it did not already exist. When the
1769 // meta row is created, it will have the row oid that was previously
1770 // requested for this table's meta row; or if no oid was ever explicitly
1771 // specified for this meta row, then a unique oid will be generated in
1772 // the row scope named "m" (so obviously MDB clients should not
1773 // manually allocate any row IDs from that special meta scope namespace).
1774 // The meta row oid can be specified either when the table is created, or
1775 // else the first time that GetMetaRow() is called, by passing a non-nil
1776 // pointer to an oid for parameter inOptionalMetaRowOid. The meta row's
1777 // actual oid is returned in outOid (if this is a non-nil pointer), and
1778 // it will be different from inOptionalMetaRowOid when the meta row was
1779 // already given a different oid earlier.
1780 // } ----- end meta attribute methods -----
1783 // { ----- begin cursor methods -----
1784 NS_IMETHOD GetTableRowCursor( // make a cursor, starting iteration at inRowPos
1785 nsIMdbEnv* ev, // context
1786 mdb_pos inRowPos, // zero-based ordinal position of row in table
1787 nsIMdbTableRowCursor** acqCursor) = 0; // acquire new cursor instance
1788 // } ----- end row position methods -----
1790 // { ----- begin row position methods -----
1791 NS_IMETHOD PosToOid( // get row member for a table position
1792 nsIMdbEnv* ev, // context
1793 mdb_pos inRowPos, // zero-based ordinal position of row in table
1794 mdbOid* outOid) = 0; // row oid at the specified position
1796 NS_IMETHOD OidToPos( // test for the table position of a row member
1797 nsIMdbEnv* ev, // context
1798 const mdbOid* inOid, // row to find in table
1799 mdb_pos* outPos) = 0; // zero-based ordinal position of row in table
1801 NS_IMETHOD PosToRow( // test for the table position of a row member
1802 nsIMdbEnv* ev, // context
1803 mdb_pos inRowPos, // zero-based ordinal position of row in table
1804 nsIMdbRow** acqRow) = 0; // acquire row at table position inRowPos
1806 NS_IMETHOD RowToPos( // test for the table position of a row member
1807 nsIMdbEnv* ev, // context
1808 nsIMdbRow* ioRow, // row to find in table
1809 mdb_pos* outPos) = 0; // zero-based ordinal position of row in table
1810 // } ----- end row position methods -----
1812 // { ----- begin oid set methods -----
1813 NS_IMETHOD AddOid( // make sure the row with inOid is a table member
1814 nsIMdbEnv* ev, // context
1815 const mdbOid* inOid) = 0; // row to ensure membership in table
1817 NS_IMETHOD HasOid( // test for the table position of a row member
1818 nsIMdbEnv* ev, // context
1819 const mdbOid* inOid, // row to find in table
1820 mdb_bool* outHasOid) = 0; // whether inOid is a member row
1822 NS_IMETHOD CutOid( // make sure the row with inOid is not a member
1823 nsIMdbEnv* ev, // context
1824 const mdbOid* inOid) = 0; // row to remove from table
1825 // } ----- end oid set methods -----
1827 // { ----- begin row set methods -----
1828 NS_IMETHOD NewRow( // create a new row instance in table
1829 nsIMdbEnv* ev, // context
1830 mdbOid* ioOid, // please use minus one (unbound) rowId for db-assigned IDs
1831 nsIMdbRow** acqRow) = 0; // create new row
1833 NS_IMETHOD AddRow( // make sure the row with inOid is a table member
1834 nsIMdbEnv* ev, // context
1835 nsIMdbRow* ioRow) = 0; // row to ensure membership in table
1837 NS_IMETHOD HasRow( // test for the table position of a row member
1838 nsIMdbEnv* ev, // context
1839 nsIMdbRow* ioRow, // row to find in table
1840 mdb_bool* outHasRow) = 0; // whether row is a table member
1842 NS_IMETHOD CutRow( // make sure the row with inOid is not a member
1843 nsIMdbEnv* ev, // context
1844 nsIMdbRow* ioRow) = 0; // row to remove from table
1846 NS_IMETHOD CutAllRows( // remove all rows from the table
1847 nsIMdbEnv* ev) = 0; // context
1848 // } ----- end row set methods -----
1850 // { ----- begin hinting methods -----
1851 NS_IMETHOD SearchColumnsHint( // advise re future expected search cols
1852 nsIMdbEnv* ev, // context
1853 const mdbColumnSet* inColumnSet) = 0; // columns likely to be searched
1855 NS_IMETHOD SortColumnsHint( // advise re future expected sort columns
1856 nsIMdbEnv* ev, // context
1857 const mdbColumnSet* inColumnSet) = 0; // columns for likely sort requests
1859 NS_IMETHOD StartBatchChangeHint( // advise before many adds and cuts
1860 nsIMdbEnv* ev, // context
1861 const void* inLabel) = 0; // intend unique address to match end call
1862 // If batch starts nest by virtue of nesting calls in the stack, then
1863 // the address of a local variable makes a good batch start label that
1864 // can be used at batch end time, and such addresses remain unique.
1866 NS_IMETHOD EndBatchChangeHint( // advise before many adds and cuts
1867 nsIMdbEnv* ev, // context
1868 const void* inLabel) = 0; // label matching start label
1869 // Suppose a table is maintaining one or many sort orders for a table,
1870 // so that every row added to the table must be inserted in each sort,
1871 // and every row cut must be removed from each sort. If a db client
1872 // intends to make many such changes before needing any information
1873 // about the order or positions of rows inside a table, then a client
1874 // might tell the table to start batch changes in order to disable
1875 // sorting of rows for the interim. Presumably a table will then do
1876 // a full sort of all rows at need when the batch changes end, or when
1877 // a surprise request occurs for row position during batch changes.
1878 // } ----- end hinting methods -----
1880 // { ----- begin searching methods -----
1881 NS_IMETHOD FindRowMatches( // search variable number of sorted cols
1882 nsIMdbEnv* ev, // context
1883 const mdbYarn* inPrefix, // content to find as prefix in row's column cell
1884 nsIMdbTableRowCursor** acqCursor) = 0; // set of matching rows
1886 NS_IMETHOD GetSearchColumns( // query columns used by FindRowMatches()
1887 nsIMdbEnv* ev, // context
1888 mdb_count* outCount, // context
1889 mdbColumnSet* outColSet) = 0; // caller supplied space to put columns
1890 // GetSearchColumns() returns the columns actually searched when the
1891 // FindRowMatches() method is called. No more than mColumnSet_Count
1892 // slots of mColumnSet_Columns will be written, since mColumnSet_Count
1893 // indicates how many slots are present in the column array. The
1894 // actual number of search column used by the table is returned in
1895 // the outCount parameter; if this number exceeds mColumnSet_Count,
1896 // then a caller needs a bigger array to read the entire column set.
1897 // The minimum of mColumnSet_Count and outCount is the number slots
1898 // in mColumnSet_Columns that were actually written by this method.
1900 // Callers are expected to change this set of columns by calls to
1901 // nsIMdbTable::SearchColumnsHint() or SetSearchSorting(), or both.
1902 // } ----- end searching methods -----
1904 // { ----- begin sorting methods -----
1905 // sorting: note all rows are assumed sorted by row ID as a secondary
1906 // sort following the primary column sort, when table rows are sorted.
1908 NS_IMETHOD
1909 CanSortColumn( // query which column is currently used for sorting
1910 nsIMdbEnv* ev, // context
1911 mdb_column inColumn, // column to query sorting potential
1912 mdb_bool* outCanSort) = 0; // whether the column can be sorted
1914 NS_IMETHOD GetSorting( // view same table in particular sorting
1915 nsIMdbEnv* ev, // context
1916 mdb_column inColumn, // requested new column for sorting table
1917 nsIMdbSorting** acqSorting) = 0; // acquire sorting for column
1919 NS_IMETHOD SetSearchSorting( // use this sorting in FindRowMatches()
1920 nsIMdbEnv* ev, // context
1921 mdb_column inColumn, // often same as nsIMdbSorting::GetSortColumn()
1922 nsIMdbSorting* ioSorting) = 0; // requested sorting for some column
1923 // SetSearchSorting() attempts to inform the table that ioSorting
1924 // should be used during calls to FindRowMatches() for searching
1925 // the column which is actually sorted by ioSorting. This method
1926 // is most useful in conjunction with nsIMdbSorting::SetCompare(),
1927 // because otherwise a caller would not be able to override the
1928 // comparison ordering method used during searchs. Note that some
1929 // database implementations might be unable to use an arbitrarily
1930 // specified sort order, either due to schema or runtime interface
1931 // constraints, in which case ioSorting might not actually be used.
1932 // Presumably ioSorting is an instance that was returned from some
1933 // earlier call to nsIMdbTable::GetSorting(). A caller can also
1934 // use nsIMdbTable::SearchColumnsHint() to specify desired change
1935 // in which columns are sorted and searched by FindRowMatches().
1937 // A caller can pass a nil pointer for ioSorting to request that
1938 // column inColumn no longer be used at all by FindRowMatches().
1939 // But when ioSorting is non-nil, then inColumn should match the
1940 // column actually sorted by ioSorting; when these do not agree,
1941 // implementations are instructed to give precedence to the column
1942 // specified by ioSorting (so this means callers might just pass
1943 // zero for inColumn when ioSorting is also provided, since then
1944 // inColumn is both redundant and ignored).
1945 // } ----- end sorting methods -----
1947 // { ----- begin moving methods -----
1948 // moving a row does nothing unless a table is currently unsorted
1950 NS_IMETHOD MoveOid( // change position of row in unsorted table
1951 nsIMdbEnv* ev, // context
1952 const mdbOid* inOid, // row oid to find in table
1953 mdb_pos inHintFromPos, // suggested hint regarding start position
1954 mdb_pos inToPos, // desired new position for row inRowId
1955 mdb_pos* outActualPos) = 0; // actual new position of row in table
1957 NS_IMETHOD MoveRow( // change position of row in unsorted table
1958 nsIMdbEnv* ev, // context
1959 nsIMdbRow* ioRow, // row oid to find in table
1960 mdb_pos inHintFromPos, // suggested hint regarding start position
1961 mdb_pos inToPos, // desired new position for row inRowId
1962 mdb_pos* outActualPos) = 0; // actual new position of row in table
1963 // } ----- end moving methods -----
1965 // { ----- begin index methods -----
1966 NS_IMETHOD AddIndex( // create a sorting index for column if possible
1967 nsIMdbEnv* ev, // context
1968 mdb_column inColumn, // the column to sort by index
1969 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental index building
1970 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
1971 // then the index addition will be finished.
1973 NS_IMETHOD CutIndex( // stop supporting a specific column index
1974 nsIMdbEnv* ev, // context
1975 mdb_column inColumn, // the column with index to be removed
1976 nsIMdbThumb** acqThumb) = 0; // acquire thumb for incremental index destroy
1977 // Call nsIMdbThumb::DoMore() until done, or until the thumb is broken, and
1978 // then the index removal will be finished.
1980 NS_IMETHOD HasIndex( // query for current presence of a column index
1981 nsIMdbEnv* ev, // context
1982 mdb_column inColumn, // the column to investigate
1983 mdb_bool* outHasIndex) = 0; // whether column has index for this column
1986 NS_IMETHOD EnableIndexOnSort( // create an index for col on first sort
1987 nsIMdbEnv* ev, // context
1988 mdb_column inColumn) = 0; // the column to index if ever sorted
1990 NS_IMETHOD QueryIndexOnSort( // check whether index on sort is enabled
1991 nsIMdbEnv* ev, // context
1992 mdb_column inColumn, // the column to investigate
1993 mdb_bool* outIndexOnSort) = 0; // whether column has index-on-sort enabled
1995 NS_IMETHOD DisableIndexOnSort( // prevent future index creation on sort
1996 nsIMdbEnv* ev, // context
1997 mdb_column inColumn) = 0; // the column to index if ever sorted
1998 // } ----- end index methods -----
2000 // } ===== end nsIMdbTable methods =====
2003 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbTable, NS_IMDBTABLE_IID)
2005 /*| nsIMdbSorting: a view of a table in some particular sort order. This
2006 **| row order closely resembles a readonly array of rows with the same row
2007 **| membership as the underlying table, but in a different order than the
2008 **| table's explicit row order. But the sorting's row membership changes
2009 **| whenever the table's membership changes (without any notification, so
2010 **| keep this in mind when modifying the table).
2012 **|| table: every sorting is associated with a particular table. You
2013 **| cannot change which table is used by a sorting (just ask some new
2014 **| table for a suitable sorting instance instead).
2016 **|| compare: the ordering method used by a sorting, wrapped up in a
2017 **| abstract plug-in interface. When this was never installed by an
2018 **| explicit call to SetNewCompare(), a compare object is still returned,
2019 **| and it might match the compare instance returned by the factory method
2020 **| nsIMdbFactory::MakeCompare(), which represents a default sort order
2021 **| (which we fervently hope is consistently ASCII byte ordering).
2023 **|| cursor: in case callers are more comfortable with a cursor style
2024 **| of accessing row members, each sorting will happily return a cursor
2025 **| instance with behavior very similar to a cursor returned from a call
2026 **| to nsIMdbTable::GetTableRowCursor(), but with different row order.
2027 **| A cursor should show exactly the same information as the pos methods.
2029 **|| pos: the PosToOid() and PosToRow() methods are just like the table
2030 **| methods of the same name, except they show rows in the sort order of
2031 **| the sorting, rather than that of the table. These methods are like
2032 **| readonly array position accessor's, or like a C++ operator[].
2034 class nsIMdbSorting : public nsIMdbObject { // sorting of some table
2035 public:
2036 // { ===== begin nsIMdbSorting methods =====
2038 // { ----- begin attribute methods -----
2039 // sorting: note all rows are assumed sorted by row ID as a secondary
2040 // sort following the primary column sort, when table rows are sorted.
2042 NS_IMETHOD GetTable(nsIMdbEnv* ev, nsIMdbTable** acqTable) = 0;
2043 NS_IMETHOD GetSortColumn( // query which col is currently sorted
2044 nsIMdbEnv* ev, // context
2045 mdb_column* outColumn) = 0; // col the table uses for sorting (or zero)
2047 NS_IMETHOD SetNewCompare(nsIMdbEnv* ev,
2048 nsIMdbCompare* ioNewCompare) = 0;
2049 // Setting the sorting's compare object will typically cause the rows
2050 // to be resorted, presumably in a lazy fashion when the sorting is
2051 // next required to be in a valid row ordering state, such as when a
2052 // call to PosToOid() happens. ioNewCompare can be nil, in which case
2053 // implementations should revert to the default sort order, which must
2054 // be equivalent to whatever is used by nsIMdbFactory::MakeCompare().
2056 NS_IMETHOD GetOldCompare(nsIMdbEnv* ev,
2057 nsIMdbCompare** acqOldCompare) = 0;
2058 // Get this sorting instance's compare object, which handles the
2059 // ordering of rows in the sorting, by comparing yarns from the cells
2060 // in the column being sorted. Since nsIMdbCompare has no interface
2061 // to query the state of the compare object, it is not clear what you
2062 // would do with this object when returned, except maybe compare it
2063 // as a pointer address to some other instance, to check identities.
2065 // } ----- end attribute methods -----
2067 // { ----- begin cursor methods -----
2068 NS_IMETHOD GetSortingRowCursor( // make a cursor, starting at inRowPos
2069 nsIMdbEnv* ev, // context
2070 mdb_pos inRowPos, // zero-based ordinal position of row in table
2071 nsIMdbTableRowCursor** acqCursor) = 0; // acquire new cursor instance
2072 // A cursor interface turning same info as PosToOid() or PosToRow().
2073 // } ----- end row position methods -----
2075 // { ----- begin row position methods -----
2076 NS_IMETHOD PosToOid( // get row member for a table position
2077 nsIMdbEnv* ev, // context
2078 mdb_pos inRowPos, // zero-based ordinal position of row in table
2079 mdbOid* outOid) = 0; // row oid at the specified position
2081 NS_IMETHOD PosToRow( // test for the table position of a row member
2082 nsIMdbEnv* ev, // context
2083 mdb_pos inRowPos, // zero-based ordinal position of row in table
2084 nsIMdbRow** acqRow) = 0; // acquire row at table position inRowPos
2085 // } ----- end row position methods -----
2087 // } ===== end nsIMdbSorting methods =====
2090 /*| nsIMdbTableRowCursor: cursor class for iterating table rows
2092 **|| table: the cursor is associated with a specific table, which can be
2093 **| set to a different table (which resets the position to -1 so the
2094 **| next row acquired is the first in the table.
2096 **|| NextRowId: the rows in the table can be iterated by identity alone,
2097 **| without actually reading the cells of any row with this method.
2099 **|| NextRowCells: read the next row in the table, but only read cells
2100 **| from the table which are already present in the row (so no new cells
2101 **| are added to the row, even if they are present in the table). All the
2102 **| cells will have content specified, even it is the empty string. No
2103 **| columns will be removed, even if missing from the row (because missing
2104 **| and empty are semantically equivalent).
2106 **|| NextRowAllCells: read the next row in the table, and access all the
2107 **| cells for this row in the table, adding any missing columns to the row
2108 **| as needed until all cells are represented. All the
2109 **| cells will have content specified, even it is the empty string. No
2110 **| columns will be removed, even if missing from the row (because missing
2111 **| and empty are semantically equivalent).
2115 #define NS_IMDBTABLEROWCURSOR_IID_STR = "4f325dad-0385-4b62-a992-c914ab93587e"
2117 #define NS_IMDBTABLEROWCURSOR_IID \
2118 {0x4f325dad, 0x0385, 0x4b62, \
2119 {0xa9, 0x92, 0xc9, 0x14, 0xab, 0x93, 0x58, 0x7e}}
2123 class nsIMdbTableRowCursor : public nsISupports { // table row iterator
2124 public:
2125 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBTABLEROWCURSOR_IID)
2127 // { ===== begin nsIMdbTableRowCursor methods =====
2129 // { ----- begin attribute methods -----
2130 // NS_IMETHOD SetTable(nsIMdbEnv* ev, nsIMdbTable* ioTable) = 0; // sets pos to -1
2131 // Method SetTable() cut and made obsolete in keeping with new sorting methods.
2133 NS_IMETHOD GetTable(nsIMdbEnv* ev, nsIMdbTable** acqTable) = 0;
2134 // } ----- end attribute methods -----
2136 // { ----- begin duplicate row removal methods -----
2137 NS_IMETHOD CanHaveDupRowMembers(nsIMdbEnv* ev, // cursor might hold dups?
2138 mdb_bool* outCanHaveDups) = 0;
2140 NS_IMETHOD MakeUniqueCursor( // clone cursor, removing duplicate rows
2141 nsIMdbEnv* ev, // context
2142 nsIMdbTableRowCursor** acqCursor) = 0; // acquire clone with no dups
2143 // Note that MakeUniqueCursor() is never necessary for a cursor which was
2144 // created by table method nsIMdbTable::GetTableRowCursor(), because a table
2145 // never contains the same row as a member more than once. However, a cursor
2146 // created by table method nsIMdbTable::FindRowMatches() might contain the
2147 // same row more than once, because the same row can generate a hit by more
2148 // than one column with a matching string prefix. Note this method can
2149 // return the very same cursor instance with just an incremented refcount,
2150 // when the original cursor could not contain any duplicate rows (calling
2151 // CanHaveDupRowMembers() shows this case on a false return). Otherwise
2152 // this method returns a different cursor instance. Callers should not use
2153 // this MakeUniqueCursor() method lightly, because it tends to defeat the
2154 // purpose of lazy programming techniques, since it can force creation of
2155 // an explicit row collection in a new cursor's representation, in order to
2156 // inspect the row membership and remove any duplicates; this can have big
2157 // impact if a collection holds tens of thousands of rows or more, when
2158 // the original cursor with dups simply referenced rows indirectly by row
2159 // position ranges, without using an explicit row set representation.
2160 // Callers are encouraged to use nsIMdbCursor::GetCount() to determine
2161 // whether the row collection is very large (tens of thousands), and to
2162 // delay calling MakeUniqueCursor() when possible, until a user interface
2163 // element actually demands the creation of an explicit set representation.
2164 // } ----- end duplicate row removal methods -----
2166 // { ----- begin oid iteration methods -----
2167 NS_IMETHOD NextRowOid( // get row id of next row in the table
2168 nsIMdbEnv* ev, // context
2169 mdbOid* outOid, // out row oid
2170 mdb_pos* outRowPos) = 0; // zero-based position of the row in table
2171 // } ----- end oid iteration methods -----
2173 // { ----- begin row iteration methods -----
2174 NS_IMETHOD NextRow( // get row cells from table for cells already in row
2175 nsIMdbEnv* ev, // context
2176 nsIMdbRow** acqRow, // acquire next row in table
2177 mdb_pos* outRowPos) = 0; // zero-based position of the row in table
2179 NS_IMETHOD PrevRowOid( // get row id of previous row in the table
2180 nsIMdbEnv* ev, // context
2181 mdbOid* outOid, // out row oid
2182 mdb_pos* outRowPos) = 0; // zero-based position of the row in table
2183 // } ----- end oid iteration methods -----
2185 // { ----- begin row iteration methods -----
2186 NS_IMETHOD PrevRow( // get row cells from table for cells already in row
2187 nsIMdbEnv* ev, // context
2188 nsIMdbRow** acqRow, // acquire previous row in table
2189 mdb_pos* outRowPos) = 0; // zero-based position of the row in table
2191 // } ----- end row iteration methods -----
2193 // { ----- begin copy iteration methods -----
2194 // NS_IMETHOD NextRowCopy( // put row cells into sink only when already in sink
2195 // nsIMdbEnv* ev, // context
2196 // nsIMdbRow* ioSinkRow, // sink for row cells read from next row
2197 // mdbOid* outOid, // out row oid
2198 // mdb_pos* outRowPos) = 0; // zero-based position of the row in table
2200 // NS_IMETHOD NextRowCopyAll( // put all row cells into sink, adding to sink
2201 // nsIMdbEnv* ev, // context
2202 // nsIMdbRow* ioSinkRow, // sink for row cells read from next row
2203 // mdbOid* outOid, // out row oid
2204 // mdb_pos* outRowPos) = 0; // zero-based position of the row in table
2205 // } ----- end copy iteration methods -----
2207 // } ===== end nsIMdbTableRowCursor methods =====
2210 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbTableRowCursor, NS_IMDBTABLEROWCURSOR_IID)
2212 /*| nsIMdbRow: a collection of cells
2216 #define NS_IMDBROW_IID_STR "271e8d6e-183a-40e3-9f18-36913b4c7853"
2219 #define NS_IMDBROW_IID \
2220 {0x271e8d6e, 0x183a, 0x40e3, \
2221 {0x9f, 0x18, 0x36, 0x91, 0x3b, 0x4c, 0x78, 0x53}}
2224 class nsIMdbRow : public nsIMdbCollection { // cell tuple
2225 public:
2227 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBROW_IID)
2228 // { ===== begin nsIMdbRow methods =====
2230 // { ----- begin cursor methods -----
2231 NS_IMETHOD GetRowCellCursor( // make a cursor starting iteration at inCellPos
2232 nsIMdbEnv* ev, // context
2233 mdb_pos inCellPos, // zero-based ordinal position of cell in row
2234 nsIMdbRowCellCursor** acqCursor) = 0; // acquire new cursor instance
2235 // } ----- end cursor methods -----
2237 // { ----- begin column methods -----
2238 NS_IMETHOD AddColumn( // make sure a particular column is inside row
2239 nsIMdbEnv* ev, // context
2240 mdb_column inColumn, // column to add
2241 const mdbYarn* inYarn) = 0; // cell value to install
2243 NS_IMETHOD CutColumn( // make sure a column is absent from the row
2244 nsIMdbEnv* ev, // context
2245 mdb_column inColumn) = 0; // column to ensure absent from row
2247 NS_IMETHOD CutAllColumns( // remove all columns from the row
2248 nsIMdbEnv* ev) = 0; // context
2249 // } ----- end column methods -----
2251 // { ----- begin cell methods -----
2252 NS_IMETHOD NewCell( // get cell for specified column, or add new one
2253 nsIMdbEnv* ev, // context
2254 mdb_column inColumn, // column to add
2255 nsIMdbCell** acqCell) = 0; // cell column and value
2257 NS_IMETHOD AddCell( // copy a cell from another row to this row
2258 nsIMdbEnv* ev, // context
2259 const nsIMdbCell* inCell) = 0; // cell column and value
2261 NS_IMETHOD GetCell( // find a cell in this row
2262 nsIMdbEnv* ev, // context
2263 mdb_column inColumn, // column to find
2264 nsIMdbCell** acqCell) = 0; // cell for specified column, or null
2266 NS_IMETHOD EmptyAllCells( // make all cells in row empty of content
2267 nsIMdbEnv* ev) = 0; // context
2268 // } ----- end cell methods -----
2270 // { ----- begin row methods -----
2271 NS_IMETHOD AddRow( // add all cells in another row to this one
2272 nsIMdbEnv* ev, // context
2273 nsIMdbRow* ioSourceRow) = 0; // row to union with
2275 NS_IMETHOD SetRow( // make exact duplicate of another row
2276 nsIMdbEnv* ev, // context
2277 nsIMdbRow* ioSourceRow) = 0; // row to duplicate
2278 // } ----- end row methods -----
2280 // { ----- begin blob methods -----
2281 NS_IMETHOD SetCellYarn(nsIMdbEnv* ev, // synonym for AddColumn()
2282 mdb_column inColumn, // column to write
2283 const mdbYarn* inYarn) = 0; // reads from yarn slots
2284 // make this text object contain content from the yarn's buffer
2286 NS_IMETHOD GetCellYarn(nsIMdbEnv* ev,
2287 mdb_column inColumn, // column to read
2288 mdbYarn* outYarn) = 0; // writes some yarn slots
2289 // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
2291 NS_IMETHOD AliasCellYarn(nsIMdbEnv* ev,
2292 mdb_column inColumn, // column to alias
2293 mdbYarn* outYarn) = 0; // writes ALL yarn slots
2295 NS_IMETHOD NextCellYarn(nsIMdbEnv* ev, // iterative version of GetCellYarn()
2296 mdb_column* ioColumn, // next column to read
2297 mdbYarn* outYarn) = 0; // writes some yarn slots
2298 // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
2300 // The ioColumn argument is an inout parameter which initially contains the
2301 // last column accessed and returns the next column corresponding to the
2302 // content read into the yarn. Callers should start with a zero column
2303 // value to say 'no previous column', which causes the first column to be
2304 // read. Then the value returned in ioColumn is perfect for the next call
2305 // to NextCellYarn(), since it will then be the previous column accessed.
2306 // Callers need only examine the column token returned to see which cell
2307 // in the row is being read into the yarn. When no more columns remain,
2308 // and the iteration has ended, ioColumn will return a zero token again.
2309 // So iterating over cells starts and ends with a zero column token.
2311 NS_IMETHOD SeekCellYarn( // resembles nsIMdbRowCellCursor::SeekCell()
2312 nsIMdbEnv* ev, // context
2313 mdb_pos inPos, // position of cell in row sequence
2314 mdb_column* outColumn, // column for this particular cell
2315 mdbYarn* outYarn) = 0; // writes some yarn slots
2316 // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
2317 // Callers can pass nil for outYarn to indicate no interest in content, so
2318 // only the outColumn value is returned. NOTE to subclasses: you must be
2319 // able to ignore outYarn when the pointer is nil; please do not crash.
2321 // } ----- end blob methods -----
2323 // } ===== end nsIMdbRow methods =====
2326 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbRow, NS_IMDBROW_IID)
2328 /*| nsIMdbRowCellCursor: cursor class for iterating row cells
2330 **|| row: the cursor is associated with a specific row, which can be
2331 **| set to a different row (which resets the position to -1 so the
2332 **| next cell acquired is the first in the row.
2334 **|| NextCell: get the next cell in the row and return its position and
2335 **| a new instance of a nsIMdbCell to represent this next cell.
2338 #define NS_IMDBROWCELLCURSOR_IID_STR "b33371a7-5d63-4d10-85a8-e44dffe75c28"
2341 #define NS_IMDBROWCELLCURSOR_IID \
2342 {0x271e8d6e, 0x5d63, 0x4d10 , \
2343 {0x85, 0xa8, 0xe4, 0x4d, 0xff, 0xe7, 0x5c, 0x28}}
2346 class nsIMdbRowCellCursor : public nsISupports{ // cell collection iterator
2347 public:
2349 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBROWCELLCURSOR_IID)
2350 // { ===== begin nsIMdbRowCellCursor methods =====
2352 // { ----- begin attribute methods -----
2353 NS_IMETHOD SetRow(nsIMdbEnv* ev, nsIMdbRow* ioRow) = 0; // sets pos to -1
2354 NS_IMETHOD GetRow(nsIMdbEnv* ev, nsIMdbRow** acqRow) = 0;
2355 // } ----- end attribute methods -----
2357 // { ----- begin cell creation methods -----
2358 NS_IMETHOD MakeCell( // get cell at current pos in the row
2359 nsIMdbEnv* ev, // context
2360 mdb_column* outColumn, // column for this particular cell
2361 mdb_pos* outPos, // position of cell in row sequence
2362 nsIMdbCell** acqCell) = 0; // the cell at inPos
2363 // } ----- end cell creation methods -----
2365 // { ----- begin cell seeking methods -----
2366 NS_IMETHOD SeekCell( // same as SetRow() followed by MakeCell()
2367 nsIMdbEnv* ev, // context
2368 mdb_pos inPos, // position of cell in row sequence
2369 mdb_column* outColumn, // column for this particular cell
2370 nsIMdbCell** acqCell) = 0; // the cell at inPos
2371 // } ----- end cell seeking methods -----
2373 // { ----- begin cell iteration methods -----
2374 NS_IMETHOD NextCell( // get next cell in the row
2375 nsIMdbEnv* ev, // context
2376 nsIMdbCell** acqCell, // changes to the next cell in the iteration
2377 mdb_column* outColumn, // column for this particular cell
2378 mdb_pos* outPos) = 0; // position of cell in row sequence
2380 NS_IMETHOD PickNextCell( // get next cell in row within filter set
2381 nsIMdbEnv* ev, // context
2382 nsIMdbCell* ioCell, // changes to the next cell in the iteration
2383 const mdbColumnSet* inFilterSet, // col set of actual caller interest
2384 mdb_column* outColumn, // column for this particular cell
2385 mdb_pos* outPos) = 0; // position of cell in row sequence
2387 // Note that inFilterSet should not have too many (many more than 10?)
2388 // cols, since this might imply a potential excessive consumption of time
2389 // over many cursor calls when looking for column and filter intersection.
2390 // } ----- end cell iteration methods -----
2392 // } ===== end nsIMdbRowCellCursor methods =====
2395 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbRowCellCursor, NS_IMDBROWCELLCURSOR_IID)
2397 /*| nsIMdbBlob: a base class for objects composed mainly of byte sequence state.
2398 **| (This provides a base class for nsIMdbCell, so that cells themselves can
2399 **| be used to set state in another cell, without extracting a buffer.)
2401 class nsIMdbBlob : public nsISupports { // a string with associated charset
2402 public:
2404 // { ===== begin nsIMdbBlob methods =====
2406 // { ----- begin attribute methods -----
2407 NS_IMETHOD SetBlob(nsIMdbEnv* ev,
2408 nsIMdbBlob* ioBlob) = 0; // reads inBlob slots
2409 // when inBlob is in the same suite, this might be fastest cell-to-cell
2411 NS_IMETHOD ClearBlob( // make empty (so content has zero length)
2412 nsIMdbEnv* ev) = 0;
2413 // clearing a yarn is like SetYarn() with empty yarn instance content
2415 NS_IMETHOD GetBlobFill(nsIMdbEnv* ev,
2416 mdb_fill* outFill) = 0; // size of blob
2417 // Same value that would be put into mYarn_Fill, if one called GetYarn()
2418 // with a yarn instance that had mYarn_Buf==nil and mYarn_Size==0.
2420 NS_IMETHOD SetYarn(nsIMdbEnv* ev,
2421 const mdbYarn* inYarn) = 0; // reads from yarn slots
2422 // make this text object contain content from the yarn's buffer
2424 NS_IMETHOD GetYarn(nsIMdbEnv* ev,
2425 mdbYarn* outYarn) = 0; // writes some yarn slots
2426 // copy content into the yarn buffer, and update mYarn_Fill and mYarn_Form
2428 NS_IMETHOD AliasYarn(nsIMdbEnv* ev,
2429 mdbYarn* outYarn) = 0; // writes ALL yarn slots
2430 // AliasYarn() reveals sensitive internal text buffer state to the caller
2431 // by setting mYarn_Buf to point into the guts of this text implementation.
2433 // The caller must take great care to avoid writing on this space, and to
2434 // avoid calling any method that would cause the state of this text object
2435 // to change (say by directly or indirectly setting the text to hold more
2436 // content that might grow the size of the buffer and free the old buffer).
2437 // In particular, callers should scrupulously avoid making calls into the
2438 // mdb interface to write any content while using the buffer pointer found
2439 // in the returned yarn instance. Best safe usage involves copying content
2440 // into some other kind of external content representation beyond mdb.
2442 // (The original design of this method a week earlier included the concept
2443 // of very fast and efficient cooperative locking via a pointer to some lock
2444 // member slot. But let's ignore that complexity in the current design.)
2446 // AliasYarn() is specifically intended as the first step in transferring
2447 // content from nsIMdbBlob to a nsString representation, without forcing extra
2448 // allocations and/or memory copies. (A standard nsIMdbBlob_AsString() utility
2449 // will use AliasYarn() as the first step in setting a nsString instance.)
2451 // This is an alternative to the GetYarn() method, which has copy semantics
2452 // only; AliasYarn() relaxes a robust safety principle only for performance
2453 // reasons, to accomodate the need for callers to transform text content to
2454 // some other canonical representation that would necessitate an additional
2455 // copy and transformation when such is incompatible with the mdbYarn format.
2457 // The implementation of AliasYarn() should have extremely little overhead
2458 // besides the virtual dispatch to the method implementation, and the code
2459 // necessary to populate all the mdbYarn member slots with internal buffer
2460 // address and metainformation that describes the buffer content. Note that
2461 // mYarn_Grow must always be set to nil to indicate no resizing is allowed.
2463 // } ----- end attribute methods -----
2465 // } ===== end nsIMdbBlob methods =====
2468 /*| nsIMdbCell: the text in a single column of a row. The base nsIMdbBlob
2469 **| class provides all the interface related to accessing cell text.
2471 **|| column: each cell in a row appears in a specific column, where this
2472 **| column is identified by the an integer mdb_scope value (generated by
2473 **| the StringToScopeToken() method in the containing nsIMdbPort instance).
2474 **| Because a row cannot have more than one cell with the same column,
2475 **| something must give if one calls SetColumn() with an existing column
2476 **| in the same row. When this happens, the other cell is replaced with
2477 **| this cell (and the old cell is closed if it has outstanding refs).
2479 **|| row: every cell instance is a part of some row, and every cell knows
2480 **| which row is the parent row. (Note this should be represented by a
2481 **| weak backpointer, so that outstanding cell references cannot keep a
2482 **| row open that should be closed. Otherwise we'd have ref graph cycles.)
2484 **|| text: a cell can either be text, or it can have a child row or table,
2485 **| but not both at once. If text is read from a cell with a child, the text
2486 **| content should be empty (for AliasYarn()) or a description of the type
2487 **| of child (perhaps "mdb:cell:child:row" or "mdb:cell:child:table").
2489 **|| child: a cell might reference another row or a table, rather than text.
2490 **| The interface for putting and getting children rows and tables was first
2491 **| defined in the nsIMdbTable interface, but then this was moved to this cell
2492 **| interface as more natural.
2497 #define NS_IMDBCELL_IID \
2498 {0xa3b62f71, 0xa181, 0x4a91, \
2499 {0xb6, 0x6b, 0x27, 0x10, 0x9b, 0x88, 0x98, 0x35}}
2501 #define NS_IMDBCELL_IID_STR = "a3b62f71-a181-4a91-b66b-27109b889835"
2503 class nsIMdbCell : public nsIMdbBlob { // text attribute in row with column scope
2504 public:
2506 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMDBTABLEROWCURSOR_IID)
2507 // { ===== begin nsIMdbCell methods =====
2509 // { ----- begin attribute methods -----
2510 NS_IMETHOD SetColumn(nsIMdbEnv* ev, mdb_column inColumn) = 0;
2511 NS_IMETHOD GetColumn(nsIMdbEnv* ev, mdb_column* outColumn) = 0;
2513 NS_IMETHOD GetCellInfo( // all cell metainfo except actual content
2514 nsIMdbEnv* ev,
2515 mdb_column* outColumn, // the column in the containing row
2516 mdb_fill* outBlobFill, // the size of text content in bytes
2517 mdbOid* outChildOid, // oid of possible row or table child
2518 mdb_bool* outIsRowChild) = 0; // nonzero if child, and a row child
2520 // Checking all cell metainfo is a good way to avoid forcing a large cell
2521 // in to memory when you don't actually want to use the content.
2523 NS_IMETHOD GetRow(nsIMdbEnv* ev, // parent row for this cell
2524 nsIMdbRow** acqRow) = 0;
2525 NS_IMETHOD GetPort(nsIMdbEnv* ev, // port containing cell
2526 nsIMdbPort** acqPort) = 0;
2527 // } ----- end attribute methods -----
2529 // { ----- begin children methods -----
2530 NS_IMETHOD HasAnyChild( // does cell have a child instead of text?
2531 nsIMdbEnv* ev,
2532 mdbOid* outOid, // out id of row or table (or unbound if no child)
2533 mdb_bool* outIsRow) = 0; // nonzero if child is a row (rather than a table)
2535 NS_IMETHOD GetAnyChild( // access table of specific attribute
2536 nsIMdbEnv* ev, // context
2537 nsIMdbRow** acqRow, // child row (or null)
2538 nsIMdbTable** acqTable) = 0; // child table (or null)
2541 NS_IMETHOD SetChildRow( // access table of specific attribute
2542 nsIMdbEnv* ev, // context
2543 nsIMdbRow* ioRow) = 0; // inRow must be bound inside this same db port
2545 NS_IMETHOD GetChildRow( // access row of specific attribute
2546 nsIMdbEnv* ev, // context
2547 nsIMdbRow** acqRow) = 0; // acquire child row (or nil if no child)
2550 NS_IMETHOD SetChildTable( // access table of specific attribute
2551 nsIMdbEnv* ev, // context
2552 nsIMdbTable* inTable) = 0; // table must be bound inside this same db port
2554 NS_IMETHOD GetChildTable( // access table of specific attribute
2555 nsIMdbEnv* ev, // context
2556 nsIMdbTable** acqTable) = 0; // acquire child table (or nil if no child)
2557 // } ----- end children methods -----
2559 // } ===== end nsIMdbCell methods =====
2562 NS_DEFINE_STATIC_IID_ACCESSOR(nsIMdbCell, NS_IMDBTABLEROWCURSOR_IID)
2564 // } %%%%% end C++ abstract class interfaces %%%%%
2566 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
2568 #endif /* _MDB_ */