All Projects → martinrybak → Sqlclient

martinrybak / Sqlclient

Licence: mit
Native Microsoft SQL Server client for iOS

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Sqlclient

Bds
Blockchain data parsing and persisting results
Stars: ✭ 1,032 (+864.49%)
Mutual labels:  sql-server
Sqlserver Kit
Useful links, scripts, tools and best practice for Microsoft SQL Server Database
Stars: ✭ 1,148 (+972.9%)
Mutual labels:  sql-server
Dbwebapi
(Migrated from CodePlex) DbWebApi is a .Net library that implement an entirely generic Web API (RESTful) for HTTP clients to call database (Oracle & SQL Server) stored procedures or functions in a managed way out-of-the-box without any configuration or coding.
Stars: ✭ 84 (-21.5%)
Mutual labels:  sql-server
Aspnetcorenlog
ASP.NET Core NLog MS SQL Server PostgreSQL MySQL Elasticsearch
Stars: ✭ 54 (-49.53%)
Mutual labels:  sql-server
Reporting Services Examples
📕 Various example reports I use for SQL Server Reporting Services (SSRS) as well as documents for unit testing, requirements and a style guide template.
Stars: ✭ 63 (-41.12%)
Mutual labels:  sql-server
Aspnetcoreactivedirectorystarterkit
Starter kit to quickly create ASP.NET Core with On-Premises Active Directory Authentication.
Stars: ✭ 71 (-33.64%)
Mutual labels:  sql-server
Dbt Sqlserver
dbt adapter for SQL Server and Azure SQL
Stars: ✭ 41 (-61.68%)
Mutual labels:  sql-server
Webtimesheetmanagement
Basic TimeSheet Management Application in ASP.NET MVC 5
Stars: ✭ 93 (-13.08%)
Mutual labels:  sql-server
Syncchanges
Synchronize/Replicate database changes using SQL Server Change Tracking
Stars: ✭ 66 (-38.32%)
Mutual labels:  sql-server
Eval Sql.net
SQL Eval Function | Dynamically Evaluate Expression in SQL Server using C# Syntax
Stars: ✭ 84 (-21.5%)
Mutual labels:  sql-server
Spa Asp.net Api Vuejs
A Vue.js single page application for basic Management By Objective tasks using ASP .NET Webapi 2 and SQL server
Stars: ✭ 57 (-46.73%)
Mutual labels:  sql-server
Mssql Docker
Official Microsoft repository for SQL Server in Docker resources
Stars: ✭ 1,111 (+938.32%)
Mutual labels:  sql-server
Rsqlserver
SQL Server DBI for R, based on the jTDS driver
Stars: ✭ 76 (-28.97%)
Mutual labels:  sql-server
Dbal
Doctrine Database Abstraction Layer
Stars: ✭ 8,495 (+7839.25%)
Mutual labels:  sql-server
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+16879.44%)
Mutual labels:  sql-server
Workstations
Vagrant virtual workstations and development environments with Visual Studio, Docker, IIS and SQL Server on Windows for .NET development
Stars: ✭ 45 (-57.94%)
Mutual labels:  sql-server
Aceql Http
AceQL HTTP is a framework of REST like http APIs that allow to access to remote SQL databases over http from any device that supports http.
Stars: ✭ 68 (-36.45%)
Mutual labels:  sql-server
Minisqlquery
Minimalist SQL Query tool for any .NET DB Provider - SQL, SQLite, SQL CE, Oracle, Access...
Stars: ✭ 103 (-3.74%)
Mutual labels:  sql-server
Sharebook Backend
Projeto backend de código livre para o app Sharebook.
Stars: ✭ 91 (-14.95%)
Mutual labels:  sql-server
Sql Apiconsumer
Database Project with generic procedures to consume API through GET/POST methods.
Stars: ✭ 77 (-28.04%)
Mutual labels:  sql-server

SQLClient

Native Microsoft SQL Server client for iOS. An Objective-C wrapper around the open-source FreeTDS library.

Sample Usage

#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];
      }];
    }
}];

Errors

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);
}

Type Conversion

SQLClient maps SQL Server data types into the following native Objective-C types:

  • bigint → NSNumber
  • binary(n) → NSData
  • bit → NSNumber
  • char(n) → NSString
  • cursor → not supported
  • date → NSDate or NSString
  • datetime → NSDate
  • datetime2 → NSDate or NSString
  • datetimeoffset → NSDate or NSString
  • decimal(p,s) → NSNumber
  • float(n) → NSNumber
  • image → NSData
  • int → NSNumber
  • money → NSDecimalNumber (last 2 digits are truncated)
  • nchar → NSString
  • ntext → NSString
  • null → NSNull
  • numeric(p,s) → NSNumber
  • nvarchar → NSString
  • nvarchar(max) → NSString
  • real → NSNumber
  • smalldatetime → NSDate
  • smallint → NSNumber
  • smallmoney → NSDecimalNumber
  • sql_variant → not supported
  • table → not supported
  • text → NSString*
  • time → NSDate or NSString
  • timestamp → NSData
  • tinyint → NSNumber
  • uniqueidentifier → NSUUID
  • varbinary → NSData
  • varbinary(max) → NSData
  • varchar(max) → NSString*
  • varchar(n) → NSString
  • xml → NSString

*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.

  • date
  • datetime2
  • datetimeoffset
  • time

Testing

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:

  • SQL Server 7.0 (TDS 7.0)
  • SQL Server 2000 (TDS 7.1)
  • SQL Server 2005 (TDS 7.2)
  • SQL Server 2008 (TDS 7.3)
  • TODO: add more!

To configure the connection for your server:

  • In Xcode, go to Edit Scheme... and select the Test scheme.
  • On the Arguments tab, uncheck Use the Run action's arguments and environment variables
  • Add the following environment variables for your server. The values should be the same as you pass in to the connect: method.
    • HOST (server\instance:port)
    • DATABASE (optional)
    • USERNAME
    • PASSWORD

Known Issues

PR's welcome!

  • strings: FreeTDS incorrectly returns an empty string "" for a single space " "
  • money: FreeTDS will truncate the rightmost 2 digits.
  • OSX support: FreeTDS-iOS needs to be compiled to support OSX and Podspec updated
  • No support for stored procedures with out parameters (yet)
  • No support for returning number of rows changed (yet)
  • Swift bindings: I welcome a PR to make the API more Swift-friendly

##Demo Project Open the Xcode project inside the SQLClient folder.

Installation

CocoaPods

CocoaPods is the preferred way to install this library.

  1. Open a Terminal window. Update RubyGems by entering: sudo gem update --system. Enter your password when prompted.
  2. Install CocoaPods by entering sudo gem install cocoapods.
  3. Create a file at the root of your Xcode project folder called Podfile.
  4. Enter the following text: pod 'SQLClient', '~> 1.0.0'
  5. In Terminal navigate to this folder and enter pod install.
  6. You will see a new SQLClient.xcworkspace file. Open this file in Xcode to work with this project from now on.

Manual

  1. Drag and drop the contents of the SQLClient/SQLClient/SQLClient folder into your Xcode project.
  2. Select Copy items into destination group's folder (if needed).
  3. Go to Project > Build Phases > Link Binary With Libraries.
  4. Click + and add libiconv.dylib.

Documentation

SQLClient Class Reference

SQLClient: A Native Microsoft SQL Server Library for iOS

Credits

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].