Using ODBC Data from Swift
If you follow the Druware twitter feed, you already know that we have been working on making the ODBCKit framework work with Apple's new Swift programming language. The truth is that the framework works with very few changes, but there are some convenience things that we have been working on to make it cleaner. In essence this means adopting some of the modern features of Objective-C like @properties, at least for a first pass. So, where do things stand today? well, with the code that is presently in the repository, we can use the framework quite easily. The example code below creates a connection to a MS SQL database using the Actual Technologies ODBC driver, it queries a table named casemaster and fetches a list of all records where the status field is equal to A. It then prints the case number to a line on the command line. It is simple, but it demonstrates the basics of working with an ODBC connection and recordset in a minimal bit of code.
Over the next few weeks we hope to finalize our changes to the code and update the framework download to have full support for Swift and be ready for Yosemite.
// // main.swift // ODBCKitSwiftClient // // Created by Andy Satori on 8/22/14. // Copyright (c) 2014 Druware Software Designs. All rights reserved. // import Foundation import ODBCKit println("Testing ODBCKit from Swift") var odbcconnection: ODBCConnection; odbcconnection = ODBCConnection(); odbcconnection.initSQLEnvironment(); odbcconnection.UserName = "domain\\user"; // SQL Server Domain Authentication odbcconnection.Password = "password!"; odbcconnection.Dsn = "TestDSN"; if (!odbcconnection.connect()) { if (!odbcconnection.isConnected()) { println("Connection Failed"); odbcconnection.close(); exit(0); } } // test a data fetch var rs: ODBCRecordset rs = odbcconnection.open("select * from casemaster where status = 'A'") while (!rs.isEOF()) { println("CaseNumber: " + rs.fieldByName("casenumber").asString()) rs.moveNext() } rs.close() // close the connection odbcconnection.close()













