FMDatabaseAdditions.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // FMDatabaseAdditions.h
  3. // fmdb
  4. //
  5. // Created by August Mueller on 10/30/05.
  6. // Copyright 2005 Flying Meat Inc.. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "FMDatabase.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. /** Category of additions for `<FMDatabase>` class.
  12. ### See also
  13. - `<FMDatabase>`
  14. */
  15. @interface FMDatabase (FMDatabaseAdditions)
  16. ///----------------------------------------
  17. /// @name Return results of SQL to variable
  18. ///----------------------------------------
  19. /** Return `int` value for query
  20. @param query The SQL query to be performed.
  21. @param ... A list of parameters that will be bound to the `?` placeholders in the SQL query.
  22. @return `int` value.
  23. @note This is not available from Swift.
  24. */
  25. - (int)intForQuery:(NSString*)query, ...;
  26. /** Return `long` value for query
  27. @param query The SQL query to be performed.
  28. @param ... A list of parameters that will be bound to the `?` placeholders in the SQL query.
  29. @return `long` value.
  30. @note This is not available from Swift.
  31. */
  32. - (long)longForQuery:(NSString*)query, ...;
  33. /** Return `BOOL` value for query
  34. @param query The SQL query to be performed.
  35. @param ... A list of parameters that will be bound to the `?` placeholders in the SQL query.
  36. @return `BOOL` value.
  37. @note This is not available from Swift.
  38. */
  39. - (BOOL)boolForQuery:(NSString*)query, ...;
  40. /** Return `double` value for query
  41. @param query The SQL query to be performed.
  42. @param ... A list of parameters that will be bound to the `?` placeholders in the SQL query.
  43. @return `double` value.
  44. @note This is not available from Swift.
  45. */
  46. - (double)doubleForQuery:(NSString*)query, ...;
  47. /** Return `NSString` value for query
  48. @param query The SQL query to be performed.
  49. @param ... A list of parameters that will be bound to the `?` placeholders in the SQL query.
  50. @return `NSString` value.
  51. @note This is not available from Swift.
  52. */
  53. - (NSString * _Nullable)stringForQuery:(NSString*)query, ...;
  54. /** Return `NSData` value for query
  55. @param query The SQL query to be performed.
  56. @param ... A list of parameters that will be bound to the `?` placeholders in the SQL query.
  57. @return `NSData` value.
  58. @note This is not available from Swift.
  59. */
  60. - (NSData * _Nullable)dataForQuery:(NSString*)query, ...;
  61. /** Return `NSDate` value for query
  62. @param query The SQL query to be performed.
  63. @param ... A list of parameters that will be bound to the `?` placeholders in the SQL query.
  64. @return `NSDate` value.
  65. @note This is not available from Swift.
  66. */
  67. - (NSDate * _Nullable)dateForQuery:(NSString*)query, ...;
  68. // Notice that there's no dataNoCopyForQuery:.
  69. // That would be a bad idea, because we close out the result set, and then what
  70. // happens to the data that we just didn't copy? Who knows, not I.
  71. ///--------------------------------
  72. /// @name Schema related operations
  73. ///--------------------------------
  74. /** Does table exist in database?
  75. @param tableName The name of the table being looked for.
  76. @return `YES` if table found; `NO` if not found.
  77. */
  78. - (BOOL)tableExists:(NSString*)tableName;
  79. /** The schema of the database.
  80. This will be the schema for the entire database. For each entity, each row of the result set will include the following fields:
  81. - `type` - The type of entity (e.g. table, index, view, or trigger)
  82. - `name` - The name of the object
  83. - `tbl_name` - The name of the table to which the object references
  84. - `rootpage` - The page number of the root b-tree page for tables and indices
  85. - `sql` - The SQL that created the entity
  86. @return `FMResultSet` of schema; `nil` on error.
  87. @see [SQLite File Format](http://www.sqlite.org/fileformat.html)
  88. */
  89. - (FMResultSet *)getSchema;
  90. /** The schema of the database.
  91. This will be the schema for a particular table as report by SQLite `PRAGMA`, for example:
  92. PRAGMA table_info('employees')
  93. This will report:
  94. - `cid` - The column ID number
  95. - `name` - The name of the column
  96. - `type` - The data type specified for the column
  97. - `notnull` - whether the field is defined as NOT NULL (i.e. values required)
  98. - `dflt_value` - The default value for the column
  99. - `pk` - Whether the field is part of the primary key of the table
  100. @param tableName The name of the table for whom the schema will be returned.
  101. @return `FMResultSet` of schema; `nil` on error.
  102. @see [table_info](http://www.sqlite.org/pragma.html#pragma_table_info)
  103. */
  104. - (FMResultSet*)getTableSchema:(NSString*)tableName;
  105. /** Test to see if particular column exists for particular table in database
  106. @param columnName The name of the column.
  107. @param tableName The name of the table.
  108. @return `YES` if column exists in table in question; `NO` otherwise.
  109. */
  110. - (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName;
  111. /** Test to see if particular column exists for particular table in database
  112. @param columnName The name of the column.
  113. @param tableName The name of the table.
  114. @return `YES` if column exists in table in question; `NO` otherwise.
  115. @see columnExists:inTableWithName:
  116. @warning Deprecated - use `<columnExists:inTableWithName:>` instead.
  117. */
  118. - (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __deprecated_msg("Use columnExists:inTableWithName: instead");
  119. /** Validate SQL statement
  120. This validates SQL statement by performing `sqlite3_prepare_v2`, but not returning the results, but instead immediately calling `sqlite3_finalize`.
  121. @param sql The SQL statement being validated.
  122. @param error This is a pointer to a `NSError` object that will receive the autoreleased `NSError` object if there was any error. If this is `nil`, no `NSError` result will be returned.
  123. @return `YES` if validation succeeded without incident; `NO` otherwise.
  124. */
  125. - (BOOL)validateSQL:(NSString*)sql error:(NSError * _Nullable *)error;
  126. ///-----------------------------------
  127. /// @name Application identifier tasks
  128. ///-----------------------------------
  129. /** Retrieve application ID
  130. @return The `uint32_t` numeric value of the application ID.
  131. @see setApplicationID:
  132. */
  133. @property (nonatomic) uint32_t applicationID;
  134. #if TARGET_OS_MAC && !TARGET_OS_IPHONE
  135. /** Retrieve application ID string
  136. @see setApplicationIDString:
  137. */
  138. @property (nonatomic, retain) NSString *applicationIDString;
  139. #endif
  140. ///-----------------------------------
  141. /// @name user version identifier tasks
  142. ///-----------------------------------
  143. /** Retrieve user version
  144. @see setUserVersion:
  145. */
  146. @property (nonatomic) uint32_t userVersion;
  147. @end
  148. NS_ASSUME_NONNULL_END