FMDatabaseAdditions.h 6.2 KB

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