Giter Site home page Giter Site logo

tds-kit's Introduction

TDSKit

Microsoft SQL Server client for iOS, watchOS, tvOS, and macOS. An Objective-C wrapper around the open-source FreeTDS library.

Sample Usage

#import "TDSClient.h"

TDSClient* client = [TDSClient new];
[client connect:@"server\instance:port" username:@"user" password:@"password" 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];
      }];
    }
}];

Type Conversion

TDSClient 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 TDSClientTests 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 (sa is SQL Server’s default admin username)
    • PASSWORD

To start an SQL Server with the AdventureWorks sample database:

docker run -p 1433:1433 -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=V3ry_g00d_p4ssw0rd' -d chriseaton/adventureworks:latest

Known Issues

PRs welcome!

  • strings: FreeTDS incorrectly returns an empty string "" for a single space " "
  • money: FreeTDS will truncate the rightmost 2 digits.
  • No support for stored procedures with out parameters (yet)
  • No support for returning number of rows changed (yet)

tds-kit's People

Contributors

freysie avatar fwaddle avatar martinrybak avatar nhgrif avatar readmecritic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.