Native Microsoft SQL Server client for iOS. An Objective-C wrapper around the open-source FreeTDS library.
#import "SQLClient.h" SQLClient* client = [SQLClient sharedInstance]; [client connect:@"server\instance:port" username:@"user" password:@"pass" database:@"db" completion:^(BOOL success) { if (success) { [client execute:@"SELECT * FROM Users" completion:^(NSArray* results) { for (NSArray* table in results) { for (NSDictionary* row in table) { for (NSString* column in row) { NSLog(@"%@=%@", column, row[column]); } } } [client disconnect]; }]; } }];
FreeTDS communicates both errors and messages. SQLClient
rebroadcasts both via NSNotificationCenter
:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(error:) name:SQLClientErrorNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(message:) name:SQLClientMessageNotification object:nil];
- (void)error:(NSNotification*)notification
{
NSNumber* code = notification.userInfo[SQLClientCodeKey];
NSString* message = notification.userInfo[SQLClientMessageKey];
NSNumber* severity = notification.userInfo[SQLClientSeverityKey];
NSLog(@"Error #%@: %@ (Severity %@)", code, message, severity);
}
- (void)message:(NSNotification*)notification
{
NSString* message = notification.userInfo[SQLClientMessageKey];
NSLog(@"Message: %@", message);
}
SQLClient maps SQL Server data types into the following native Objective-C types:
*The maximum length of a string in a query is configured on the server via the SET TEXTSIZE
command. To find out your current setting, execute SELECT @@TEXTSIZE
. SQLClient uses 4096 by default. To override this setting, update the maxTextSize
property.
†The following data types are only converted to NSDate on TDS version 7.3 and higher. By default FreeTDS uses version 7.1 of the TDS protocol, which converts them to NSString. To use a higher version of the TDS protocol, add an environment variable to Xcode named TDSVER
. Possible values are
4.2
, 5.0
, 7.0
, 7.1
, 7.2
, 7.3
, 7.4
, auto
.
A value of auto
tells FreeTDS to use an autodetection (trial-and-error) algorithm to choose the highest available protocol version.
The SQLClientTests
target contains integration tests which require a connection to an instance of SQL Server. The integration tests have passed successfully on the following database servers:
To configure the connection for your server:
Edit Scheme...
and select the Test
scheme.Arguments
tab, uncheck Use the Run action's arguments and environment variables
connect:
method.
HOST
(server\instance:port
)DATABASE
(optional)USERNAME
PASSWORD
PR's welcome!
Open the Xcode project inside the SQLClient folder.
CocoaPods is the preferred way to install this library.
sudo gem update --system
. Enter your password when prompted.sudo gem install cocoapods
.pod 'SQLClient', '~> 1.0.0'
pod install
.SQLClient: A Native Microsoft SQL Server Library for iOS
FreeTDS: http://www.freetds.org
FreeTDS-iOS: https://github.com/patchhf/FreeTDS-iOS
FreeTDS example code in C: http://freetds.schemamania.org/userguide/samplecode.htm
SQL Server Logo © Microsoft