FMDatabaseAdditions.h 6.1 KB

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