home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / CIncludes / DatabaseAccess.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  12.0 KB  |  318 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        DatabaseAccess.h
  3.  
  4.      Copyright:    © 1984-1994 by Apple Computer, Inc.
  5.                  All rights reserved.
  6.  
  7.      Version:    Universal Interfaces 2.0a3  ETO #16, MPW prerelease.  Friday, November 11, 1994. 
  8.  
  9.      Bugs?:        If you find a problem with this file, send the file and version
  10.                  information (from above) and the problem description to:
  11.  
  12.                      Internet:    apple.bugs@applelink.apple.com
  13.                      AppleLink:    APPLE.BUGS
  14.  
  15. */
  16.  
  17. #ifndef __DATABASEACCESS__
  18. #define __DATABASEACCESS__
  19.  
  20.  
  21. #ifndef __RESOURCES__
  22. #include <Resources.h>
  23. #endif
  24. /*    #include <Types.h>                                            */
  25. /*        #include <ConditionalMacros.h>                            */
  26. /*    #include <MixedMode.h>                                        */
  27. /*    #include <Files.h>                                            */
  28. /*        #include <OSUtils.h>                                    */
  29. /*            #include <Memory.h>                                    */
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if GENERATINGPOWERPC
  36. #pragma options align=mac68k
  37. #endif
  38.  
  39. #ifdef __CFM68K__
  40. #pragma lib_export on
  41. #endif
  42.  
  43.  
  44. enum {
  45.     typeNone                    = 'none',
  46.     typeDate                    = 'date',
  47.     typeTime                    = 'time',
  48.     typeTimeStamp                = 'tims',
  49.     typeDecimal                    = 'deci',
  50.     typeMoney                    = 'mone',
  51.     typeVChar                    = 'vcha',
  52.     typeVBin                    = 'vbin',
  53.     typeLChar                    = 'lcha',
  54.     typeLBin                    = 'lbin',
  55.     typeDiscard                    = 'disc',
  56. /* "dummy" types for DBResultsToText */
  57.     typeUnknown                    = 'unkn',
  58.     typeColBreak                = 'colb',
  59.     typeRowBreak                = 'rowb',
  60. /* pass this in to DBGetItem for any data type */
  61.     typeAnyType                    = 0
  62. };
  63.  
  64. /* infinite timeout value for DBGetItem */
  65. enum {
  66. /* messages for status functions for DBStartQuery */
  67.     kDBUpdateWind                = 0,
  68.     kDBAboutToInit                = 1,
  69.     kDBInitComplete                = 2,
  70.     kDBSendComplete                = 3,
  71.     kDBExecComplete                = 4,
  72.     kDBStartQueryComplete        = 5
  73. };
  74.  
  75. enum {
  76. /* messages for status functions for DBGetQueryResults */
  77.     kDBGetItemComplete            = 6,
  78.     kDBGetQueryResultsComplete    = 7,
  79.     kDBWaitForever                = -1,
  80. /*  flags for DBGetItem  */
  81.     kDBLastColFlag                = 0x0001,
  82.     kDBNullFlag                    = 0x0004
  83. };
  84.  
  85. typedef OSType DBType;
  86.  
  87. typedef struct DBAsyncParamBlockRec DBAsyncParamBlockRec, *DBAsyncParmBlkPtr;
  88.  
  89. /*
  90.         DBCompletionProcPtr uses register based parameters on the 68k and cannot
  91.         be written in or called from a high-level language without the help of
  92.         mixed mode or assembly glue.
  93.  
  94.         In:
  95.          => pb              A1.L
  96. */
  97.  
  98. #if GENERATINGCFM
  99. typedef UniversalProcPtr DBCompletionUPP;
  100. #else
  101. typedef Register68kProcPtr DBCompletionUPP;
  102. #endif
  103.  
  104. struct DBAsyncParamBlockRec {
  105.     DBCompletionUPP                    completionProc;                /* pointer to completion routine */
  106.     OSErr                            result;                        /* result of call */
  107.     long                            userRef;                    /* for application's use */
  108.     long                            ddevRef;                    /* for ddev's use */
  109.     long                            reserved;                    /* for internal use */
  110. };
  111. enum {
  112.     uppDBCompletionProcInfo = kRegisterBased
  113.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(DBAsyncParmBlkPtr)))
  114. };
  115.  
  116. #if GENERATINGCFM
  117. #define CallDBCompletionProc(userRoutine, pb)        \
  118.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBCompletionProcInfo, (pb))
  119. #else
  120. /* (*DBCompletionProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  121. #endif
  122.  
  123. #if GENERATINGCFM
  124. #define NewDBCompletionProc(userRoutine)        \
  125.         (DBCompletionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBCompletionProcInfo, GetCurrentArchitecture())
  126. #else
  127. #define NewDBCompletionProc(userRoutine)        \
  128.         ((DBCompletionUPP) (userRoutine))
  129. #endif
  130.  
  131. struct ResListElem {
  132.     ResType                            theType;                    /* resource type */
  133.     short                            id;                            /* resource id */
  134. };
  135. typedef struct ResListElem ResListElem;
  136.  
  137. typedef ResListElem *ResListPtr, **ResListHandle;
  138.  
  139. /* structure for query list in QueryRecord */
  140. typedef Handle QueryArray[256];
  141.  
  142. typedef Handle **QueryListHandle;
  143.  
  144. struct QueryRecord {
  145.     short                            version;                    /* version */
  146.     short                            id;                            /* id of 'qrsc' this came from */
  147.     Handle                            queryProc;                    /* handle to query def proc */
  148.     Str63                            ddevName;                    /* ddev name */
  149.     Str255                            host;                        /* host name */
  150.     Str255                            user;                        /* user name */
  151.     Str255                            password;                    /* password */
  152.     Str255                            connStr;                    /* connection string */
  153.     short                            currQuery;                    /* index of current query */
  154.     short                            numQueries;                    /* number of queries in list */
  155.     QueryListHandle                    queryList;                    /* handle to array of handles to text */
  156.     short                            numRes;                        /* number of resources in list */
  157.     ResListHandle                    resList;                    /* handle to array of resource list elements */
  158.     Handle                            dataHandle;                    /* for use by query def proc */
  159.     long                            refCon;                        /* for use by application */
  160. };
  161. typedef struct QueryRecord QueryRecord;
  162.  
  163. typedef QueryRecord *QueryPtr, **QueryHandle;
  164.  
  165. /* structure of column types array in ResultsRecord */
  166. typedef DBType ColTypesArray[256];
  167.  
  168. typedef Handle ColTypesHandle;
  169.  
  170. struct DBColInfoRecord {
  171.     short                            len;
  172.     short                            places;
  173.     short                            flags;
  174. };
  175. typedef struct DBColInfoRecord DBColInfoRecord;
  176.  
  177. typedef DBColInfoRecord ColInfoArray[256];
  178.  
  179. typedef Handle ColInfoHandle;
  180.  
  181. struct ResultsRecord {
  182.     short                            numRows;                    /* number of rows in result */
  183.     short                            numCols;                    /* number of columns per row */
  184.     ColTypesHandle                    colTypes;                    /* data type array */
  185.     Handle                            colData;                    /* actual results */
  186.     ColInfoHandle                    colInfo;                    /* DBColInfoRecord array */
  187. };
  188. typedef struct ResultsRecord ResultsRecord;
  189.  
  190. typedef pascal OSErr (*DBQueryDefProcPtr)(long *sessID, QueryHandle query);
  191. typedef pascal Boolean (*DBStatusProcPtr)(short message, OSErr result, short dataLen, short dataPlaces, short dataFlags, DBType dataType, Ptr dataPtr);
  192. typedef pascal OSErr (*DBResultHandlerProcPtr)(DBType dataType, short theLen, short thePlaces, short theFlags, Ptr theData, Handle theText);
  193.  
  194. #if GENERATINGCFM
  195. typedef UniversalProcPtr DBQueryDefUPP;
  196. typedef UniversalProcPtr DBStatusUPP;
  197. typedef UniversalProcPtr DBResultHandlerUPP;
  198. #else
  199. typedef DBQueryDefProcPtr DBQueryDefUPP;
  200. typedef DBStatusProcPtr DBStatusUPP;
  201. typedef DBResultHandlerProcPtr DBResultHandlerUPP;
  202. #endif
  203.  
  204. enum {
  205.     uppDBQueryDefProcInfo = kPascalStackBased
  206.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  207.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long*)))
  208.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(QueryHandle))),
  209.     uppDBStatusProcInfo = kPascalStackBased
  210.          | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  211.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
  212.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(OSErr)))
  213.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  214.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short)))
  215.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(short)))
  216.          | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(DBType)))
  217.          | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(Ptr))),
  218.     uppDBResultHandlerProcInfo = kPascalStackBased
  219.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  220.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DBType)))
  221.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short)))
  222.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  223.          | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short)))
  224.          | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(Ptr)))
  225.          | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(Handle)))
  226. };
  227.  
  228. #if GENERATINGCFM
  229. #define NewDBQueryDefProc(userRoutine)        \
  230.         (DBQueryDefUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBQueryDefProcInfo, GetCurrentArchitecture())
  231. #define NewDBStatusProc(userRoutine)        \
  232.         (DBStatusUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBStatusProcInfo, GetCurrentArchitecture())
  233. #define NewDBResultHandlerProc(userRoutine)        \
  234.         (DBResultHandlerUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDBResultHandlerProcInfo, GetCurrentArchitecture())
  235. #else
  236. #define NewDBQueryDefProc(userRoutine)        \
  237.         ((DBQueryDefUPP) (userRoutine))
  238. #define NewDBStatusProc(userRoutine)        \
  239.         ((DBStatusUPP) (userRoutine))
  240. #define NewDBResultHandlerProc(userRoutine)        \
  241.         ((DBResultHandlerUPP) (userRoutine))
  242. #endif
  243.  
  244. #if GENERATINGCFM
  245. #define CallDBQueryDefProc(userRoutine, sessID, query)        \
  246.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBQueryDefProcInfo, (sessID), (query))
  247. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)        \
  248.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBStatusProcInfo, (message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  249. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)        \
  250.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDBResultHandlerProcInfo, (dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  251. #else
  252. #define CallDBQueryDefProc(userRoutine, sessID, query)        \
  253.         (*(userRoutine))((sessID), (query))
  254. #define CallDBStatusProc(userRoutine, message, result, dataLen, dataPlaces, dataFlags, dataType, dataPtr)        \
  255.         (*(userRoutine))((message), (result), (dataLen), (dataPlaces), (dataFlags), (dataType), (dataPtr))
  256. #define CallDBResultHandlerProc(userRoutine, dataType, theLen, thePlaces, theFlags, theData, theText)        \
  257.         (*(userRoutine))((dataType), (theLen), (thePlaces), (theFlags), (theData), (theText))
  258. #endif
  259.  
  260. extern pascal OSErr InitDBPack(void)
  261.  FIVEWORDINLINE(0x3F3C, 0x0004, 0x303C, 0x0100, 0xA82F);
  262. extern pascal OSErr DBInit(long *sessID, ConstStr63Param ddevName, ConstStr255Param host, ConstStr255Param user, ConstStr255Param passwd, ConstStr255Param connStr, DBAsyncParmBlkPtr asyncPB)
  263.  THREEWORDINLINE(0x303C, 0x0E02, 0xA82F);
  264. extern pascal OSErr DBEnd(long sessID, DBAsyncParmBlkPtr asyncPB)
  265.  THREEWORDINLINE(0x303C, 0x0403, 0xA82F);
  266. extern pascal OSErr DBGetConnInfo(long sessID, short sessNum, long *returnedID, long *version, Str63 ddevName, Str255 host, Str255 user, Str255 network, Str255 connStr, long *start, OSErr *state, DBAsyncParmBlkPtr asyncPB)
  267.  THREEWORDINLINE(0x303C, 0x1704, 0xA82F);
  268. extern pascal OSErr DBGetSessionNum(long sessID, short *sessNum, DBAsyncParmBlkPtr asyncPB)
  269.  THREEWORDINLINE(0x303C, 0x0605, 0xA82F);
  270. extern pascal OSErr DBSend(long sessID, Ptr text, short len, DBAsyncParmBlkPtr asyncPB)
  271.  THREEWORDINLINE(0x303C, 0x0706, 0xA82F);
  272. extern pascal OSErr DBSendItem(long sessID, DBType dataType, short len, short places, short flags, void *buffer, DBAsyncParmBlkPtr asyncPB)
  273.  THREEWORDINLINE(0x303C, 0x0B07, 0xA82F);
  274. extern pascal OSErr DBExec(long sessID, DBAsyncParmBlkPtr asyncPB)
  275.  THREEWORDINLINE(0x303C, 0x0408, 0xA82F);
  276. extern pascal OSErr DBState(long sessID, DBAsyncParmBlkPtr asyncPB)
  277.  THREEWORDINLINE(0x303C, 0x0409, 0xA82F);
  278. extern pascal OSErr DBGetErr(long sessID, long *err1, long *err2, Str255 item1, Str255 item2, Str255 errorMsg, DBAsyncParmBlkPtr asyncPB)
  279.  THREEWORDINLINE(0x303C, 0x0E0A, 0xA82F);
  280. extern pascal OSErr DBBreak(long sessID, Boolean abort, DBAsyncParmBlkPtr asyncPB)
  281.  THREEWORDINLINE(0x303C, 0x050B, 0xA82F);
  282. extern pascal OSErr DBGetItem(long sessID, long timeout, DBType *dataType, short *len, short *places, short *flags, void *buffer, DBAsyncParmBlkPtr asyncPB)
  283.  THREEWORDINLINE(0x303C, 0x100C, 0xA82F);
  284. extern pascal OSErr DBUnGetItem(long sessID, DBAsyncParmBlkPtr asyncPB)
  285.  THREEWORDINLINE(0x303C, 0x040D, 0xA82F);
  286. extern pascal OSErr DBKill(DBAsyncParmBlkPtr asyncPB)
  287.  THREEWORDINLINE(0x303C, 0x020E, 0xA82F);
  288. extern pascal OSErr DBGetNewQuery(short queryID, QueryHandle *query)
  289.  THREEWORDINLINE(0x303C, 0x030F, 0xA82F);
  290. extern pascal OSErr DBDisposeQuery(QueryHandle query)
  291.  THREEWORDINLINE(0x303C, 0x0210, 0xA82F);
  292. extern pascal OSErr DBStartQuery(long *sessID, QueryHandle query, DBStatusUPP statusProc, DBAsyncParmBlkPtr asyncPB)
  293.  THREEWORDINLINE(0x303C, 0x0811, 0xA82F);
  294. extern pascal OSErr DBGetQueryResults(long sessID, ResultsRecord *results, long timeout, DBStatusUPP statusProc, DBAsyncParmBlkPtr asyncPB)
  295.  THREEWORDINLINE(0x303C, 0x0A12, 0xA82F);
  296. extern pascal OSErr DBResultsToText(ResultsRecord *results, Handle *theText)
  297.  THREEWORDINLINE(0x303C, 0x0413, 0xA82F);
  298. extern pascal OSErr DBInstallResultHandler(DBType dataType, DBResultHandlerUPP theHandler, Boolean isSysHandler)
  299.  THREEWORDINLINE(0x303C, 0x0514, 0xA82F);
  300. extern pascal OSErr DBRemoveResultHandler(DBType dataType)
  301.  THREEWORDINLINE(0x303C, 0x0215, 0xA82F);
  302. extern pascal OSErr DBGetResultHandler(DBType dataType, DBResultHandlerUPP *theHandler, Boolean getSysHandler)
  303.  THREEWORDINLINE(0x303C, 0x0516, 0xA82F);
  304.  
  305. #ifdef __CFM68K__
  306. #pragma lib_export off
  307. #endif
  308.  
  309. #if GENERATINGPOWERPC
  310. #pragma options align=reset
  311. #endif
  312.  
  313. #ifdef __cplusplus
  314. }
  315. #endif
  316.  
  317. #endif /* __DATABASEACCESS__ */
  318.