├── .gitignore
├── LICENSE.txt
├── README.md
├── SQLClient.podspec
└── SQLClient
├── SQLClient.xcodeproj
├── project.pbxproj
└── project.xcworkspace
│ └── contents.xcworkspacedata
├── SQLClient
├── Images.xcassets
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── Icon-40@2x.png
│ │ ├── Icon-40@3x.png
│ │ ├── Icon-60@2x.png
│ │ ├── Icon-60@3x.png
│ │ ├── Icon-Small.png
│ │ ├── Icon-Small@2x.png
│ │ ├── Icon-Small@3x.png
│ │ ├── Icon.png
│ │ └── Icon@2x.png
│ ├── Contents.json
│ └── LaunchImage.launchimage
│ │ ├── Contents.json
│ │ ├── Default-568h@2x~iphone.png
│ │ ├── Default-667h@2x~iphone.png
│ │ └── Default-736h@3x~iphone.png
├── SQLAppDelegate.h
├── SQLAppDelegate.m
├── SQLClient-Info.plist
├── SQLClient-Prefix.pch
├── SQLClient
│ ├── SQLClient.h
│ ├── SQLClient.m
│ ├── bkpublic.h
│ ├── cspublic.h
│ ├── cstypes.h
│ ├── ctpublic.h
│ ├── libsybdb.a
│ ├── odbcss.h
│ ├── sqldb.h
│ ├── sqlfront.h
│ ├── sybdb.h
│ ├── syberror.h
│ ├── sybfront.h
│ └── tds_sysdep_public.h
├── SQLViewController.h
├── SQLViewController.m
├── en.lproj
│ └── InfoPlist.strings
└── main.m
└── SQLClientTests
├── SQLClientTests-Info.plist
├── SQLClientTests.m
└── en.lproj
└── InfoPlist.strings
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | .DS_Store
3 | */build/*
4 | *.pbxuser
5 | !default.pbxuser
6 | *.mode1v3
7 | !default.mode1v3
8 | *.mode2v3
9 | !default.mode2v3
10 | *.perspectivev3
11 | !default.perspectivev3
12 | xcuserdata
13 | profile
14 | *.moved-aside
15 | DerivedData
16 | .idea/
17 | *.hmap
18 | *.xccheckout
19 |
20 | #CocoaPods
21 | Pods
22 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Martin Rybak
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SQLClient
2 | =========
3 |
4 | Native Microsoft SQL Server client for iOS. An Objective-C wrapper around the open-source [FreeTDS](https://github.com/FreeTDS/freetds/) library.
5 |
6 | ## Sample Usage
7 |
8 |
9 | #import "SQLClient.h"
10 |
11 | SQLClient* client = [SQLClient sharedInstance];
12 | [client connect:@"server\instance:port" username:@"user" password:@"pass" database:@"db" completion:^(BOOL success) {
13 | if (success) {
14 | [client execute:@"SELECT * FROM Users" completion:^(NSArray* results) {
15 | for (NSArray* table in results) {
16 | for (NSDictionary* row in table) {
17 | for (NSString* column in row) {
18 | NSLog(@"%@=%@", column, row[column]);
19 | }
20 | }
21 | }
22 | [client disconnect];
23 | }];
24 | }
25 | }];
26 |
27 |
28 | ## Errors
29 |
30 | FreeTDS communicates both errors and messages. `SQLClient` rebroadcasts both via `NSNotificationCenter`:
31 |
32 | ```
33 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(error:) name:SQLClientErrorNotification object:nil];
34 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(message:) name:SQLClientMessageNotification object:nil];
35 |
36 | - (void)error:(NSNotification*)notification
37 | {
38 | NSNumber* code = notification.userInfo[SQLClientCodeKey];
39 | NSString* message = notification.userInfo[SQLClientMessageKey];
40 | NSNumber* severity = notification.userInfo[SQLClientSeverityKey];
41 | NSLog(@"Error #%@: %@ (Severity %@)", code, message, severity);
42 | }
43 |
44 | - (void)message:(NSNotification*)notification
45 | {
46 | NSString* message = notification.userInfo[SQLClientMessageKey];
47 | NSLog(@"Message: %@", message);
48 | }
49 | ```
50 |
51 | ## Type Conversion
52 | SQLClient maps SQL Server data types into the following native Objective-C types:
53 |
54 | * bigint → NSNumber
55 | * binary(n) → NSData
56 | * bit → NSNumber
57 | * char(n) → NSString
58 | * cursor → **not supported**
59 | * date → **NSDate** or **NSString**†
60 | * datetime → NSDate
61 | * datetime2 → **NSDate** or **NSString**†
62 | * datetimeoffset → **NSDate** or **NSString**†
63 | * decimal(p,s) → NSNumber
64 | * float(n) → NSNumber
65 | * image → **NSData**
66 | * int → NSNumber
67 | * money → NSDecimalNumber **(last 2 digits are truncated)**
68 | * nchar → NSString
69 | * ntext → NSString
70 | * null → NSNull
71 | * numeric(p,s) → NSNumber
72 | * nvarchar → NSString
73 | * nvarchar(max) → NSString
74 | * real → NSNumber
75 | * smalldatetime → NSDate
76 | * smallint → NSNumber
77 | * smallmoney → NSDecimalNumber
78 | * sql_variant → **not supported**
79 | * table → **not supported**
80 | * text → NSString*
81 | * time → **NSDate** or **NSString**†
82 | * timestamp → NSData
83 | * tinyint → NSNumber
84 | * uniqueidentifier → NSUUID
85 | * varbinary → NSData
86 | * varbinary(max) → NSData
87 | * varchar(max) → NSString*
88 | * varchar(n) → NSString
89 | * xml → NSString
90 |
91 | \*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.
92 |
93 | †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
94 | `4.2`, `5.0`, `7.0`, `7.1`, `7.2`, `7.3`, `7.4`, `auto`.
95 | A value of `auto` tells FreeTDS to use an autodetection (trial-and-error) algorithm to choose the highest available protocol version.
96 |
97 | * date
98 | * datetime2
99 | * datetimeoffset
100 | * time
101 |
102 | ## Testing
103 |
104 | 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:
105 |
106 | * SQL Server 7.0 (TDS 7.0)
107 | * SQL Server 2000 (TDS 7.1)
108 | * SQL Server 2005 (TDS 7.2)
109 | * SQL Server 2008 (TDS 7.3)
110 | * **TODO: add more!**
111 |
112 | To configure the connection for your server:
113 |
114 | * In Xcode, go to `Edit Scheme...` and select the `Test` scheme.
115 | * On the `Arguments` tab, uncheck `Use the Run action's arguments and environment variables`
116 | * Add the following environment variables for your server. The values should be the same as you pass in to the `connect:` method.
117 | * `HOST` (`server\instance:port`)
118 | * `DATABASE` (optional)
119 | * `USERNAME`
120 | * `PASSWORD`
121 |
122 | ## Known Issues
123 | PR's welcome!
124 |
125 | * **strings**: FreeTDS incorrectly returns an empty string "" for a single space " "
126 | * **money**: FreeTDS will truncate the rightmost 2 digits.
127 | * OSX support: [FreeTDS-iOS](https://github.com/martinrybak/FreeTDS-iOS) needs to be compiled to support OSX and Podspec updated
128 | * No support for stored procedures with out parameters (yet)
129 | * No support for returning number of rows changed (yet)
130 | * Swift bindings: I welcome a PR to make the API more Swift-friendly
131 |
132 | ##Demo Project
133 | Open the Xcode project inside the **SQLClient** folder.
134 |
135 |
136 | ## Installation
137 |
138 | ### CocoaPods
139 |
140 | CocoaPods is the preferred way to install this library.
141 |
142 | 1. Open a Terminal window. Update RubyGems by entering: `sudo gem update --system`. Enter your password when prompted.
143 | 2. Install CocoaPods by entering `sudo gem install cocoapods`.
144 | 3. Create a file at the root of your Xcode project folder called **Podfile**.
145 | 4. Enter the following text: `pod 'SQLClient', '~> 1.0.0'`
146 | 4. In Terminal navigate to this folder and enter `pod install`.
147 | 5. You will see a new **SQLClient.xcworkspace** file. Open this file in Xcode to work with this project from now on.
148 |
149 | ### Manual
150 |
151 | 1. Drag and drop the contents of the **SQLClient/SQLClient/SQLClient** folder into your Xcode project.
152 | 2. Select **Copy items into destination group's folder (if needed)**.
153 | 3. Go to Project > Build Phases > Link Binary With Libraries.
154 | 3. Click + and add **libiconv.dylib**.
155 |
156 | ## Documentation
157 |
158 | SQLClient Class Reference
159 |
160 | SQLClient: A Native Microsoft SQL Server Library for iOS
161 |
162 | ## Credits
163 |
164 | FreeTDS:
165 | http://www.freetds.org
166 |
167 | FreeTDS-iOS:
168 | https://github.com/patchhf/FreeTDS-iOS
169 |
170 | FreeTDS example code in C:
171 | http://freetds.schemamania.org/userguide/samplecode.htm
172 |
173 | SQL Server Logo
174 | © Microsoft
175 |
--------------------------------------------------------------------------------
/SQLClient.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = 'SQLClient'
3 | s.version = '1.0.0'
4 | s.license = 'MIT'
5 | s.summary = 'An Objective-C wrapper around the open-source FreeTDS library'
6 | s.homepage = 'https://github.com/martinrybak/SQLClient'
7 | s.authors = { 'Martin Rybak' => 'martin.rybak@gmail.com' }
8 | s.source = { :git => 'https://github.com/martinrybak/SQLClient.git', :tag => s.version.to_s }
9 | s.source_files = 'SQLClient/SQLClient/SQLClient/*.{h,m}'
10 | s.vendored_libraries = 'SQLClient/SQLClient/SQLClient/libsybdb.a'
11 | s.libraries = 'iconv'
12 | s.requires_arc = true
13 | s.ios.deployment_target = '7.0'
14 | s.tvos.deployment_target = '9.0'
15 | end
16 |
17 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 5B0FC84F180DCEB000DF4EFE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B0FC84E180DCEB000DF4EFE /* Foundation.framework */; };
11 | 5B0FC851180DCEB000DF4EFE /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B0FC850180DCEB000DF4EFE /* CoreGraphics.framework */; };
12 | 5B0FC853180DCEB000DF4EFE /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B0FC852180DCEB000DF4EFE /* UIKit.framework */; };
13 | 5B0FC859180DCEB000DF4EFE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5B0FC857180DCEB000DF4EFE /* InfoPlist.strings */; };
14 | 5B0FC85B180DCEB000DF4EFE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B0FC85A180DCEB000DF4EFE /* main.m */; };
15 | 5B0FC85F180DCEB000DF4EFE /* SQLAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B0FC85E180DCEB000DF4EFE /* SQLAppDelegate.m */; };
16 | 5B0FC865180DCEB000DF4EFE /* SQLViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B0FC864180DCEB000DF4EFE /* SQLViewController.m */; };
17 | 5B0FC867180DCEB000DF4EFE /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5B0FC866180DCEB000DF4EFE /* Images.xcassets */; };
18 | 5B0FC86E180DCEB000DF4EFE /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B0FC86D180DCEB000DF4EFE /* XCTest.framework */; };
19 | 5B0FC86F180DCEB000DF4EFE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B0FC84E180DCEB000DF4EFE /* Foundation.framework */; };
20 | 5B0FC870180DCEB000DF4EFE /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B0FC852180DCEB000DF4EFE /* UIKit.framework */; };
21 | 5B0FC878180DCEB000DF4EFE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5B0FC876180DCEB000DF4EFE /* InfoPlist.strings */; };
22 | 5B0FC87A180DCEB000DF4EFE /* SQLClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B0FC879180DCEB000DF4EFE /* SQLClientTests.m */; };
23 | 5B0FC888180DCF3800DF4EFE /* libiconv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B0FC887180DCF3800DF4EFE /* libiconv.dylib */; };
24 | 5B0FC8D9180DDF7E00DF4EFE /* SQLClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B0FC8D1180DDF7E00DF4EFE /* SQLClient.m */; };
25 | 5BC11BCC180EE4C9003471E4 /* libsybdb.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B0FC8CE180DDF7E00DF4EFE /* libsybdb.a */; };
26 | /* End PBXBuildFile section */
27 |
28 | /* Begin PBXContainerItemProxy section */
29 | 5B0FC871180DCEB000DF4EFE /* PBXContainerItemProxy */ = {
30 | isa = PBXContainerItemProxy;
31 | containerPortal = 5B0FC843180DCEB000DF4EFE /* Project object */;
32 | proxyType = 1;
33 | remoteGlobalIDString = 5B0FC84A180DCEB000DF4EFE;
34 | remoteInfo = SQLClient;
35 | };
36 | /* End PBXContainerItemProxy section */
37 |
38 | /* Begin PBXFileReference section */
39 | 5B0FC84B180DCEB000DF4EFE /* SQLClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SQLClient.app; sourceTree = BUILT_PRODUCTS_DIR; };
40 | 5B0FC84E180DCEB000DF4EFE /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
41 | 5B0FC850180DCEB000DF4EFE /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
42 | 5B0FC852180DCEB000DF4EFE /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
43 | 5B0FC856180DCEB000DF4EFE /* SQLClient-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SQLClient-Info.plist"; sourceTree = ""; };
44 | 5B0FC858180DCEB000DF4EFE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
45 | 5B0FC85A180DCEB000DF4EFE /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
46 | 5B0FC85C180DCEB000DF4EFE /* SQLClient-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SQLClient-Prefix.pch"; sourceTree = ""; };
47 | 5B0FC85D180DCEB000DF4EFE /* SQLAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQLAppDelegate.h; sourceTree = ""; };
48 | 5B0FC85E180DCEB000DF4EFE /* SQLAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SQLAppDelegate.m; sourceTree = ""; };
49 | 5B0FC863180DCEB000DF4EFE /* SQLViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SQLViewController.h; sourceTree = ""; };
50 | 5B0FC864180DCEB000DF4EFE /* SQLViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SQLViewController.m; sourceTree = ""; };
51 | 5B0FC866180DCEB000DF4EFE /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
52 | 5B0FC86C180DCEB000DF4EFE /* SQLClientTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SQLClientTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
53 | 5B0FC86D180DCEB000DF4EFE /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
54 | 5B0FC875180DCEB000DF4EFE /* SQLClientTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SQLClientTests-Info.plist"; sourceTree = ""; };
55 | 5B0FC877180DCEB000DF4EFE /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
56 | 5B0FC879180DCEB000DF4EFE /* SQLClientTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SQLClientTests.m; sourceTree = ""; };
57 | 5B0FC885180DCEDF00DF4EFE /* freetds.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = freetds.a; path = SQLClient/SQLClient/freetds.a; sourceTree = ""; };
58 | 5B0FC887180DCF3800DF4EFE /* libiconv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libiconv.dylib; path = usr/lib/libiconv.dylib; sourceTree = SDKROOT; };
59 | 5B0FC8CA180DDF7E00DF4EFE /* bkpublic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bkpublic.h; sourceTree = ""; };
60 | 5B0FC8CB180DDF7E00DF4EFE /* cspublic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cspublic.h; sourceTree = ""; };
61 | 5B0FC8CC180DDF7E00DF4EFE /* cstypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cstypes.h; sourceTree = ""; };
62 | 5B0FC8CD180DDF7E00DF4EFE /* ctpublic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ctpublic.h; sourceTree = ""; };
63 | 5B0FC8CE180DDF7E00DF4EFE /* libsybdb.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libsybdb.a; sourceTree = ""; };
64 | 5B0FC8CF180DDF7E00DF4EFE /* odbcss.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = odbcss.h; sourceTree = ""; };
65 | 5B0FC8D0180DDF7E00DF4EFE /* SQLClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLClient.h; sourceTree = ""; };
66 | 5B0FC8D1180DDF7E00DF4EFE /* SQLClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SQLClient.m; sourceTree = ""; };
67 | 5B0FC8D2180DDF7E00DF4EFE /* sqldb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sqldb.h; sourceTree = ""; };
68 | 5B0FC8D3180DDF7E00DF4EFE /* sqlfront.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sqlfront.h; sourceTree = ""; };
69 | 5B0FC8D4180DDF7E00DF4EFE /* sybdb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sybdb.h; sourceTree = ""; };
70 | 5B0FC8D5180DDF7E00DF4EFE /* syberror.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = syberror.h; sourceTree = ""; };
71 | 5B0FC8D6180DDF7E00DF4EFE /* sybfront.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sybfront.h; sourceTree = ""; };
72 | 5B0FC8D7180DDF7E00DF4EFE /* tds_sysdep_public.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tds_sysdep_public.h; sourceTree = ""; };
73 | /* End PBXFileReference section */
74 |
75 | /* Begin PBXFrameworksBuildPhase section */
76 | 5B0FC848180DCEB000DF4EFE /* Frameworks */ = {
77 | isa = PBXFrameworksBuildPhase;
78 | buildActionMask = 2147483647;
79 | files = (
80 | 5B0FC851180DCEB000DF4EFE /* CoreGraphics.framework in Frameworks */,
81 | 5B0FC853180DCEB000DF4EFE /* UIKit.framework in Frameworks */,
82 | 5B0FC84F180DCEB000DF4EFE /* Foundation.framework in Frameworks */,
83 | 5BC11BCC180EE4C9003471E4 /* libsybdb.a in Frameworks */,
84 | 5B0FC888180DCF3800DF4EFE /* libiconv.dylib in Frameworks */,
85 | );
86 | runOnlyForDeploymentPostprocessing = 0;
87 | };
88 | 5B0FC869180DCEB000DF4EFE /* Frameworks */ = {
89 | isa = PBXFrameworksBuildPhase;
90 | buildActionMask = 2147483647;
91 | files = (
92 | 5B0FC86E180DCEB000DF4EFE /* XCTest.framework in Frameworks */,
93 | 5B0FC870180DCEB000DF4EFE /* UIKit.framework in Frameworks */,
94 | 5B0FC86F180DCEB000DF4EFE /* Foundation.framework in Frameworks */,
95 | );
96 | runOnlyForDeploymentPostprocessing = 0;
97 | };
98 | /* End PBXFrameworksBuildPhase section */
99 |
100 | /* Begin PBXGroup section */
101 | 5B0FC842180DCEB000DF4EFE = {
102 | isa = PBXGroup;
103 | children = (
104 | 5B0FC854180DCEB000DF4EFE /* SQLClient */,
105 | 5B0FC873180DCEB000DF4EFE /* SQLClientTests */,
106 | 5B0FC84D180DCEB000DF4EFE /* Frameworks */,
107 | 5B0FC84C180DCEB000DF4EFE /* Products */,
108 | );
109 | sourceTree = "";
110 | };
111 | 5B0FC84C180DCEB000DF4EFE /* Products */ = {
112 | isa = PBXGroup;
113 | children = (
114 | 5B0FC84B180DCEB000DF4EFE /* SQLClient.app */,
115 | 5B0FC86C180DCEB000DF4EFE /* SQLClientTests.xctest */,
116 | );
117 | name = Products;
118 | sourceTree = "";
119 | };
120 | 5B0FC84D180DCEB000DF4EFE /* Frameworks */ = {
121 | isa = PBXGroup;
122 | children = (
123 | 5B0FC887180DCF3800DF4EFE /* libiconv.dylib */,
124 | 5B0FC885180DCEDF00DF4EFE /* freetds.a */,
125 | 5B0FC84E180DCEB000DF4EFE /* Foundation.framework */,
126 | 5B0FC850180DCEB000DF4EFE /* CoreGraphics.framework */,
127 | 5B0FC852180DCEB000DF4EFE /* UIKit.framework */,
128 | 5B0FC86D180DCEB000DF4EFE /* XCTest.framework */,
129 | );
130 | name = Frameworks;
131 | sourceTree = "";
132 | };
133 | 5B0FC854180DCEB000DF4EFE /* SQLClient */ = {
134 | isa = PBXGroup;
135 | children = (
136 | 5B0FC8C9180DDF7E00DF4EFE /* SQLClient */,
137 | 5B0FC85D180DCEB000DF4EFE /* SQLAppDelegate.h */,
138 | 5B0FC85E180DCEB000DF4EFE /* SQLAppDelegate.m */,
139 | 5B0FC863180DCEB000DF4EFE /* SQLViewController.h */,
140 | 5B0FC864180DCEB000DF4EFE /* SQLViewController.m */,
141 | 5B0FC866180DCEB000DF4EFE /* Images.xcassets */,
142 | 5B0FC855180DCEB000DF4EFE /* Supporting Files */,
143 | );
144 | path = SQLClient;
145 | sourceTree = "";
146 | };
147 | 5B0FC855180DCEB000DF4EFE /* Supporting Files */ = {
148 | isa = PBXGroup;
149 | children = (
150 | 5B0FC856180DCEB000DF4EFE /* SQLClient-Info.plist */,
151 | 5B0FC857180DCEB000DF4EFE /* InfoPlist.strings */,
152 | 5B0FC85A180DCEB000DF4EFE /* main.m */,
153 | 5B0FC85C180DCEB000DF4EFE /* SQLClient-Prefix.pch */,
154 | );
155 | name = "Supporting Files";
156 | sourceTree = "";
157 | };
158 | 5B0FC873180DCEB000DF4EFE /* SQLClientTests */ = {
159 | isa = PBXGroup;
160 | children = (
161 | 5B0FC879180DCEB000DF4EFE /* SQLClientTests.m */,
162 | 5B0FC874180DCEB000DF4EFE /* Supporting Files */,
163 | );
164 | path = SQLClientTests;
165 | sourceTree = "";
166 | };
167 | 5B0FC874180DCEB000DF4EFE /* Supporting Files */ = {
168 | isa = PBXGroup;
169 | children = (
170 | 5B0FC875180DCEB000DF4EFE /* SQLClientTests-Info.plist */,
171 | 5B0FC876180DCEB000DF4EFE /* InfoPlist.strings */,
172 | );
173 | name = "Supporting Files";
174 | sourceTree = "";
175 | };
176 | 5B0FC8C9180DDF7E00DF4EFE /* SQLClient */ = {
177 | isa = PBXGroup;
178 | children = (
179 | 5B0FC8CE180DDF7E00DF4EFE /* libsybdb.a */,
180 | 5B0FC8D0180DDF7E00DF4EFE /* SQLClient.h */,
181 | 5B0FC8D1180DDF7E00DF4EFE /* SQLClient.m */,
182 | 5B0FC8CA180DDF7E00DF4EFE /* bkpublic.h */,
183 | 5B0FC8CB180DDF7E00DF4EFE /* cspublic.h */,
184 | 5B0FC8CC180DDF7E00DF4EFE /* cstypes.h */,
185 | 5B0FC8CD180DDF7E00DF4EFE /* ctpublic.h */,
186 | 5B0FC8CF180DDF7E00DF4EFE /* odbcss.h */,
187 | 5B0FC8D2180DDF7E00DF4EFE /* sqldb.h */,
188 | 5B0FC8D3180DDF7E00DF4EFE /* sqlfront.h */,
189 | 5B0FC8D4180DDF7E00DF4EFE /* sybdb.h */,
190 | 5B0FC8D5180DDF7E00DF4EFE /* syberror.h */,
191 | 5B0FC8D6180DDF7E00DF4EFE /* sybfront.h */,
192 | 5B0FC8D7180DDF7E00DF4EFE /* tds_sysdep_public.h */,
193 | );
194 | path = SQLClient;
195 | sourceTree = "";
196 | };
197 | /* End PBXGroup section */
198 |
199 | /* Begin PBXNativeTarget section */
200 | 5B0FC84A180DCEB000DF4EFE /* SQLClient */ = {
201 | isa = PBXNativeTarget;
202 | buildConfigurationList = 5B0FC87D180DCEB000DF4EFE /* Build configuration list for PBXNativeTarget "SQLClient" */;
203 | buildPhases = (
204 | 5B0FC847180DCEB000DF4EFE /* Sources */,
205 | 5B0FC848180DCEB000DF4EFE /* Frameworks */,
206 | 5B0FC849180DCEB000DF4EFE /* Resources */,
207 | );
208 | buildRules = (
209 | );
210 | dependencies = (
211 | );
212 | name = SQLClient;
213 | productName = SQLClient;
214 | productReference = 5B0FC84B180DCEB000DF4EFE /* SQLClient.app */;
215 | productType = "com.apple.product-type.application";
216 | };
217 | 5B0FC86B180DCEB000DF4EFE /* SQLClientTests */ = {
218 | isa = PBXNativeTarget;
219 | buildConfigurationList = 5B0FC880180DCEB000DF4EFE /* Build configuration list for PBXNativeTarget "SQLClientTests" */;
220 | buildPhases = (
221 | 5B0FC868180DCEB000DF4EFE /* Sources */,
222 | 5B0FC869180DCEB000DF4EFE /* Frameworks */,
223 | 5B0FC86A180DCEB000DF4EFE /* Resources */,
224 | );
225 | buildRules = (
226 | );
227 | dependencies = (
228 | 5B0FC872180DCEB000DF4EFE /* PBXTargetDependency */,
229 | );
230 | name = SQLClientTests;
231 | productName = SQLClientTests;
232 | productReference = 5B0FC86C180DCEB000DF4EFE /* SQLClientTests.xctest */;
233 | productType = "com.apple.product-type.bundle.unit-test";
234 | };
235 | /* End PBXNativeTarget section */
236 |
237 | /* Begin PBXProject section */
238 | 5B0FC843180DCEB000DF4EFE /* Project object */ = {
239 | isa = PBXProject;
240 | attributes = {
241 | CLASSPREFIX = SQL;
242 | LastUpgradeCheck = 0800;
243 | ORGANIZATIONNAME = "Martin Rybak";
244 | TargetAttributes = {
245 | 5B0FC86B180DCEB000DF4EFE = {
246 | TestTargetID = 5B0FC84A180DCEB000DF4EFE;
247 | };
248 | };
249 | };
250 | buildConfigurationList = 5B0FC846180DCEB000DF4EFE /* Build configuration list for PBXProject "SQLClient" */;
251 | compatibilityVersion = "Xcode 3.2";
252 | developmentRegion = English;
253 | hasScannedForEncodings = 0;
254 | knownRegions = (
255 | en,
256 | Base,
257 | );
258 | mainGroup = 5B0FC842180DCEB000DF4EFE;
259 | productRefGroup = 5B0FC84C180DCEB000DF4EFE /* Products */;
260 | projectDirPath = "";
261 | projectRoot = "";
262 | targets = (
263 | 5B0FC84A180DCEB000DF4EFE /* SQLClient */,
264 | 5B0FC86B180DCEB000DF4EFE /* SQLClientTests */,
265 | );
266 | };
267 | /* End PBXProject section */
268 |
269 | /* Begin PBXResourcesBuildPhase section */
270 | 5B0FC849180DCEB000DF4EFE /* Resources */ = {
271 | isa = PBXResourcesBuildPhase;
272 | buildActionMask = 2147483647;
273 | files = (
274 | 5B0FC867180DCEB000DF4EFE /* Images.xcassets in Resources */,
275 | 5B0FC859180DCEB000DF4EFE /* InfoPlist.strings in Resources */,
276 | );
277 | runOnlyForDeploymentPostprocessing = 0;
278 | };
279 | 5B0FC86A180DCEB000DF4EFE /* Resources */ = {
280 | isa = PBXResourcesBuildPhase;
281 | buildActionMask = 2147483647;
282 | files = (
283 | 5B0FC878180DCEB000DF4EFE /* InfoPlist.strings in Resources */,
284 | );
285 | runOnlyForDeploymentPostprocessing = 0;
286 | };
287 | /* End PBXResourcesBuildPhase section */
288 |
289 | /* Begin PBXSourcesBuildPhase section */
290 | 5B0FC847180DCEB000DF4EFE /* Sources */ = {
291 | isa = PBXSourcesBuildPhase;
292 | buildActionMask = 2147483647;
293 | files = (
294 | 5B0FC85B180DCEB000DF4EFE /* main.m in Sources */,
295 | 5B0FC8D9180DDF7E00DF4EFE /* SQLClient.m in Sources */,
296 | 5B0FC865180DCEB000DF4EFE /* SQLViewController.m in Sources */,
297 | 5B0FC85F180DCEB000DF4EFE /* SQLAppDelegate.m in Sources */,
298 | );
299 | runOnlyForDeploymentPostprocessing = 0;
300 | };
301 | 5B0FC868180DCEB000DF4EFE /* Sources */ = {
302 | isa = PBXSourcesBuildPhase;
303 | buildActionMask = 2147483647;
304 | files = (
305 | 5B0FC87A180DCEB000DF4EFE /* SQLClientTests.m in Sources */,
306 | );
307 | runOnlyForDeploymentPostprocessing = 0;
308 | };
309 | /* End PBXSourcesBuildPhase section */
310 |
311 | /* Begin PBXTargetDependency section */
312 | 5B0FC872180DCEB000DF4EFE /* PBXTargetDependency */ = {
313 | isa = PBXTargetDependency;
314 | target = 5B0FC84A180DCEB000DF4EFE /* SQLClient */;
315 | targetProxy = 5B0FC871180DCEB000DF4EFE /* PBXContainerItemProxy */;
316 | };
317 | /* End PBXTargetDependency section */
318 |
319 | /* Begin PBXVariantGroup section */
320 | 5B0FC857180DCEB000DF4EFE /* InfoPlist.strings */ = {
321 | isa = PBXVariantGroup;
322 | children = (
323 | 5B0FC858180DCEB000DF4EFE /* en */,
324 | );
325 | name = InfoPlist.strings;
326 | sourceTree = "";
327 | };
328 | 5B0FC876180DCEB000DF4EFE /* InfoPlist.strings */ = {
329 | isa = PBXVariantGroup;
330 | children = (
331 | 5B0FC877180DCEB000DF4EFE /* en */,
332 | );
333 | name = InfoPlist.strings;
334 | sourceTree = "";
335 | };
336 | /* End PBXVariantGroup section */
337 |
338 | /* Begin XCBuildConfiguration section */
339 | 5B0FC87B180DCEB000DF4EFE /* Debug */ = {
340 | isa = XCBuildConfiguration;
341 | buildSettings = {
342 | ALWAYS_SEARCH_USER_PATHS = NO;
343 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
344 | CLANG_CXX_LIBRARY = "libc++";
345 | CLANG_ENABLE_MODULES = YES;
346 | CLANG_ENABLE_OBJC_ARC = YES;
347 | CLANG_WARN_BOOL_CONVERSION = YES;
348 | CLANG_WARN_CONSTANT_CONVERSION = YES;
349 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
350 | CLANG_WARN_EMPTY_BODY = YES;
351 | CLANG_WARN_ENUM_CONVERSION = YES;
352 | CLANG_WARN_INFINITE_RECURSION = YES;
353 | CLANG_WARN_INT_CONVERSION = YES;
354 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
355 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
356 | CLANG_WARN_UNREACHABLE_CODE = YES;
357 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
358 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
359 | COPY_PHASE_STRIP = NO;
360 | ENABLE_STRICT_OBJC_MSGSEND = YES;
361 | ENABLE_TESTABILITY = YES;
362 | GCC_C_LANGUAGE_STANDARD = gnu99;
363 | GCC_DYNAMIC_NO_PIC = NO;
364 | GCC_NO_COMMON_BLOCKS = YES;
365 | GCC_OPTIMIZATION_LEVEL = 0;
366 | GCC_PREPROCESSOR_DEFINITIONS = (
367 | "DEBUG=1",
368 | "$(inherited)",
369 | );
370 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
371 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
372 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
373 | GCC_WARN_UNDECLARED_SELECTOR = YES;
374 | GCC_WARN_UNINITIALIZED_AUTOS = YES;
375 | GCC_WARN_UNUSED_FUNCTION = YES;
376 | GCC_WARN_UNUSED_VARIABLE = YES;
377 | IPHONEOS_DEPLOYMENT_TARGET = 7.0;
378 | ONLY_ACTIVE_ARCH = YES;
379 | SDKROOT = iphoneos;
380 | };
381 | name = Debug;
382 | };
383 | 5B0FC87C180DCEB000DF4EFE /* Release */ = {
384 | isa = XCBuildConfiguration;
385 | buildSettings = {
386 | ALWAYS_SEARCH_USER_PATHS = NO;
387 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
388 | CLANG_CXX_LIBRARY = "libc++";
389 | CLANG_ENABLE_MODULES = YES;
390 | CLANG_ENABLE_OBJC_ARC = YES;
391 | CLANG_WARN_BOOL_CONVERSION = YES;
392 | CLANG_WARN_CONSTANT_CONVERSION = YES;
393 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
394 | CLANG_WARN_EMPTY_BODY = YES;
395 | CLANG_WARN_ENUM_CONVERSION = YES;
396 | CLANG_WARN_INFINITE_RECURSION = YES;
397 | CLANG_WARN_INT_CONVERSION = YES;
398 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
399 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
400 | CLANG_WARN_UNREACHABLE_CODE = YES;
401 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
402 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
403 | COPY_PHASE_STRIP = YES;
404 | ENABLE_NS_ASSERTIONS = NO;
405 | ENABLE_STRICT_OBJC_MSGSEND = YES;
406 | GCC_C_LANGUAGE_STANDARD = gnu99;
407 | GCC_NO_COMMON_BLOCKS = YES;
408 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
409 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
410 | GCC_WARN_UNDECLARED_SELECTOR = YES;
411 | GCC_WARN_UNINITIALIZED_AUTOS = YES;
412 | GCC_WARN_UNUSED_FUNCTION = YES;
413 | GCC_WARN_UNUSED_VARIABLE = YES;
414 | IPHONEOS_DEPLOYMENT_TARGET = 7.0;
415 | SDKROOT = iphoneos;
416 | VALIDATE_PRODUCT = YES;
417 | };
418 | name = Release;
419 | };
420 | 5B0FC87E180DCEB000DF4EFE /* Debug */ = {
421 | isa = XCBuildConfiguration;
422 | buildSettings = {
423 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
424 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
425 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
426 | GCC_PREFIX_HEADER = "SQLClient/SQLClient-Prefix.pch";
427 | HEADER_SEARCH_PATHS = (
428 | "$(inherited)",
429 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
430 | );
431 | INFOPLIST_FILE = "SQLClient/SQLClient-Info.plist";
432 | LIBRARY_SEARCH_PATHS = (
433 | "$(inherited)",
434 | "$(SRCROOT)/SQLClient/SQLClient",
435 | );
436 | ONLY_ACTIVE_ARCH = YES;
437 | PRODUCT_BUNDLE_IDENTIFIER = "com.martinrybak.${PRODUCT_NAME:rfc1034identifier}";
438 | PRODUCT_NAME = "$(TARGET_NAME)";
439 | VALID_ARCHS = "armv7 armv7s arm64";
440 | WRAPPER_EXTENSION = app;
441 | };
442 | name = Debug;
443 | };
444 | 5B0FC87F180DCEB000DF4EFE /* Release */ = {
445 | isa = XCBuildConfiguration;
446 | buildSettings = {
447 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
448 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
449 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
450 | GCC_PREFIX_HEADER = "SQLClient/SQLClient-Prefix.pch";
451 | HEADER_SEARCH_PATHS = (
452 | "$(inherited)",
453 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
454 | );
455 | INFOPLIST_FILE = "SQLClient/SQLClient-Info.plist";
456 | LIBRARY_SEARCH_PATHS = (
457 | "$(inherited)",
458 | "$(SRCROOT)/SQLClient/SQLClient",
459 | );
460 | ONLY_ACTIVE_ARCH = NO;
461 | PRODUCT_BUNDLE_IDENTIFIER = "com.martinrybak.${PRODUCT_NAME:rfc1034identifier}";
462 | PRODUCT_NAME = "$(TARGET_NAME)";
463 | VALID_ARCHS = "armv7 armv7s arm64";
464 | WRAPPER_EXTENSION = app;
465 | };
466 | name = Release;
467 | };
468 | 5B0FC881180DCEB000DF4EFE /* Debug */ = {
469 | isa = XCBuildConfiguration;
470 | buildSettings = {
471 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/SQLClient.app/SQLClient";
472 | FRAMEWORK_SEARCH_PATHS = (
473 | "$(SDKROOT)/Developer/Library/Frameworks",
474 | "$(inherited)",
475 | "$(DEVELOPER_FRAMEWORKS_DIR)",
476 | );
477 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
478 | GCC_PREFIX_HEADER = "SQLClient/SQLClient-Prefix.pch";
479 | GCC_PREPROCESSOR_DEFINITIONS = (
480 | "DEBUG=1",
481 | "$(inherited)",
482 | );
483 | INFOPLIST_FILE = "SQLClientTests/SQLClientTests-Info.plist";
484 | PRODUCT_BUNDLE_IDENTIFIER = "com.martinrybak.${PRODUCT_NAME:rfc1034identifier}";
485 | PRODUCT_NAME = "$(TARGET_NAME)";
486 | TEST_HOST = "$(BUNDLE_LOADER)";
487 | WRAPPER_EXTENSION = xctest;
488 | };
489 | name = Debug;
490 | };
491 | 5B0FC882180DCEB000DF4EFE /* Release */ = {
492 | isa = XCBuildConfiguration;
493 | buildSettings = {
494 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/SQLClient.app/SQLClient";
495 | FRAMEWORK_SEARCH_PATHS = (
496 | "$(SDKROOT)/Developer/Library/Frameworks",
497 | "$(inherited)",
498 | "$(DEVELOPER_FRAMEWORKS_DIR)",
499 | );
500 | GCC_PRECOMPILE_PREFIX_HEADER = YES;
501 | GCC_PREFIX_HEADER = "SQLClient/SQLClient-Prefix.pch";
502 | INFOPLIST_FILE = "SQLClientTests/SQLClientTests-Info.plist";
503 | PRODUCT_BUNDLE_IDENTIFIER = "com.martinrybak.${PRODUCT_NAME:rfc1034identifier}";
504 | PRODUCT_NAME = "$(TARGET_NAME)";
505 | TEST_HOST = "$(BUNDLE_LOADER)";
506 | WRAPPER_EXTENSION = xctest;
507 | };
508 | name = Release;
509 | };
510 | /* End XCBuildConfiguration section */
511 |
512 | /* Begin XCConfigurationList section */
513 | 5B0FC846180DCEB000DF4EFE /* Build configuration list for PBXProject "SQLClient" */ = {
514 | isa = XCConfigurationList;
515 | buildConfigurations = (
516 | 5B0FC87B180DCEB000DF4EFE /* Debug */,
517 | 5B0FC87C180DCEB000DF4EFE /* Release */,
518 | );
519 | defaultConfigurationIsVisible = 0;
520 | defaultConfigurationName = Release;
521 | };
522 | 5B0FC87D180DCEB000DF4EFE /* Build configuration list for PBXNativeTarget "SQLClient" */ = {
523 | isa = XCConfigurationList;
524 | buildConfigurations = (
525 | 5B0FC87E180DCEB000DF4EFE /* Debug */,
526 | 5B0FC87F180DCEB000DF4EFE /* Release */,
527 | );
528 | defaultConfigurationIsVisible = 0;
529 | defaultConfigurationName = Release;
530 | };
531 | 5B0FC880180DCEB000DF4EFE /* Build configuration list for PBXNativeTarget "SQLClientTests" */ = {
532 | isa = XCConfigurationList;
533 | buildConfigurations = (
534 | 5B0FC881180DCEB000DF4EFE /* Debug */,
535 | 5B0FC882180DCEB000DF4EFE /* Release */,
536 | );
537 | defaultConfigurationIsVisible = 0;
538 | defaultConfigurationName = Release;
539 | };
540 | /* End XCConfigurationList section */
541 | };
542 | rootObject = 5B0FC843180DCEB000DF4EFE /* Project object */;
543 | }
544 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "29x29",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-Small.png",
7 | "scale" : "1x"
8 | },
9 | {
10 | "size" : "29x29",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-Small@2x.png",
13 | "scale" : "2x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-Small@3x.png",
19 | "scale" : "3x"
20 | },
21 | {
22 | "size" : "40x40",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-40@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "40x40",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-40@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "57x57",
35 | "idiom" : "iphone",
36 | "filename" : "Icon.png",
37 | "scale" : "1x"
38 | },
39 | {
40 | "size" : "57x57",
41 | "idiom" : "iphone",
42 | "filename" : "Icon@2x.png",
43 | "scale" : "2x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-60@3x.png",
55 | "scale" : "3x"
56 | }
57 | ],
58 | "info" : {
59 | "version" : 1,
60 | "author" : "xcode"
61 | }
62 | }
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-40@2x.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-40@3x.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-60@2x.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-60@3x.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-Small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-Small.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-Small@2x.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon-Small@3x.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/AppIcon.appiconset/Icon@2x.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "extent" : "full-screen",
5 | "idiom" : "iphone",
6 | "subtype" : "736h",
7 | "filename" : "Default-736h@3x~iphone.png",
8 | "minimum-system-version" : "8.0",
9 | "orientation" : "portrait",
10 | "scale" : "3x"
11 | },
12 | {
13 | "orientation" : "landscape",
14 | "idiom" : "iphone",
15 | "extent" : "full-screen",
16 | "minimum-system-version" : "8.0",
17 | "subtype" : "736h",
18 | "scale" : "3x"
19 | },
20 | {
21 | "extent" : "full-screen",
22 | "idiom" : "iphone",
23 | "subtype" : "667h",
24 | "filename" : "Default-667h@2x~iphone.png",
25 | "minimum-system-version" : "8.0",
26 | "orientation" : "portrait",
27 | "scale" : "2x"
28 | },
29 | {
30 | "orientation" : "portrait",
31 | "idiom" : "iphone",
32 | "extent" : "full-screen",
33 | "minimum-system-version" : "7.0",
34 | "scale" : "2x"
35 | },
36 | {
37 | "extent" : "full-screen",
38 | "idiom" : "iphone",
39 | "subtype" : "retina4",
40 | "filename" : "Default-568h@2x~iphone.png",
41 | "minimum-system-version" : "7.0",
42 | "orientation" : "portrait",
43 | "scale" : "2x"
44 | },
45 | {
46 | "orientation" : "portrait",
47 | "idiom" : "iphone",
48 | "extent" : "full-screen",
49 | "scale" : "1x"
50 | },
51 | {
52 | "orientation" : "portrait",
53 | "idiom" : "iphone",
54 | "extent" : "full-screen",
55 | "scale" : "2x"
56 | },
57 | {
58 | "orientation" : "portrait",
59 | "idiom" : "iphone",
60 | "extent" : "full-screen",
61 | "subtype" : "retina4",
62 | "scale" : "2x"
63 | }
64 | ],
65 | "info" : {
66 | "version" : 1,
67 | "author" : "xcode"
68 | }
69 | }
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/LaunchImage.launchimage/Default-568h@2x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/LaunchImage.launchimage/Default-568h@2x~iphone.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/LaunchImage.launchimage/Default-667h@2x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/LaunchImage.launchimage/Default-667h@2x~iphone.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/Images.xcassets/LaunchImage.launchimage/Default-736h@3x~iphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/Images.xcassets/LaunchImage.launchimage/Default-736h@3x~iphone.png
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLAppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // SQLAppDelegate.h
3 | // SQLClient
4 | //
5 | // Created by Martin Rybak on 10/15/13.
6 | // Copyright (c) 2013 Martin Rybak. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SQLAppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow* window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLAppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // SQLAppDelegate.m
3 | // SQLClient
4 | //
5 | // Created by Martin Rybak on 10/15/13.
6 | // Copyright (c) 2013 Martin Rybak. All rights reserved.
7 | //
8 |
9 | #import "SQLAppDelegate.h"
10 | #import "SQLViewController.h"
11 |
12 | @implementation SQLAppDelegate
13 |
14 | - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
15 | {
16 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
17 |
18 | //Only show SQLViewController if not testing
19 | if (NSClassFromString(@"XCTest")) {
20 | self.window.rootViewController = [[UIViewController alloc] init];
21 | } else {
22 | self.window.rootViewController = [[SQLViewController alloc] init];
23 | }
24 |
25 | [self.window makeKeyAndVisible];
26 | return YES;
27 | }
28 |
29 | @end
30 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 28
25 | LSRequiresIPhoneOS
26 |
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #import
8 |
9 | #ifndef __IPHONE_5_0
10 | #warning "This project uses features only available in iOS SDK 5.0 and later."
11 | #endif
12 |
13 | #ifdef __OBJC__
14 | #import
15 | #import
16 | #endif
17 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/SQLClient.h:
--------------------------------------------------------------------------------
1 | //
2 | // SQLClient.h
3 | // SQLClient
4 | //
5 | // Created by Martin Rybak on 10/4/13.
6 | // Copyright (c) 2013 Martin Rybak. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | extern NSString* _Nonnull const SQLClientMessageNotification;
12 | extern NSString* _Nonnull const SQLClientErrorNotification;
13 | extern NSString* _Nonnull const SQLClientMessageKey;
14 | extern NSString* _Nonnull const SQLClientCodeKey;
15 | extern NSString* _Nonnull const SQLClientSeverityKey;
16 |
17 | /**
18 | * Native SQL Server client for iOS. An Objective-C wrapper around the open-source FreeTDS library.
19 | */
20 | @interface SQLClient : NSObject
21 |
22 | /**
23 | * Connection timeout, in seconds. Default is 5. Set before calling connect.
24 | */
25 | @property (nonatomic, assign) int timeout;
26 |
27 | /**
28 | * The character set to use for converting the UCS-2 server results. Default is UTF-8.
29 | * Set before calling connect. Can be set to any charset supported by the iconv library.
30 | * To list all supported iconv character sets, open a Terminal window and enter:
31 | $ iconv --list
32 | */
33 | @property (nonatomic, copy, nonnull) NSString* charset;
34 |
35 | /**
36 | * The maximum length of a string in a query is configured on the server via the SET TEXTSIZE command.
37 | * To find out your current setting, execute SELECT @@TEXTSIZE. SQLClient uses 4096 by default.
38 | * To override this setting, update this property.
39 | */
40 | @property (atomic, assign) int maxTextSize;
41 |
42 | /**
43 | * Returns an initialized SQLClient instance as a singleton.
44 | *
45 | * @return Shared SQLClient object
46 | */
47 | + (nullable instancetype)sharedInstance;
48 |
49 | /**
50 | * Connects to a SQL database server.
51 | *
52 | * @param host Required. The database server, i.e. server, server:port, or server\instance (be sure to escape the backslash)
53 | * @param username Required. The database username
54 | * @param password Required. The database password
55 | * @param database The database name
56 | * @param completion Block to be executed upon method successful connection
57 | */
58 | - (void)connect:(nonnull NSString*)host
59 | username:(nonnull NSString*)username
60 | password:(nonnull NSString*)password
61 | database:(nullable NSString*)database
62 | completion:(nullable void(^)(BOOL success))completion;
63 |
64 | /**
65 | * Indicates whether the database is currently connected.
66 | */
67 | - (BOOL)isConnected;
68 |
69 | /**
70 | * Indicates whether the database is executing a command.
71 | */
72 | - (BOOL)isExecuting;
73 |
74 | /**
75 | * Executes a SQL statement. Results of queries will be passed to the completion handler. Inserts, updates, and deletes do not return results.
76 | *
77 | * @param sql Required. A SQL statement
78 | * @param completion Block to be executed upon method completion. Accepts an NSArray of tables. Each table is an NSArray of rows.
79 | * Each row is an NSDictionary of columns where key = name and object = value as one of the following types:
80 | * NSString, NSNumber, NSDecimalNumber, NSData, UIImage, NSDate, NSUUID
81 | */
82 | - (void)execute:(nonnull NSString*)sql completion:(nullable void(^)(NSArray* _Nullable results))completion;
83 |
84 | /**
85 | * Disconnects from database server.
86 | */
87 | - (void)disconnect;
88 |
89 | @end
90 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/SQLClient.m:
--------------------------------------------------------------------------------
1 | //
2 | // SQLClient.m
3 | // SQLClient
4 | //
5 | // Created by Martin Rybak on 10/4/13.
6 | // Copyright (c) 2013 Martin Rybak. All rights reserved.
7 | //
8 |
9 | #import "SQLClient.h"
10 | #import "sybfront.h"
11 | #import "sybdb.h"
12 | #import "syberror.h"
13 |
14 | #define SYBUNIQUEIDENTIFIER 36
15 |
16 | int const SQLClientDefaultTimeout = 5;
17 | int const SQLClientDefaultMaxTextSize = 4096;
18 | NSString* const SQLClientDefaultCharset = @"UTF-8";
19 | NSString* const SQLClientWorkerQueueName = @"com.martinrybak.sqlclient";
20 | NSString* const SQLClientPendingConnectionError = @"Attempting to connect while a connection is active.";
21 | NSString* const SQLClientNoConnectionError = @"Attempting to execute while not connected.";
22 | NSString* const SQLClientPendingExecutionError = @"Attempting to execute while a command is in progress.";
23 | NSString* const SQLClientRowIgnoreMessage = @"Ignoring unknown row type";
24 | NSString* const SQLClientMessageNotification = @"SQLClientMessageNotification";
25 | NSString* const SQLClientErrorNotification = @"SQLClientErrorNotification";
26 | NSString* const SQLClientMessageKey = @"SQLClientMessageKey";
27 | NSString* const SQLClientCodeKey = @"SQLClientCodeKey";
28 | NSString* const SQLClientSeverityKey = @"SQLClientSeverityKey";
29 |
30 | struct GUID {
31 | unsigned long data1;
32 | unsigned short data2;
33 | unsigned short data3;
34 | unsigned char data4[8];
35 | };
36 |
37 | struct COLUMN
38 | {
39 | char* name;
40 | int type;
41 | int size;
42 | int status;
43 | BYTE* data;
44 | };
45 |
46 | @interface SQLClient ()
47 |
48 | @property (nonatomic, strong) NSOperationQueue* workerQueue;
49 | @property (nonatomic, weak) NSOperationQueue* callbackQueue;
50 | @property (atomic, assign, getter=isExecuting) BOOL executing;
51 |
52 | @end
53 |
54 | @implementation SQLClient
55 | {
56 | char* _password;
57 | LOGINREC* _login;
58 | DBPROCESS* _connection;
59 | struct COLUMN* _columns;
60 | int _numColumns;
61 | RETCODE _returnCode;
62 | }
63 |
64 | #pragma mark - NSObject
65 |
66 | //Initializes the FreeTDS library and sets callback handlers
67 | - (id)init
68 | {
69 | if (self = [super init])
70 | {
71 | //Initialize the FreeTDS library
72 | if (dbinit() == FAIL) {
73 | return nil;
74 | }
75 |
76 | //Initialize SQLClient
77 | self.timeout = SQLClientDefaultTimeout;
78 | self.charset = SQLClientDefaultCharset;
79 | self.callbackQueue = [NSOperationQueue currentQueue];
80 | self.workerQueue = [[NSOperationQueue alloc] init];
81 | self.workerQueue.name = SQLClientWorkerQueueName;
82 | self.workerQueue.maxConcurrentOperationCount = 1;
83 | self.maxTextSize = SQLClientDefaultMaxTextSize;
84 | self.executing = NO;
85 |
86 | //Set FreeTDS callback handlers
87 | dberrhandle(err_handler);
88 | dbmsghandle(msg_handler);
89 | }
90 | return self;
91 | }
92 |
93 | //Exits the FreeTDS library
94 | - (void)dealloc
95 | {
96 | dbexit();
97 | }
98 |
99 | #pragma mark - Public
100 |
101 | + (nullable instancetype)sharedInstance
102 | {
103 | static SQLClient* sharedInstance = nil;
104 | static dispatch_once_t onceToken;
105 | dispatch_once(&onceToken, ^{
106 | sharedInstance = [[self alloc] init];
107 | });
108 | return sharedInstance;
109 | }
110 |
111 | - (void)connect:(nonnull NSString*)host
112 | username:(nonnull NSString*)username
113 | password:(nonnull NSString*)password
114 | database:(nullable NSString*)database
115 | completion:(nullable void(^)(BOOL success))completion
116 | {
117 | NSParameterAssert(host);
118 | NSParameterAssert(username);
119 | NSParameterAssert(password);
120 |
121 | //Connect to database on worker queue
122 | [self.workerQueue addOperationWithBlock:^{
123 |
124 | if (self.isConnected) {
125 | [self message:SQLClientPendingConnectionError];
126 | [self connectionFailure:completion];
127 | return;
128 | }
129 |
130 | /*
131 | Copy password into a global C string. This is because in cleanupAfterConnection,
132 | dbloginfree() will attempt to overwrite the password in the login struct with zeroes for security.
133 | So it must be a string that stays alive until then.
134 | */
135 | _password = strdup([password UTF8String]);
136 |
137 | //Initialize login struct
138 | _login = dblogin();
139 | if (_login == FAIL) {
140 | [self connectionFailure:completion];
141 | return;
142 | }
143 |
144 | //Populate login struct
145 | DBSETLUSER(_login, [username UTF8String]);
146 | DBSETLPWD(_login, _password);
147 | DBSETLHOST(_login, [host UTF8String]);
148 | DBSETLCHARSET(_login, [self.charset UTF8String]);
149 |
150 | //Set login timeout
151 | dbsetlogintime(self.timeout);
152 |
153 | //Connect to database server
154 | _connection = dbopen(_login, [host UTF8String]);
155 | if (!_connection) {
156 | [self connectionFailure:completion];
157 | return;
158 | }
159 |
160 | //Switch to database, if provided
161 | if (database) {
162 | _returnCode = dbuse(_connection, [database UTF8String]);
163 | if (_returnCode == FAIL) {
164 | [self connectionFailure:completion];
165 | return;
166 | }
167 | }
168 |
169 | //Success!
170 | [self connectionSuccess:completion];
171 | }];
172 | }
173 |
174 | - (BOOL)isConnected
175 | {
176 | return !dbdead(_connection);
177 | }
178 |
179 | // TODO: get number of records modified for insert/update/delete commands
180 | // TODO: handle SQL stored procedure output parameters
181 | - (void)execute:(nonnull NSString*)sql completion:(nullable void(^)(NSArray* _Nullable results))completion
182 | {
183 | NSParameterAssert(sql);
184 |
185 | //Execute query on worker queue
186 | [self.workerQueue addOperationWithBlock:^{
187 |
188 | if (!self.isConnected) {
189 | [self message:SQLClientNoConnectionError];
190 | [self executionFailure:completion];
191 | return;
192 | }
193 |
194 | if (self.isExecuting) {
195 | [self message:SQLClientPendingExecutionError];
196 | [self executionFailure:completion];
197 | return;
198 | }
199 |
200 | self.executing = YES;
201 |
202 | //Set query timeout
203 | dbsettime(self.timeout);
204 |
205 | //Prepare SQL statement
206 | _returnCode = dbcmd(_connection, [sql UTF8String]);
207 | if (_returnCode == FAIL) {
208 | [self executionFailure:completion];
209 | return;
210 | }
211 |
212 | //Execute SQL statement
213 | _returnCode = dbsqlexec(_connection);
214 | if (_returnCode == FAIL) {
215 | [self executionFailure:completion];
216 | return;
217 | }
218 |
219 | //Create array to contain the tables
220 | NSMutableArray* output = [NSMutableArray array];
221 |
222 | //Loop through each table metadata
223 | //dbresults() returns SUCCEED, FAIL or, NO_MORE_RESULTS.
224 | while ((_returnCode = dbresults(_connection)) != NO_MORE_RESULTS)
225 | {
226 | if (_returnCode == FAIL) {
227 | [self executionFailure:completion];
228 | return;
229 | }
230 |
231 | //Get number of columns
232 | _numColumns = dbnumcols(_connection);
233 |
234 | //No columns, skip to next table
235 | if (!_numColumns) {
236 | continue;
237 | }
238 |
239 | //Create array to contain the rows for this table
240 | NSMutableArray* table = [NSMutableArray array];
241 |
242 | //Allocate C-style array of COL structs
243 | _columns = calloc(_numColumns, sizeof(struct COLUMN));
244 | if (!_columns) {
245 | [self executionFailure:completion];
246 | return;
247 | }
248 |
249 | struct COLUMN* column;
250 | STATUS rowCode;
251 |
252 | //Bind the column info
253 | for (column = _columns; column - _columns < _numColumns; column++)
254 | {
255 | //Get column number
256 | int c = column - _columns + 1;
257 |
258 | //Get column metadata
259 | column->name = dbcolname(_connection, c);
260 | column->type = dbcoltype(_connection, c);
261 | column->size = dbcollen(_connection, c);
262 |
263 | //Set bind type based on column type
264 | int bindType = CHARBIND; //Default
265 | switch (column->type)
266 | {
267 | case SYBBIT:
268 | case SYBBITN:
269 | {
270 | bindType = BITBIND;
271 | break;
272 | }
273 | case SYBINT1:
274 | {
275 | bindType = TINYBIND;
276 | break;
277 | }
278 | case SYBINT2:
279 | {
280 | bindType = SMALLBIND;
281 | break;
282 | }
283 | case SYBINT4:
284 | case SYBINTN:
285 | {
286 | bindType = INTBIND;
287 | break;
288 | }
289 | case SYBINT8:
290 | {
291 | bindType = BIGINTBIND;
292 | break;
293 | }
294 | case SYBFLT8:
295 | case SYBFLTN:
296 | {
297 | bindType = FLT8BIND;
298 | break;
299 | }
300 | case SYBREAL:
301 | {
302 | bindType = REALBIND;
303 | break;
304 | }
305 | case SYBMONEY4:
306 | {
307 | bindType = SMALLMONEYBIND;
308 | break;
309 | }
310 | case SYBMONEY:
311 | case SYBMONEYN:
312 | {
313 | bindType = MONEYBIND;
314 | break;
315 | }
316 | case SYBDECIMAL:
317 | case SYBNUMERIC:
318 | {
319 | //Workaround for incorrect size
320 | bindType = CHARBIND;
321 | column->size += 23;
322 | break;
323 | }
324 | case SYBCHAR:
325 | case SYBVARCHAR:
326 | case SYBNVARCHAR:
327 | case SYBTEXT:
328 | case SYBNTEXT:
329 | {
330 | bindType = NTBSTRINGBIND;
331 | column->size = MIN(column->size, self.maxTextSize);
332 | break;
333 | }
334 | case SYBDATETIME:
335 | case SYBDATETIME4:
336 | case SYBDATETIMN:
337 | case SYBBIGDATETIME:
338 | case SYBBIGTIME:
339 | {
340 | bindType = DATETIMEBIND;
341 | break;
342 | }
343 | case SYBDATE:
344 | case SYBMSDATE:
345 | {
346 | bindType = DATEBIND;
347 | break;
348 | }
349 | case SYBTIME:
350 | case SYBMSTIME:
351 | {
352 | //Workaround for TIME data type. We have to increase the size and cast as string.
353 | column->size += 14;
354 | bindType = CHARBIND;
355 | break;
356 | }
357 | case SYBMSDATETIMEOFFSET:
358 | case SYBMSDATETIME2:
359 | {
360 | bindType = DATETIME2BIND;
361 | break;
362 | }
363 | case SYBVOID:
364 | case SYBIMAGE:
365 | case SYBBINARY:
366 | case SYBVARBINARY:
367 | case SYBUNIQUEIDENTIFIER:
368 | {
369 | bindType = BINARYBIND;
370 | break;
371 | }
372 | }
373 |
374 | //Create space for column data
375 | column->data = calloc(1, column->size);
376 | if (!column->data) {
377 | [self executionFailure:completion];
378 | return;
379 | }
380 |
381 | //Bind column data
382 | _returnCode = dbbind(_connection, c, bindType, column->size, column->data);
383 | if (_returnCode == FAIL) {
384 | [self executionFailure:completion];
385 | return;
386 | }
387 |
388 | //Bind null value into column status
389 | _returnCode = dbnullbind(_connection, c, &column->status);
390 | if (_returnCode == FAIL) {
391 | [self executionFailure:completion];
392 | return;
393 | }
394 | }
395 |
396 | //Loop through each row
397 | while ((rowCode = dbnextrow(_connection)) != NO_MORE_ROWS)
398 | {
399 | //Check row type
400 | switch (rowCode)
401 | {
402 | //Regular row
403 | case REG_ROW:
404 | {
405 | //Create a new dictionary to contain the column names and vaues
406 | NSMutableDictionary* row = [[NSMutableDictionary alloc] initWithCapacity:_numColumns];
407 |
408 | //Loop through each column and create an entry where dictionary[columnName] = columnValue
409 | for (column = _columns; column - _columns < _numColumns; column++)
410 | {
411 | //Default to null
412 | id value = [NSNull null];
413 |
414 | //If not null, update value with column data
415 | if (column->status != -1)
416 | {
417 | switch (column->type)
418 | {
419 | case SYBBIT: //0 or 1
420 | {
421 | BOOL _value;
422 | memcpy(&_value, column->data, sizeof _value);
423 | value = [NSNumber numberWithBool:_value];
424 | break;
425 | }
426 | case SYBINT1: //Whole numbers from 0 to 255
427 | case SYBINT2: //Whole numbers between -32,768 and 32,767
428 | {
429 | int16_t _value;
430 | memcpy(&_value, column->data, sizeof _value);
431 | value = [NSNumber numberWithShort:_value];
432 | break;
433 | }
434 | case SYBINT4: //Whole numbers between -2,147,483,648 and 2,147,483,647
435 | {
436 | int32_t _value;
437 | memcpy(&_value, column->data, sizeof _value);
438 | value = [NSNumber numberWithInt:_value];
439 | break;
440 | }
441 | case SYBINT8: //Whole numbers between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807
442 | {
443 | long long _value;
444 | memcpy(&_value, column->data, sizeof _value);
445 | value = [NSNumber numberWithLongLong:_value];
446 | break;
447 | }
448 | case SYBFLT8: //Floating precision number data from -1.79E+308 to 1.79E+308
449 | {
450 | double _value;
451 | memcpy(&_value, column->data, sizeof _value);
452 | value = [NSNumber numberWithDouble:_value];
453 | break;
454 | }
455 | case SYBREAL: //Floating precision number data from -3.40E+38 to 3.40E+38
456 | {
457 | float _value;
458 | memcpy(&_value, column->data, sizeof _value);
459 | value = [NSNumber numberWithFloat:_value];
460 | break;
461 | }
462 | case SYBDECIMAL: //Numbers from -10^38 +1 to 10^38 –1.
463 | case SYBNUMERIC:
464 | {
465 | NSString* _value = [[NSString alloc] initWithUTF8String:(char*)column->data];
466 | value = [NSDecimalNumber decimalNumberWithString:_value];
467 | break;
468 | }
469 | case SYBMONEY4: //Monetary data from -214,748.3648 to 214,748.3647
470 | {
471 | DBMONEY4 _value;
472 | memcpy(&_value, column->data, sizeof _value);
473 | NSNumber* number = @(_value.mny4);
474 | NSDecimalNumber* decimalNumber = [NSDecimalNumber decimalNumberWithString:[number description]];
475 | value = [decimalNumber decimalNumberByDividingBy:[NSDecimalNumber decimalNumberWithString:@"10000"]];
476 | break;
477 | }
478 | case SYBMONEY: //Monetary data from -922,337,203,685,477.5808 to 922,337,203,685,477.5807
479 | {
480 | BYTE* _value = calloc(20, sizeof(BYTE)); //Max string length is 20
481 | dbconvert(_connection, SYBMONEY, column->data, sizeof(SYBMONEY), SYBCHAR, _value, -1);
482 | value = [NSDecimalNumber decimalNumberWithString:[NSString stringWithUTF8String:(char*)_value]];
483 | free(_value);
484 | break;
485 | }
486 | case SYBDATETIME: //From 1/1/1753 00:00:00.000 to 12/31/9999 23:59:59.997 with an accuracy of 3.33 milliseconds
487 | case SYBDATETIMN:
488 | case SYBBIGDATETIME:
489 | case SYBBIGTIME:
490 | case SYBMSDATETIME2: //From 1/1/0001 00:00:00 to 12/31/9999 23:59:59.9999999 with an accuracy of 100 nanoseconds
491 | case SYBMSDATETIMEOFFSET: //The same as SYBMSDATETIME2 with the addition of a time zone offset
492 | {
493 | DBDATEREC2 _value;
494 | dbanydatecrack(_connection, &_value, column->type, column->data);
495 | value = [self dateWithYear:_value.dateyear month:_value.datemonth + 1 day:_value.datedmonth hour:_value.datehour minute:_value.dateminute second:_value.datesecond nanosecond:_value.datensecond timezone:_value.datetzone];
496 | break;
497 | }
498 | case SYBDATETIME4: //From January 1, 1900 00:00 to June 6, 2079 23:59 with an accuracy of 1 minute
499 | {
500 | DBDATEREC _value;
501 | dbdatecrack(_connection, &_value, (DBDATETIME*)column->data);
502 | value = [self dateWithYear:_value.dateyear month:_value.datemonth + 1 day:_value.datedmonth hour:_value.datehour minute:_value.dateminute second:_value.datesecond];
503 | break;
504 | }
505 | case SYBMSDATE: //From January 1, 0001 to December 31, 9999
506 | {
507 | DBDATEREC _value;
508 | dbdatecrack(_connection, &_value, (DBDATETIME*)column->data);
509 | value = [self dateWithYear:_value.dateyear month:_value.datemonth + 1 day:_value.datedmonth];
510 | break;
511 | }
512 | case SYBMSTIME: //00:00:00 to 23:59:59.9999999 with an accuracy of 100 nanoseconds
513 | {
514 | //Extract time components out of string since DBDATEREC conversion does not work
515 | NSString* string = [NSString stringWithUTF8String:(char*)column->data];
516 | value = [self dateWithTimeString:string];
517 | break;
518 | }
519 | case SYBCHAR:
520 | case SYBVARCHAR:
521 | case SYBNVARCHAR:
522 | case SYBTEXT:
523 | case SYBNTEXT:
524 | {
525 | value = [NSString stringWithUTF8String:(char*)column->data];
526 | break;
527 | }
528 | case SYBUNIQUEIDENTIFIER: //https://en.wikipedia.org/wiki/Globally_unique_identifier#Binary_encoding
529 | {
530 | //Convert GUID to UUID
531 | struct GUID _value;
532 | memcpy(&_value, column->data, sizeof _value);
533 | _value.data1 = NTOHL(_value.data1);
534 | _value.data2 = NTOHS(_value.data2);
535 | _value.data3 = NTOHS(_value.data3);
536 | value = [[NSUUID alloc] initWithUUIDBytes:(const unsigned char*)&_value];
537 | break;
538 | }
539 | case SYBVOID:
540 | case SYBIMAGE:
541 | case SYBBINARY:
542 | case SYBVARBINARY:
543 | {
544 | value = [NSData dataWithBytes:column->data length:column->size];
545 | break;
546 | }
547 | }
548 | }
549 |
550 | NSString* columnName = [NSString stringWithUTF8String:column->name];
551 | row[columnName] = value;
552 | }
553 |
554 | //Add an immutable copy to the table
555 | [table addObject:[row copy]];
556 | break;
557 | }
558 | //Buffer full
559 | case BUF_FULL:
560 | [self executionFailure:completion];
561 | return;
562 | //Error
563 | case FAIL:
564 | [self executionFailure:completion];
565 | return;
566 | default:
567 | [self message:SQLClientRowIgnoreMessage];
568 | break;
569 | }
570 | }
571 |
572 | //Add immutable copy of table to output
573 | [output addObject:[table copy]];
574 | [self cleanupAfterTable];
575 | }
576 |
577 | //Success! Send an immutable copy of the results array
578 | [self executionSuccess:completion results:[output copy]];
579 | }];
580 | }
581 |
582 | - (void)disconnect
583 | {
584 | [self.workerQueue addOperationWithBlock:^{
585 | [self cleanupAfterConnection];
586 | if (_connection) {
587 | dbclose(_connection);
588 | _connection = NULL;
589 | }
590 | }];
591 | }
592 |
593 | #pragma mark - FreeTDS Callbacks
594 |
595 | //Handles message callback from FreeTDS library.
596 | int msg_handler(DBPROCESS* dbproc, DBINT msgno, int msgstate, int severity, char* msgtext, char* srvname, char* procname, int line)
597 | {
598 | //Can't call self from a C function, so need to access singleton
599 | SQLClient* self = [SQLClient sharedInstance];
600 | [self message:[NSString stringWithUTF8String:msgtext]];
601 | return INT_EXIT;
602 | }
603 |
604 | //Handles error callback from FreeTDS library.
605 | int err_handler(DBPROCESS* dbproc, int severity, int dberr, int oserr, char* dberrstr, char* oserrstr)
606 | {
607 | //Can't call self from a C function, so need to access singleton
608 | SQLClient* self = [SQLClient sharedInstance];
609 | [self error:[NSString stringWithUTF8String:dberrstr] code:dberr severity:severity];
610 | return INT_CANCEL;
611 | }
612 |
613 | //Posts a SQLClientMessageNotification notification
614 | - (void)message:(NSString*)message
615 | {
616 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{
617 | [[NSNotificationCenter defaultCenter] postNotificationName:SQLClientMessageNotification object:nil userInfo:@{ SQLClientMessageKey:message }];
618 | }];
619 | }
620 |
621 | //Posts a SQLClientErrorNotification notification
622 | - (void)error:(NSString*)error code:(int)code severity:(int)severity
623 | {
624 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{
625 | [[NSNotificationCenter defaultCenter] postNotificationName:SQLClientErrorNotification object:nil userInfo:@{
626 | SQLClientMessageKey:error,
627 | SQLClientCodeKey:@(code),
628 | SQLClientSeverityKey:@(severity)
629 | }];
630 | }];
631 | }
632 |
633 | #pragma mark - Cleanup
634 |
635 | - (void)cleanupAfterTable
636 | {
637 | if (_columns) {
638 | for (struct COLUMN* column = _columns; column - _columns < _numColumns; column++) {
639 | if (column) {
640 | free(column->data);
641 | column->data = NULL;
642 | }
643 | }
644 | free(_columns);
645 | _columns = NULL;
646 | }
647 | }
648 |
649 | - (void)cleanupAfterExecution
650 | {
651 | [self cleanupAfterTable];
652 | if (_connection) {
653 | dbfreebuf(_connection);
654 | }
655 | }
656 |
657 | - (void)cleanupAfterConnection
658 | {
659 | [self cleanupAfterExecution];
660 | if (_login) {
661 | dbloginfree(_login);
662 | _login = NULL;
663 | }
664 | free(_password);
665 | _password = NULL;
666 | }
667 |
668 | #pragma mark - Private
669 |
670 | //Invokes connection completion handler on callback queue with success = NO
671 | - (void)connectionFailure:(void (^)(BOOL success))completion
672 | {
673 | [self cleanupAfterConnection];
674 | [self.callbackQueue addOperationWithBlock:^{
675 | if (completion) {
676 | completion(NO);
677 | }
678 | }];
679 | }
680 |
681 | //Invokes connection completion handler on callback queue with success = [self connected]
682 | - (void)connectionSuccess:(void (^)(BOOL success))completion
683 | {
684 | [self cleanupAfterConnection];
685 | [self.callbackQueue addOperationWithBlock:^{
686 | if (completion) {
687 | completion([self isConnected]);
688 | }
689 | }];
690 | }
691 |
692 | //Invokes execution completion handler on callback queue with results = nil
693 | - (void)executionFailure:(void (^)(NSArray* results))completion
694 | {
695 | self.executing = NO;
696 | [self cleanupAfterExecution];
697 | [self.callbackQueue addOperationWithBlock:^{
698 | if (completion) {
699 | completion(nil);
700 | }
701 | }];
702 | }
703 |
704 | //Invokes execution completion handler on callback queue with results array
705 | - (void)executionSuccess:(void (^)(NSArray* results))completion results:(NSArray*)results
706 | {
707 | self.executing = NO;
708 | [self cleanupAfterExecution];
709 | [self.callbackQueue addOperationWithBlock:^{
710 | if (completion) {
711 | completion(results);
712 | }
713 | }];
714 | }
715 |
716 | #pragma mark - Date
717 |
718 | - (NSDate*)referenceDate
719 | {
720 | return [self dateWithYear:1900 month:1 day:1 hour:0 minute:0 second:0 nanosecond:0];
721 | }
722 |
723 | - (NSDate*)dateWithYear:(int)year month:(int)month day:(int)day
724 | {
725 | return [self dateWithYear:year month:month day:day hour:0 minute:0 second:0];
726 | }
727 |
728 | - (NSDate*)dateWithYear:(int)year month:(int)month day:(int)day hour:(int)hour minute:(int)minute second:(int)second
729 | {
730 | return [self dateWithYear:year month:month day:day hour:hour minute:minute second:second nanosecond:0];
731 | }
732 |
733 | - (NSDate*)dateWithYear:(int)year month:(int)month day:(int)day hour:(int)hour minute:(int)minute second:(int)second nanosecond:(int)nanosecond
734 | {
735 | return [self dateWithYear:year month:month day:day hour:hour minute:minute second:second nanosecond:0 timezone:0];
736 | }
737 |
738 | - (NSDate*)dateWithYear:(int)year month:(int)month day:(int)day hour:(int)hour minute:(int)minute second:(int)second nanosecond:(int)nanosecond timezone:(int)timezone
739 | {
740 | NSCalendar* calendar = [NSCalendar currentCalendar];
741 | NSDateComponents* dateComponents = [[NSDateComponents alloc] init];
742 | dateComponents.year = year;
743 | dateComponents.month = month;
744 | dateComponents.day = day;
745 | dateComponents.hour = hour;
746 | dateComponents.minute = minute;
747 | dateComponents.second = second;
748 | dateComponents.nanosecond = nanosecond;
749 | dateComponents.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:timezone * 60];
750 | return [calendar dateFromComponents:dateComponents];
751 | }
752 |
753 | - (NSDate*)dateWithTimeString:(NSString*)string
754 | {
755 | if (string.length < 30) {
756 | return nil;
757 | }
758 |
759 | NSString* time = [string substringFromIndex:string.length - 18];
760 | int hour = [[time substringWithRange:NSMakeRange(0, 2)] integerValue];
761 | int minute = [[time substringWithRange:NSMakeRange(3, 2)] integerValue];
762 | int second = [[time substringWithRange:NSMakeRange(6, 2)] integerValue];
763 | int nanosecond = [[time substringWithRange:NSMakeRange(9, 7)] integerValue];
764 | NSString* meridian = [time substringWithRange:NSMakeRange(16, 2)];
765 |
766 | if ([meridian isEqualToString:@"AM"]) {
767 | if (hour == 12) {
768 | hour = 0;
769 | }
770 | } else {
771 | if (hour < 12) {
772 | hour += 12;
773 | }
774 | }
775 |
776 | return [self dateWithYear:1900 month:1 day:1 hour:hour minute:minute second:second nanosecond:nanosecond * 100 timezone:0];
777 | }
778 |
779 | @end
780 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/bkpublic.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998-1999 Brian Bruns
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef _bkpublic_h_
21 | #define _bkpublic_h_
22 |
23 | static const char rcsid_bkpublic_h[] = "$Id: bkpublic.h,v 1.5 2004-10-28 12:42:11 freddy77 Exp $";
24 | static const void *const no_unused_bkpublic_h_warn[] = { rcsid_bkpublic_h, no_unused_bkpublic_h_warn };
25 |
26 | /* seperate this stuff out later */
27 | #include
28 |
29 | #ifdef __cplusplus
30 | extern "C"
31 | {
32 | #if 0
33 | }
34 | #endif
35 | #endif
36 |
37 | /* buld properties start with 1 i guess */
38 | #define BLK_IDENTITY 1
39 |
40 | CS_RETCODE blk_alloc(CS_CONNECTION * connection, CS_INT version, CS_BLKDESC ** blk_pointer);
41 | CS_RETCODE blk_bind(CS_BLKDESC * blkdesc, CS_INT colnum, CS_DATAFMT * datafmt, CS_VOID * buffer, CS_INT * datalen,
42 | CS_SMALLINT * indicator);
43 | CS_RETCODE blk_colval(SRV_PROC * srvproc, CS_BLKDESC * blkdescp, CS_BLK_ROW * rowp, CS_INT colnum, CS_VOID * valuep,
44 | CS_INT valuelen, CS_INT * outlenp);
45 | CS_RETCODE blk_default(CS_BLKDESC * blkdesc, CS_INT colnum, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
46 | CS_RETCODE blk_describe(CS_BLKDESC * blkdesc, CS_INT colnum, CS_DATAFMT * datafmt);
47 | CS_RETCODE blk_done(CS_BLKDESC * blkdesc, CS_INT type, CS_INT * outrow);
48 | CS_RETCODE blk_drop(CS_BLKDESC * blkdesc);
49 | CS_RETCODE blk_getrow(SRV_PROC * srvproc, CS_BLKDESC * blkdescp, CS_BLK_ROW * rowp);
50 | CS_RETCODE blk_gettext(SRV_PROC * srvproc, CS_BLKDESC * blkdescp, CS_BLK_ROW * rowp, CS_INT bufsize, CS_INT * outlenp);
51 | CS_RETCODE blk_init(CS_BLKDESC * blkdesc, CS_INT direction, CS_CHAR * tablename, CS_INT tnamelen);
52 | CS_RETCODE blk_props(CS_BLKDESC * blkdesc, CS_INT action, CS_INT property, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
53 | CS_RETCODE blk_rowalloc(SRV_PROC * srvproc, CS_BLK_ROW ** row);
54 | CS_RETCODE blk_rowdrop(SRV_PROC * srvproc, CS_BLK_ROW * row);
55 | CS_RETCODE blk_rowxfer(CS_BLKDESC * blkdesc);
56 | CS_RETCODE blk_rowxfer_mult(CS_BLKDESC * blkdesc, CS_INT * row_count);
57 | CS_RETCODE blk_sendrow(CS_BLKDESC * blkdesc, CS_BLK_ROW * row);
58 | CS_RETCODE blk_sendtext(CS_BLKDESC * blkdesc, CS_BLK_ROW * row, CS_BYTE * buffer, CS_INT buflen);
59 | CS_RETCODE blk_srvinit(SRV_PROC * srvproc, CS_BLKDESC * blkdescp);
60 | CS_RETCODE blk_textxfer(CS_BLKDESC * blkdesc, CS_BYTE * buffer, CS_INT buflen, CS_INT * outlen);
61 |
62 | #ifdef __cplusplus
63 | #if 0
64 | {
65 | #endif
66 | }
67 | #endif
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/cspublic.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Brian Bruns
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef _cspublic_h_
21 | #define _cspublic_h_
22 |
23 | #include
24 |
25 | #undef TDS_STATIC_CAST
26 | #ifdef __cplusplus
27 | #define TDS_STATIC_CAST(type, a) static_cast(a)
28 | extern "C"
29 | {
30 | #if 0
31 | }
32 | #endif
33 | #else
34 | #define TDS_STATIC_CAST(type, a) ((type)(a))
35 | #endif
36 |
37 | #define CS_PUBLIC
38 | #define CS_STATIC static
39 |
40 | #define CS_SUCCEED 1
41 | #define CS_FAIL 0
42 | #define CS_MEM_ERROR -1
43 | #define CS_PENDING -2
44 | #define CS_QUIET -3
45 | #define CS_BUSY -4
46 | #define CS_INTERRUPT -5
47 | #define CS_BLK_HAS_TEXT -6
48 | #define CS_CONTINUE -7
49 | #define CS_FATAL -8
50 | #define CS_RET_HAFAILOVER -9
51 | #define CS_UNSUPPORTED -10
52 |
53 | #define CS_CANCELED -202
54 | #define CS_ROW_FAIL -203
55 | #define CS_END_DATA -204
56 | #define CS_END_RESULTS -205
57 | #define CS_END_ITEM -206
58 | #define CS_NOMSG -207
59 | #define CS_TIMED_OUT -208
60 |
61 | #define CS_SIZEOF(x) sizeof(x)
62 |
63 | #define CS_LAYER(x) (((x) >> 24) & 0xFF)
64 | #define CS_ORIGIN(x) (((x) >> 16) & 0xFF)
65 | #define CS_SEVERITY(x) (((x) >> 8) & 0xFF)
66 | #define CS_NUMBER(x) ((x) & 0xFF)
67 |
68 | /* forward declarations */
69 | typedef CS_RETCODE(*CS_CSLIBMSG_FUNC) (CS_CONTEXT *, CS_CLIENTMSG *);
70 | typedef CS_RETCODE(*CS_CLIENTMSG_FUNC) (CS_CONTEXT *, CS_CONNECTION *, CS_CLIENTMSG *);
71 | typedef CS_RETCODE(*CS_SERVERMSG_FUNC) (CS_CONTEXT *, CS_CONNECTION *, CS_SERVERMSG *);
72 |
73 |
74 | #define CS_IODATA TDS_STATIC_CAST(CS_INT, 1600)
75 | #define CS_SRC_VALUE -2562
76 |
77 |
78 |
79 | /* status bits for CS_SERVERMSG */
80 | #define CS_HASEED 0x01
81 |
82 | typedef struct _cs_blkdesc CS_BLKDESC;
83 |
84 | /* CS_CAP_REQUEST values */
85 | #define CS_REQ_LANG 1
86 | #define CS_REQ_RPC 2
87 | #define CS_REQ_NOTIF 3
88 | #define CS_REQ_MSTMT 4
89 | #define CS_REQ_BCP 5
90 | #define CS_REQ_CURSOR 6
91 | #define CS_REQ_DYN 7
92 | #define CS_REQ_MSG 8
93 | #define CS_REQ_PARAM 9
94 | #define CS_DATA_INT1 10
95 | #define CS_DATA_INT2 11
96 | #define CS_DATA_INT4 12
97 | #define CS_DATA_BIT 13
98 | #define CS_DATA_CHAR 14
99 | #define CS_DATA_VCHAR 15
100 | #define CS_DATA_BIN 16
101 | #define CS_DATA_VBIN 17
102 | #define CS_DATA_MNY8 18
103 | #define CS_DATA_MNY4 19
104 | #define CS_DATA_DATE8 20
105 | #define CS_DATA_DATE4 21
106 | #define CS_DATA_FLT4 22
107 | #define CS_DATA_FLT8 23
108 | #define CS_DATA_NUM 24
109 | #define CS_DATA_TEXT 25
110 | #define CS_DATA_IMAGE 26
111 | #define CS_DATA_DEC 27
112 | #define CS_DATA_LCHAR 28
113 | #define CS_DATA_LBIN 29
114 | #define CS_DATA_INTN 30
115 | #define CS_DATA_DATETIMEN 31
116 | #define CS_DATA_MONEYN 32
117 | #define CS_CSR_PREV 33
118 | #define CS_CSR_FIRST 34
119 | #define CS_CSR_LAST 35
120 | #define CS_CSR_ABS 36
121 | #define CS_CSR_REL 37
122 | #define CS_CSR_MULTI 38
123 | #define CS_CON_OOB 39
124 | #define CS_CON_INBAND 40
125 | #define CS_CON_LOGICAL 41
126 | #define CS_PROTO_TEXT 42
127 | #define CS_PROTO_BULK 43
128 | #define CS_REQ_URGNOTIF 44
129 | #define CS_DATA_SENSITIVITY 45
130 | #define CS_DATA_BOUNDARY 46
131 | #define CS_PROTO_DYNAMIC 47
132 | #define CS_PROTO_DYNPROC 48
133 | #define CS_DATA_FLTN 49
134 | #define CS_DATA_BITN 50
135 | #define CS_OPTION_GET 51
136 | #define CS_DATA_INT8 52
137 | #define CS_DATA_VOID 53
138 |
139 | /* CS_CAP_RESPONSE values */
140 | #define CS_RES_NOMSG 1
141 | #define CS_RES_NOEED 2
142 | #define CS_RES_NOPARAM 3
143 | #define CS_DATA_NOINT1 4
144 | #define CS_DATA_NOINT2 5
145 | #define CS_DATA_NOINT4 6
146 | #define CS_DATA_NOBIT 7
147 | #define CS_DATA_NOCHAR 8
148 | #define CS_DATA_NOVCHAR 9
149 | #define CS_DATA_NOBIN 10
150 | #define CS_DATA_NOVBIN 11
151 | #define CS_DATA_NOMNY8 12
152 | #define CS_DATA_NOMNY4 13
153 | #define CS_DATA_NODATE8 14
154 | #define CS_DATA_NODATE4 15
155 | #define CS_DATA_NOFLT4 16
156 | #define CS_DATA_NOFLT8 17
157 | #define CS_DATA_NONUM 18
158 | #define CS_DATA_NOTEXT 19
159 | #define CS_DATA_NOIMAGE 20
160 | #define CS_DATA_NODEC 21
161 | #define CS_DATA_NOLCHAR 22
162 | #define CS_DATA_NOLBIN 23
163 | #define CS_DATA_NOINTN 24
164 | #define CS_DATA_NODATETIMEN 25
165 | #define CS_DATA_NOMONEYN 26
166 | #define CS_CON_NOOOB 27
167 | #define CS_CON_NOINBAND 28
168 | #define CS_PROTO_NOTEXT 29
169 | #define CS_PROTO_NOBULK 30
170 | #define CS_DATA_NOSENSITIVITY 31
171 | #define CS_DATA_NOBOUNDARY 32
172 | #define CS_RES_NOTDSDEBUG 33
173 | #define CS_RES_NOSTRIPBLANKS 34
174 | #define CS_DATA_NOINT8 35
175 |
176 | /* Properties */
177 | enum
178 | {
179 | /*
180 | * These defines looks weird but programs can test support for defines,
181 | * compiler can check enum and there are no define side effecs
182 | */
183 | CS_USERNAME = 9100,
184 | #define CS_USERNAME CS_USERNAME
185 | CS_PASSWORD = 9101,
186 | #define CS_PASSWORD CS_PASSWORD
187 | CS_APPNAME = 9102,
188 | #define CS_APPNAME CS_APPNAME
189 | CS_HOSTNAME = 9103,
190 | #define CS_HOSTNAME CS_HOSTNAME
191 | CS_LOGIN_STATUS = 9104,
192 | #define CS_LOGIN_STATUS CS_LOGIN_STATUS
193 | CS_TDS_VERSION = 9105,
194 | #define CS_TDS_VERSION CS_TDS_VERSION
195 | CS_CHARSETCNV = 9106,
196 | #define CS_CHARSETCNV CS_CHARSETCNV
197 | CS_PACKETSIZE = 9107,
198 | #define CS_PACKETSIZE CS_PACKETSIZE
199 | CS_USERDATA = 9108,
200 | #define CS_USERDATA CS_USERDATA
201 | CS_NETIO = 9110,
202 | #define CS_NETIO CS_NETIO
203 | CS_TEXTLIMIT = 9112,
204 | #define CS_TEXTLIMIT CS_TEXTLIMIT
205 | CS_HIDDEN_KEYS = 9113,
206 | #define CS_HIDDEN_KEYS CS_HIDDEN_KEYS
207 | CS_VERSION = 9114,
208 | #define CS_VERSION CS_VERSION
209 | CS_IFILE = 9115,
210 | #define CS_IFILE CS_IFILE
211 | CS_LOGIN_TIMEOUT = 9116,
212 | #define CS_LOGIN_TIMEOUT CS_LOGIN_TIMEOUT
213 | CS_TIMEOUT = 9117,
214 | #define CS_TIMEOUT CS_TIMEOUT
215 | CS_MAX_CONNECT = 9118,
216 | #define CS_MAX_CONNECT CS_MAX_CONNECT
217 | CS_EXPOSE_FMTS = 9120,
218 | #define CS_EXPOSE_FMTS CS_EXPOSE_FMTS
219 | CS_EXTRA_INF = 9121,
220 | #define CS_EXTRA_INF CS_EXTRA_INF
221 | CS_ANSI_BINDS = 9123,
222 | #define CS_ANSI_BINDS CS_ANSI_BINDS
223 | CS_BULK_LOGIN = 9124,
224 | #define CS_BULK_LOGIN CS_BULK_LOGIN
225 | CS_LOC_PROP = 9125,
226 | #define CS_LOC_PROP CS_LOC_PROP
227 | CS_PARENT_HANDLE = 9130,
228 | #define CS_PARENT_HANDLE CS_PARENT_HANDLE
229 | CS_EED_CMD = 9131,
230 | #define CS_EED_CMD CS_EED_CMD
231 | CS_DIAG_TIMEOUT = 9132,
232 | #define CS_DIAG_TIMEOUT CS_DIAG_TIMEOUT
233 | CS_DISABLE_POLL = 9133,
234 | #define CS_DISABLE_POLL CS_DISABLE_POLL
235 | CS_SEC_ENCRYPTION = 9135,
236 | #define CS_SEC_ENCRYPTION CS_SEC_ENCRYPTION
237 | CS_SEC_CHALLENGE = 9136,
238 | #define CS_SEC_CHALLENGE CS_SEC_CHALLENGE
239 | CS_SEC_NEGOTIATE = 9137,
240 | #define CS_SEC_NEGOTIATE CS_SEC_NEGOTIATE
241 | CS_CON_STATUS = 9143,
242 | #define CS_CON_STATUS CS_CON_STATUS
243 | CS_VER_STRING = 9144,
244 | #define CS_VER_STRING CS_VER_STRING
245 | CS_SERVERNAME = 9146,
246 | #define CS_SERVERNAME CS_SERVERNAME
247 | CS_SEC_APPDEFINED = 9149,
248 | #define CS_SEC_APPDEFINED CS_SEC_APPDEFINED
249 | CS_STICKY_BINDS = 9151,
250 | #define CS_STICKY_BINDS CS_STICKY_BINDS
251 | CS_SERVERADDR = 9206,
252 | #define CS_SERVERADDR CS_SERVERADDR
253 | CS_PORT = 9300
254 | #define CS_PORT CS_PORT
255 | };
256 |
257 | /* Arbitrary precision math operators */
258 | enum
259 | {
260 | CS_ADD = 1,
261 | CS_SUB,
262 | CS_MULT,
263 | CS_DIV
264 | };
265 |
266 | enum
267 | {
268 | CS_TDS_40 = 7360,
269 | CS_TDS_42,
270 | CS_TDS_46,
271 | CS_TDS_495,
272 | CS_TDS_50,
273 | CS_TDS_70,
274 | CS_TDS_71,
275 | CS_TDS_72,
276 | CS_TDS_73,
277 | CS_TDS_74,
278 | };
279 |
280 | /* bit mask values used by CS_DATAFMT.status */
281 | #define CS_HIDDEN (1 << 0)
282 | #define CS_KEY (1 << 1)
283 | #define CS_VERSION_KEY (1 << 2)
284 | #define CS_NODATA (1 << 3)
285 | #define CS_UPDATABLE (1 << 4)
286 | #define CS_CANBENULL (1 << 5)
287 | #define CS_DESCIN (1 << 6)
288 | #define CS_DESCOUT (1 << 7)
289 | #define CS_INPUTVALUE (1 << 8)
290 | #define CS_UPDATECOL (1 << 9)
291 | #define CS_RETURN (1 << 10)
292 | #define CS_TIMESTAMP (1 << 13)
293 | #define CS_NODEFAULT (1 << 14)
294 | #define CS_IDENTITY (1 << 15)
295 |
296 | /*
297 | * DBD::Sybase compares indicator to CS_NULLDATA so this is -1
298 | * (the documentation states -1)
299 | */
300 | #define CS_GOODDATA 0
301 | #define CS_NULLDATA (-1)
302 |
303 | /* CS_CON_STATUS read-only property bit mask values */
304 | #define CS_CONSTAT_CONNECTED 0x01
305 | #define CS_CONSTAT_DEAD 0x02
306 |
307 | /*
308 | * Code added for CURSOR support
309 | * types accepted by ct_cursor
310 | */
311 | #define CS_CURSOR_DECLARE 700
312 | #define CS_CURSOR_OPEN 701
313 | #define CS_CURSOR_ROWS 703
314 | #define CS_CURSOR_UPDATE 704
315 | #define CS_CURSOR_DELETE 705
316 | #define CS_CURSOR_CLOSE 706
317 | #define CS_CURSOR_DEALLOC 707
318 | #define CS_CURSOR_OPTION 725
319 |
320 | #define CS_FOR_UPDATE TDS_STATIC_CAST(CS_INT, 0x1)
321 | #define CS_READ_ONLY TDS_STATIC_CAST(CS_INT, 0x2)
322 | #define CS_RESTORE_OPEN TDS_STATIC_CAST(CS_INT, 0x8)
323 | #define CS_IMPLICIT_CURSOR TDS_STATIC_CAST(CS_INT, 0x40)
324 |
325 |
326 | #define CS_CURSTAT_NONE TDS_STATIC_CAST(CS_INT, 0x0)
327 | #define CS_CURSTAT_DECLARED TDS_STATIC_CAST(CS_INT, 0x1)
328 | #define CS_CURSTAT_OPEN TDS_STATIC_CAST(CS_INT, 0x2)
329 | #define CS_CURSTAT_CLOSED TDS_STATIC_CAST(CS_INT, 0x4)
330 | #define CS_CURSTAT_RDONLY TDS_STATIC_CAST(CS_INT, 0x8)
331 | #define CS_CURSTAT_UPDATABLE TDS_STATIC_CAST(CS_INT, 0x10)
332 | #define CS_CURSTAT_ROWCOUNT TDS_STATIC_CAST(CS_INT, 0x20)
333 | #define CS_CURSTAT_DEALLOC TDS_STATIC_CAST(CS_INT, 0x40)
334 |
335 | #define CS_CUR_STATUS TDS_STATIC_CAST(CS_INT, 9126)
336 | #define CS_CUR_ID TDS_STATIC_CAST(CS_INT, 9127)
337 | #define CS_CUR_NAME TDS_STATIC_CAST(CS_INT, 9128)
338 | #define CS_CUR_ROWCOUNT TDS_STATIC_CAST(CS_INT, 9129)
339 |
340 | /* options accepted by ct_options() */
341 | #define CS_OPT_DATEFIRST 5001
342 | #define CS_OPT_TEXTSIZE 5002
343 | #define CS_OPT_STATS_TIME 5003
344 | #define CS_OPT_STATS_IO 5004
345 | #define CS_OPT_ROWCOUNT 5005
346 | #define CS_OPT_DATEFORMAT 5007
347 | #define CS_OPT_ISOLATION 5008
348 | #define CS_OPT_AUTHON 5009
349 | #define CS_OPT_SHOWPLAN 5013
350 | #define CS_OPT_NOEXEC 5014
351 | #define CS_OPT_ARITHIGNORE 5015
352 | #define CS_OPT_TRUNCIGNORE 5016
353 | #define CS_OPT_ARITHABORT 5017
354 | #define CS_OPT_PARSEONLY 5018
355 | #define CS_OPT_GETDATA 5020
356 | #define CS_OPT_NOCOUNT 5021
357 | #define CS_OPT_FORCEPLAN 5023
358 | #define CS_OPT_FORMATONLY 5024
359 | #define CS_OPT_CHAINXACTS 5025
360 | #define CS_OPT_CURCLOSEONXACT 5026
361 | #define CS_OPT_FIPSFLAG 5027
362 | #define CS_OPT_RESTREES 5028
363 | #define CS_OPT_IDENTITYON 5029
364 | #define CS_OPT_CURREAD 5030
365 | #define CS_OPT_CURWRITE 5031
366 | #define CS_OPT_IDENTITYOFF 5032
367 | #define CS_OPT_AUTHOFF 5033
368 | #define CS_OPT_ANSINULL 5034
369 | #define CS_OPT_QUOTED_IDENT 5035
370 | #define CS_OPT_ANSIPERM 5036
371 | #define CS_OPT_STR_RTRUNC 5037
372 |
373 | /* options accepted by ct_command() */
374 | enum ct_command_options
375 | {
376 | CS_MORE = 16,
377 | CS_END = 32,
378 | CS_RECOMPILE = 188,
379 | CS_NO_RECOMPILE,
380 | CS_BULK_INIT,
381 | CS_BULK_CONT,
382 | CS_BULK_DATA,
383 | CS_COLUMN_DATA
384 | };
385 |
386 |
387 | /*
388 | * bind formats, should be mapped to TDS types
389 | * can be a combination of bit
390 | */
391 | enum
392 | {
393 | CS_FMT_UNUSED = 0,
394 | #define CS_FMT_UNUSED CS_FMT_UNUSED
395 | CS_FMT_NULLTERM = 1,
396 | #define CS_FMT_NULLTERM CS_FMT_NULLTERM
397 | CS_FMT_PADNULL = 2,
398 | #define CS_FMT_PADBLANK CS_FMT_PADBLANK
399 | CS_FMT_PADBLANK = 4,
400 | #define CS_FMT_PADNULL CS_FMT_PADNULL
401 | CS_FMT_JUSTIFY_RT = 8
402 | #define CS_FMT_JUSTIFY_RT CS_FMT_JUSTIFY_RT
403 | };
404 |
405 | /* callbacks */
406 | #define CS_COMPLETION_CB 1
407 | #define CS_SERVERMSG_CB 2
408 | #define CS_CLIENTMSG_CB 3
409 | #define CS_NOTIF_CB 4
410 | #define CS_ENCRYPT_CB 5
411 | #define CS_CHALLENGE_CB 6
412 | #define CS_DS_LOOKUP_CB 7
413 | #define CS_SECSESSION_CB 8
414 | #define CS_SIGNAL_CB 100
415 | #define CS_MESSAGE_CB 9119
416 |
417 | /* string types */
418 | #define CS_NULLTERM -9
419 | #define CS_WILDCARD -99
420 | #define CS_NO_LIMIT -9999
421 | #define CS_UNUSED -99999
422 |
423 | /* other */
424 | #define CS_GET 33
425 | #define CS_SET 34
426 | #define CS_CLEAR 35
427 | #define CS_INIT 36
428 | #define CS_STATUS 37
429 | #define CS_MSGLIMIT 38
430 | #define CS_SUPPORTED 40
431 |
432 | #define CS_CMD_DONE 4046
433 | #define CS_CMD_SUCCEED 4047
434 | #define CS_CMD_FAIL 4048
435 |
436 | /* commands */
437 | #define CS_LANG_CMD 148
438 | #define CS_RPC_CMD 149
439 | #define CS_SEND_DATA_CMD 151
440 | #define CS_SEND_BULK_CMD 153
441 |
442 | #define CS_VERSION_100 112
443 | #define CS_VERSION_110 1100
444 | #define CS_VERSION_120 1100
445 | #define CS_VERSION_125 12500
446 | #define CS_VERSION_150 15000
447 |
448 | #define BLK_VERSION_100 CS_VERSION_100
449 | #define BLK_VERSION_110 CS_VERSION_110
450 | #define BLK_VERSION_120 CS_VERSION_120
451 | #define BLK_VERSION_125 CS_VERSION_125
452 | #define BLK_VERSION_150 CS_VERSION_150
453 |
454 | #define CS_FORCE_EXIT 300
455 | #define CS_FORCE_CLOSE 301
456 |
457 | #define CS_SYNC_IO 8111
458 | #define CS_ASYNC_IO 8112
459 | #define CS_DEFER_IO 8113
460 |
461 | #define CS_CANCEL_CURRENT 6000
462 | #define CS_CANCEL_ALL 6001
463 | #define CS_CANCEL_ATTN 6002
464 |
465 | #define CS_ROW_COUNT 800
466 | #define CS_CMD_NUMBER 801
467 | #define CS_NUM_COMPUTES 802
468 | #define CS_NUMDATA 803
469 | #define CS_NUMORDERCOLS 805
470 | #define CS_MSGTYPE 806
471 | #define CS_BROWSE_INFO 807
472 | #define CS_TRANS_STATE 808
473 |
474 | #define CS_TRAN_UNDEFINED 0
475 | #define CS_TRAN_IN_PROGRESS 1
476 | #define CS_TRAN_COMPLETED 2
477 | #define CS_TRAN_FAIL 3
478 | #define CS_TRAN_STMT_FAIL 4
479 |
480 | #define CS_COMP_OP 5350
481 | #define CS_COMP_ID 5351
482 | #define CS_COMP_COLID 5352
483 | #define CS_COMP_BYLIST 5353
484 | #define CS_BYLIST_LEN 5354
485 |
486 | #define CS_NO_COUNT -1
487 |
488 | #define CS_OP_SUM 5370
489 | #define CS_OP_AVG 5371
490 | #define CS_OP_COUNT 5372
491 | #define CS_OP_MIN 5373
492 | #define CS_OP_MAX 5374
493 |
494 | #define CS_CAP_REQUEST 1
495 | #define CS_CAP_RESPONSE 2
496 |
497 | #define CS_PREPARE 717
498 | #define CS_EXECUTE 718
499 | #define CS_DESCRIBE_INPUT 720
500 | #define CS_DESCRIBE_OUTPUT 721
501 |
502 | #define CS_DEALLOC 711
503 |
504 | #define CS_LC_ALL 7
505 | #define CS_SYB_LANG 8
506 | #define CS_SYB_CHARSET 9
507 | #define CS_SYB_SORTORDER 10
508 | #define CS_SYB_COLLATE CS_SYB_SORTORDER
509 | #define CS_SYB_LANG_CHARSET 11
510 |
511 | #define CS_BLK_IN 1
512 | #define CS_BLK_OUT 2
513 |
514 | #define CS_BLK_BATCH 1
515 | #define CS_BLK_ALL 2
516 | #define CS_BLK_CANCEL 3
517 |
518 | /* to do support these */
519 |
520 | #define CS_BLK_ARRAY_MAXLEN 0x1000
521 | #define CS_DEF_PREC 18
522 |
523 | /* Error Severities */
524 | #define CS_SV_INFORM TDS_STATIC_CAST(CS_INT, 0)
525 | #define CS_SV_API_FAIL TDS_STATIC_CAST(CS_INT, 1)
526 | #define CS_SV_RETRY_FAIL TDS_STATIC_CAST(CS_INT, 2)
527 | #define CS_SV_RESOURCE_FAIL TDS_STATIC_CAST(CS_INT, 3)
528 | #define CS_SV_CONFIG_FAIL TDS_STATIC_CAST(CS_INT, 4)
529 | #define CS_SV_COMM_FAIL TDS_STATIC_CAST(CS_INT, 5)
530 | #define CS_SV_INTERNAL_FAIL TDS_STATIC_CAST(CS_INT, 6)
531 | #define CS_SV_FATAL TDS_STATIC_CAST(CS_INT, 7)
532 |
533 | /* result_types */
534 | #define CS_COMPUTE_RESULT 4045
535 | #define CS_CURSOR_RESULT 4041
536 | #define CS_PARAM_RESULT 4042
537 | #define CS_ROW_RESULT 4040
538 | #define CS_STATUS_RESULT 4043
539 | #define CS_COMPUTEFMT_RESULT 4050
540 | #define CS_ROWFMT_RESULT 4049
541 | #define CS_MSG_RESULT 4044
542 | #define CS_DESCRIBE_RESULT 4051
543 |
544 | /* bind types */
545 | #define CS_ILLEGAL_TYPE TDS_STATIC_CAST(CS_INT, -1)
546 | #define CS_CHAR_TYPE TDS_STATIC_CAST(CS_INT, 0)
547 | #define CS_BINARY_TYPE TDS_STATIC_CAST(CS_INT, 1)
548 | #define CS_LONGCHAR_TYPE TDS_STATIC_CAST(CS_INT, 2)
549 | #define CS_LONGBINARY_TYPE TDS_STATIC_CAST(CS_INT, 3)
550 | #define CS_TEXT_TYPE TDS_STATIC_CAST(CS_INT, 4)
551 | #define CS_IMAGE_TYPE TDS_STATIC_CAST(CS_INT, 5)
552 | #define CS_TINYINT_TYPE TDS_STATIC_CAST(CS_INT, 6)
553 | #define CS_SMALLINT_TYPE TDS_STATIC_CAST(CS_INT, 7)
554 | #define CS_INT_TYPE TDS_STATIC_CAST(CS_INT, 8)
555 | #define CS_REAL_TYPE TDS_STATIC_CAST(CS_INT, 9)
556 | #define CS_FLOAT_TYPE TDS_STATIC_CAST(CS_INT, 10)
557 | #define CS_BIT_TYPE TDS_STATIC_CAST(CS_INT, 11)
558 | #define CS_DATETIME_TYPE TDS_STATIC_CAST(CS_INT, 12)
559 | #define CS_DATETIME4_TYPE TDS_STATIC_CAST(CS_INT, 13)
560 | #define CS_MONEY_TYPE TDS_STATIC_CAST(CS_INT, 14)
561 | #define CS_MONEY4_TYPE TDS_STATIC_CAST(CS_INT, 15)
562 | #define CS_NUMERIC_TYPE TDS_STATIC_CAST(CS_INT, 16)
563 | #define CS_DECIMAL_TYPE TDS_STATIC_CAST(CS_INT, 17)
564 | #define CS_VARCHAR_TYPE TDS_STATIC_CAST(CS_INT, 18)
565 | #define CS_VARBINARY_TYPE TDS_STATIC_CAST(CS_INT, 19)
566 | #define CS_LONG_TYPE TDS_STATIC_CAST(CS_INT, 20)
567 | #define CS_SENSITIVITY_TYPE TDS_STATIC_CAST(CS_INT, 21)
568 | #define CS_BOUNDARY_TYPE TDS_STATIC_CAST(CS_INT, 22)
569 | #define CS_VOID_TYPE TDS_STATIC_CAST(CS_INT, 23)
570 | #define CS_USHORT_TYPE TDS_STATIC_CAST(CS_INT, 24)
571 | #define CS_UNICHAR_TYPE TDS_STATIC_CAST(CS_INT, 25)
572 | #define CS_BLOB_TYPE TDS_STATIC_CAST(CS_INT, 26)
573 | #define CS_DATE_TYPE TDS_STATIC_CAST(CS_INT, 27)
574 | #define CS_TIME_TYPE TDS_STATIC_CAST(CS_INT, 28)
575 | #define CS_UNITEXT_TYPE TDS_STATIC_CAST(CS_INT, 29)
576 | #define CS_BIGINT_TYPE TDS_STATIC_CAST(CS_INT, 30)
577 | #define CS_USMALLINT_TYPE TDS_STATIC_CAST(CS_INT, 31)
578 | #define CS_UINT_TYPE TDS_STATIC_CAST(CS_INT, 32)
579 | #define CS_UBIGINT_TYPE TDS_STATIC_CAST(CS_INT, 33)
580 | #define CS_XML_TYPE TDS_STATIC_CAST(CS_INT, 34)
581 | #define CS_BIGDATETIME_TYPE TDS_STATIC_CAST(CS_INT, 35)
582 | #define CS_BIGTIME_TYPE TDS_STATIC_CAST(CS_INT, 36)
583 | #define CS_UNIQUE_TYPE TDS_STATIC_CAST(CS_INT, 40)
584 |
585 | #define CS_USER_TYPE TDS_STATIC_CAST(CS_INT, 100)
586 | /* cs_dt_info type values */
587 | enum
588 | {
589 | CS_MONTH = 7340,
590 | #define CS_MONTH CS_MONTH
591 | CS_SHORTMONTH,
592 | #define CS_SHORTMONTH CS_SHORTMONTH
593 | CS_DAYNAME,
594 | #define CS_DAYNAME CS_DAYNAME
595 | CS_DATEORDER,
596 | #define CS_DATEORDER CS_DATEORDER
597 | CS_12HOUR,
598 | #define CS_12HOUR CS_12HOUR
599 | CS_DT_CONVFMT
600 | #define CS_DT_CONVFMT CS_DT_CONVFMT
601 | };
602 |
603 | /* DT_CONVFMT types */
604 | enum
605 | {
606 | CS_DATES_SHORT = 0,
607 | #define CS_DATES_SHORT CS_DATES_SHORT
608 | CS_DATES_MDY1,
609 | #define CS_DATES_MDY1 CS_DATES_MDY1
610 | CS_DATES_YMD1,
611 | #define CS_DATES_YMD1 CS_DATES_YMD1
612 | CS_DATES_DMY1,
613 | #define CS_DATES_DMY1 CS_DATES_DMY1
614 | CS_DATES_DMY2,
615 | #define CS_DATES_DMY2 CS_DATES_DMY2
616 | CS_DATES_DMY3,
617 | #define CS_DATES_DMY3 CS_DATES_DMY3
618 | CS_DATES_DMY4,
619 | #define CS_DATES_DMY4 CS_DATES_DMY4
620 | CS_DATES_MDY2,
621 | #define CS_DATES_MDY2 CS_DATES_MDY2
622 | CS_DATES_HMS,
623 | #define CS_DATES_HMS CS_DATES_HMS
624 | CS_DATES_LONG,
625 | #define CS_DATES_LONG CS_DATES_LONG
626 | CS_DATES_MDY3,
627 | #define CS_DATES_MDY3 CS_DATES_MDY3
628 | CS_DATES_YMD2,
629 | #define CS_DATES_YMD2 CS_DATES_YMD2
630 | CS_DATES_YMD3,
631 | #define CS_DATES_YMD3 CS_DATES_YMD3
632 | CS_DATES_YDM1,
633 | #define CS_DATES_YDM1 CS_DATES_YDM1
634 | CS_DATES_MYD1,
635 | #define CS_DATES_MYD1 CS_DATES_MYD1
636 | CS_DATES_DYM1,
637 | #define CS_DATES_DYM1 CS_DATES_DYM1
638 | CS_DATES_MDY1_YYYY = 101,
639 | #define CS_DATES_MDY1_YYYY CS_DATES_MDY1_YYYY
640 | CS_DATES_YMD1_YYYY,
641 | #define CS_DATES_YMD1_YYYY CS_DATES_YMD1_YYYY
642 | CS_DATES_DMY1_YYYY,
643 | #define CS_DATES_DMY1_YYYY CS_DATES_DMY1_YYYY
644 | CS_DATES_DMY2_YYYY,
645 | #define CS_DATES_DMY2_YYYY CS_DATES_DMY2_YYYY
646 | CS_DATES_DMY3_YYYY,
647 | #define CS_DATES_DMY3_YYYY CS_DATES_DMY3_YYYY
648 | CS_DATES_DMY4_YYYY,
649 | #define CS_DATES_DMY4_YYYY CS_DATES_DMY4_YYYY
650 | CS_DATES_MDY2_YYYY,
651 | #define CS_DATES_MDY2_YYYY CS_DATES_MDY2_YYYY
652 | CS_DATES_MDY3_YYYY = 110,
653 | #define CS_DATES_MDY3_YYYY CS_DATES_MDY3_YYYY
654 | CS_DATES_YMD2_YYYY,
655 | #define CS_DATES_YMD2_YYYY CS_DATES_YMD2_YYYY
656 | CS_DATES_YMD3_YYYY
657 | #define CS_DATES_YMD3_YYYY CS_DATES_YMD3_YYYY
658 | };
659 |
660 | typedef CS_RETCODE(*CS_CONV_FUNC) (CS_CONTEXT * context, CS_DATAFMT * srcfmt, CS_VOID * src, CS_DATAFMT * detsfmt, CS_VOID * dest,
661 | CS_INT * destlen);
662 |
663 | typedef struct _cs_objname
664 | {
665 | CS_BOOL thinkexists;
666 | CS_INT object_type;
667 | CS_CHAR last_name[CS_MAX_NAME];
668 | CS_INT lnlen;
669 | CS_CHAR first_name[CS_MAX_NAME];
670 | CS_INT fnlen;
671 | CS_VOID *scope;
672 | CS_INT scopelen;
673 | CS_VOID *thread;
674 | CS_INT threadlen;
675 | } CS_OBJNAME;
676 |
677 | typedef struct _cs_objdata
678 | {
679 | CS_BOOL actuallyexists;
680 | CS_CONNECTION *connection;
681 | CS_COMMAND *command;
682 | CS_VOID *buffer;
683 | CS_INT buflen;
684 | } CS_OBJDATA;
685 |
686 | /* Eventually, these should be in terms of TDS values */
687 | enum
688 | {
689 | CS_OPT_MONDAY = 1,
690 | CS_OPT_TUESDAY,
691 | CS_OPT_WEDNESDAY,
692 | CS_OPT_THURSDAY,
693 | CS_OPT_FRIDAY,
694 | CS_OPT_SATURDAY,
695 | CS_OPT_SUNDAY
696 | };
697 | enum
698 | {
699 | CS_OPT_FMTMDY = 1,
700 | CS_OPT_FMTDMY,
701 | CS_OPT_FMTYMD,
702 | CS_OPT_FMTYDM,
703 | CS_OPT_FMTMYD,
704 | CS_OPT_FMTDYM
705 | };
706 | enum
707 | {
708 | CS_OPT_LEVEL0 = 0,
709 | CS_OPT_LEVEL1,
710 | CS_OPT_LEVEL2,
711 | CS_OPT_LEVEL3
712 | };
713 |
714 | #define CS_FALSE 0
715 | #define CS_TRUE 1
716 |
717 | #define SRV_PROC CS_VOID
718 |
719 | /* constants required for ct_diag (not jet implemented) */
720 | #define CS_CLIENTMSG_TYPE 4700
721 | #define CS_SERVERMSG_TYPE 4701
722 | #define CS_ALLMSG_TYPE 4702
723 |
724 | CS_RETCODE cs_convert(CS_CONTEXT * ctx, CS_DATAFMT * srcfmt, CS_VOID * srcdata, CS_DATAFMT * destfmt, CS_VOID * destdata,
725 | CS_INT * resultlen);
726 | CS_RETCODE cs_ctx_alloc(CS_INT version, CS_CONTEXT ** ctx);
727 | CS_RETCODE cs_ctx_global(CS_INT version, CS_CONTEXT ** ctx);
728 | CS_RETCODE cs_ctx_drop(CS_CONTEXT * ctx);
729 | CS_RETCODE cs_config(CS_CONTEXT * ctx, CS_INT action, CS_INT property, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
730 | CS_RETCODE cs_strbuild(CS_CONTEXT * ctx, CS_CHAR * buffer, CS_INT buflen, CS_INT * resultlen, CS_CHAR * text, CS_INT textlen,
731 | CS_CHAR * formats, CS_INT formatlen, ...);
732 | #undef cs_dt_crack
733 | CS_RETCODE cs_dt_crack(CS_CONTEXT * ctx, CS_INT datetype, CS_VOID * dateval, CS_DATEREC * daterec);
734 | CS_RETCODE cs_dt_crack_v2(CS_CONTEXT * ctx, CS_INT datetype, CS_VOID * dateval, CS_DATEREC * daterec);
735 | #define cs_dt_crack cs_dt_crack_v2
736 | CS_RETCODE cs_loc_alloc(CS_CONTEXT * ctx, CS_LOCALE ** locptr);
737 | CS_RETCODE cs_loc_drop(CS_CONTEXT * ctx, CS_LOCALE * locale);
738 | CS_RETCODE cs_locale(CS_CONTEXT * ctx, CS_INT action, CS_LOCALE * locale, CS_INT type, CS_VOID * buffer, CS_INT buflen,
739 | CS_INT * outlen);
740 | CS_RETCODE cs_dt_info(CS_CONTEXT * ctx, CS_INT action, CS_LOCALE * locale, CS_INT type, CS_INT item, CS_VOID * buffer,
741 | CS_INT buflen, CS_INT * outlen);
742 |
743 | CS_RETCODE cs_calc(CS_CONTEXT * ctx, CS_INT op, CS_INT datatype, CS_VOID * var1, CS_VOID * var2, CS_VOID * dest);
744 | CS_RETCODE cs_cmp(CS_CONTEXT * ctx, CS_INT datatype, CS_VOID * var1, CS_VOID * var2, CS_INT * result);
745 | CS_RETCODE cs_conv_mult(CS_CONTEXT * ctx, CS_LOCALE * srcloc, CS_LOCALE * destloc, CS_INT * conv_multiplier);
746 | CS_RETCODE cs_diag(CS_CONTEXT * ctx, CS_INT operation, CS_INT type, CS_INT idx, CS_VOID * buffer);
747 | CS_RETCODE cs_manage_convert(CS_CONTEXT * ctx, CS_INT action, CS_INT srctype, CS_CHAR * srcname, CS_INT srcnamelen, CS_INT desttype,
748 | CS_CHAR * destname, CS_INT destnamelen, CS_INT * conv_multiplier, CS_CONV_FUNC * func);
749 | CS_RETCODE cs_objects(CS_CONTEXT * ctx, CS_INT action, CS_OBJNAME * objname, CS_OBJDATA * objdata);
750 | CS_RETCODE cs_set_convert(CS_CONTEXT * ctx, CS_INT action, CS_INT srctype, CS_INT desttype, CS_CONV_FUNC * func);
751 | CS_RETCODE cs_setnull(CS_CONTEXT * ctx, CS_DATAFMT * datafmt, CS_VOID * buffer, CS_INT buflen);
752 | CS_RETCODE cs_strcmp(CS_CONTEXT * ctx, CS_LOCALE * locale, CS_INT type, CS_CHAR * str1, CS_INT len1, CS_CHAR * str2, CS_INT len2,
753 | CS_INT * result);
754 | CS_RETCODE cs_time(CS_CONTEXT * ctx, CS_LOCALE * locale, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen, CS_DATEREC * daterec);
755 | CS_RETCODE cs_will_convert(CS_CONTEXT * ctx, CS_INT srctype, CS_INT desttype, CS_BOOL * result);
756 |
757 | const char * cs_prretcode(int retcode);
758 |
759 | #ifdef __cplusplus
760 | #if 0
761 | {
762 | #endif
763 | }
764 | #endif
765 |
766 | #endif
767 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/cstypes.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998-1999 Brian Bruns
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef _cstypes_h_
21 | #define _cstypes_h_
22 |
23 | #include "tds_sysdep_public.h"
24 |
25 | #ifdef __cplusplus
26 | extern "C"
27 | {
28 | #if 0
29 | }
30 | #endif
31 | #endif
32 |
33 | static const char rcsid_cstypes_h[] = "$Id: cstypes.h,v 1.7 2008-05-06 00:14:02 jklowden Exp $";
34 | static const void *const no_unused_cstypes_h_warn[] = { rcsid_cstypes_h, no_unused_cstypes_h_warn };
35 |
36 | typedef tds_sysdep_int32_type CS_INT;
37 | typedef unsigned tds_sysdep_int32_type CS_UINT;
38 | typedef tds_sysdep_int64_type CS_BIGINT;
39 | typedef unsigned tds_sysdep_int64_type CS_UBIGINT;
40 | typedef tds_sysdep_int16_type CS_SMALLINT;
41 | typedef unsigned tds_sysdep_int16_type CS_USMALLINT;
42 | typedef unsigned char CS_TINYINT;
43 | typedef char CS_CHAR;
44 | typedef unsigned char CS_BYTE;
45 | typedef tds_sysdep_real32_type CS_REAL;
46 | typedef tds_sysdep_real64_type CS_FLOAT;
47 | typedef tds_sysdep_int32_type CS_BOOL;
48 | typedef void CS_VOID;
49 | typedef unsigned char CS_IMAGE;
50 | typedef unsigned char CS_TEXT;
51 | typedef unsigned char CS_LONGBINARY;
52 | typedef unsigned char CS_LONGCHAR;
53 | typedef long CS_LONG;
54 | typedef unsigned char CS_BINARY;
55 | typedef unsigned tds_sysdep_int16_type CS_USHORT;
56 | typedef unsigned char CS_BIT;
57 |
58 | typedef CS_INT CS_RETCODE;
59 |
60 | #define CS_MAX_NAME 132
61 | #define CS_MAX_SCALE 77
62 | #define CS_MAX_PREC 77 /* used by php */
63 | #define CS_MAX_NUMLEN 33 /* used by roguewave */
64 | #define CS_MAX_MSG 1024
65 | #define CS_SQLSTATE_SIZE 8
66 | #define CS_OBJ_NAME 400
67 | #define CS_TP_SIZE 16 /* text pointer */
68 | #define CS_TS_SIZE 8 /* length of timestamp */
69 |
70 |
71 | typedef struct _cs_numeric
72 | {
73 | unsigned char precision;
74 | unsigned char scale;
75 | unsigned char array[CS_MAX_NUMLEN];
76 | } CS_NUMERIC;
77 |
78 | typedef CS_NUMERIC CS_DECIMAL;
79 |
80 | typedef struct _cs_varbinary
81 | {
82 | CS_SMALLINT len;
83 | CS_CHAR array[256];
84 | } CS_VARBINARY;
85 |
86 | typedef struct _cs_varchar
87 | {
88 | CS_SMALLINT len; /* length of the string */
89 | CS_CHAR str[256]; /* string, no NULL terminator */
90 | } CS_VARCHAR;
91 |
92 | typedef struct _cs_config CS_CONFIG;
93 | typedef struct _cs_context CS_CONTEXT;
94 | typedef struct _cs_connection CS_CONNECTION;
95 | typedef struct _cs_locale CS_LOCALE;
96 | typedef struct _cs_command CS_COMMAND;
97 | typedef struct _cs_blk_row CS_BLK_ROW;
98 |
99 | typedef struct _cs_iodesc
100 | {
101 | CS_INT iotype;
102 | CS_INT datatype;
103 | CS_LOCALE *locale;
104 | CS_INT usertype;
105 | CS_INT total_txtlen;
106 | CS_INT offset;
107 | CS_BOOL log_on_update;
108 | CS_CHAR name[CS_OBJ_NAME];
109 | CS_INT namelen;
110 | CS_BYTE timestamp[CS_TS_SIZE];
111 | CS_INT timestamplen;
112 | CS_BYTE textptr[CS_TP_SIZE];
113 | CS_INT textptrlen;
114 | } CS_IODESC;
115 |
116 | typedef struct _cs_datafmt
117 | {
118 | CS_CHAR name[CS_MAX_NAME];
119 | CS_INT namelen;
120 | CS_INT datatype;
121 | CS_INT format;
122 | CS_INT maxlength;
123 | CS_INT scale;
124 | CS_INT precision;
125 | CS_INT status;
126 | CS_INT count;
127 | CS_INT usertype;
128 | CS_LOCALE *locale;
129 | } CS_DATAFMT;
130 |
131 | typedef struct _cs_money
132 | {
133 | CS_INT mnyhigh;
134 | CS_UINT mnylow;
135 | } CS_MONEY;
136 |
137 | typedef struct _cs_money4
138 | {
139 | CS_INT mny4;
140 | } CS_MONEY4;
141 |
142 | typedef CS_INT CS_DATE;
143 |
144 | typedef CS_INT CS_TIME;
145 |
146 | typedef struct _cs_datetime
147 | {
148 | CS_INT dtdays;
149 | CS_INT dttime;
150 | } CS_DATETIME;
151 |
152 | typedef struct _cs_datetime4
153 | {
154 | CS_USHORT days;
155 | CS_USHORT minutes;
156 | } CS_DATETIME4;
157 |
158 | typedef struct _cs_daterec
159 | {
160 | CS_INT dateyear;
161 | CS_INT datemonth;
162 | CS_INT datedmonth;
163 | CS_INT datedyear;
164 | CS_INT datedweek;
165 | CS_INT datehour;
166 | CS_INT dateminute;
167 | CS_INT datesecond;
168 | CS_INT datemsecond;
169 | CS_INT datetzone;
170 | CS_INT datesecfrac;
171 | CS_INT datesecprec;
172 | } CS_DATEREC;
173 |
174 | typedef CS_INT CS_MSGNUM;
175 |
176 | typedef struct _cs_clientmsg
177 | {
178 | CS_INT severity;
179 | CS_MSGNUM msgnumber;
180 | CS_CHAR msgstring[CS_MAX_MSG];
181 | CS_INT msgstringlen;
182 | CS_INT osnumber;
183 | CS_CHAR osstring[CS_MAX_MSG];
184 | CS_INT osstringlen;
185 | CS_INT status;
186 | CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
187 | CS_INT sqlstatelen;
188 | } CS_CLIENTMSG;
189 |
190 | typedef struct _cs_servermsg
191 | {
192 | CS_MSGNUM msgnumber;
193 | CS_INT state;
194 | CS_INT severity;
195 | CS_CHAR text[CS_MAX_MSG];
196 | CS_INT textlen;
197 | CS_CHAR svrname[CS_MAX_NAME];
198 | CS_INT svrnlen;
199 | CS_CHAR proc[CS_MAX_NAME];
200 | CS_INT proclen;
201 | CS_INT line;
202 | CS_INT status;
203 | CS_BYTE sqlstate[CS_SQLSTATE_SIZE];
204 | CS_INT sqlstatelen;
205 | } CS_SERVERMSG;
206 |
207 | #ifdef __cplusplus
208 | #if 0
209 | {
210 | #endif
211 | }
212 | #endif
213 |
214 | #endif
215 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/ctpublic.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998-1999 Brian Bruns
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef _ctpublic_h_
21 | #define _ctpublic_h_
22 |
23 | #include
24 |
25 | #undef TDS_STATIC_CAST
26 | #ifdef __cplusplus
27 | #define TDS_STATIC_CAST(type, a) static_cast(a)
28 | extern "C"
29 | {
30 | #if 0
31 | }
32 | #endif
33 | #else
34 | #define TDS_STATIC_CAST(type, a) ((type)(a))
35 | #endif
36 |
37 | /*
38 | ** define for each CT-Lib API
39 | */
40 | #define CT_BIND TDS_STATIC_CAST(CS_INT, 0)
41 | #define CT_BR_COLUMN TDS_STATIC_CAST(CS_INT, 1)
42 | #define CT_BR_TABLE TDS_STATIC_CAST(CS_INT, 2)
43 | #define CT_CALLBACK TDS_STATIC_CAST(CS_INT, 3)
44 | #define CT_CANCEL TDS_STATIC_CAST(CS_INT, 4)
45 | #define CT_CAPABILITY TDS_STATIC_CAST(CS_INT, 5)
46 | #define CT_CLOSE TDS_STATIC_CAST(CS_INT, 6)
47 | #define CT_CMD_ALLOC TDS_STATIC_CAST(CS_INT, 7)
48 | #define CT_CMD_DROP TDS_STATIC_CAST(CS_INT, 8)
49 | #define CT_CMD_PROPS TDS_STATIC_CAST(CS_INT, 9)
50 | #define CT_COMMAND TDS_STATIC_CAST(CS_INT, 10)
51 | #define CT_COMPUTE_INFO TDS_STATIC_CAST(CS_INT, 11)
52 | #define CT_CON_ALLOC TDS_STATIC_CAST(CS_INT, 12)
53 | #define CT_CON_DROP TDS_STATIC_CAST(CS_INT, 13)
54 | #define CT_CON_PROPS TDS_STATIC_CAST(CS_INT, 14)
55 | #define CT_CON_XFER TDS_STATIC_CAST(CS_INT, 15)
56 | #define CT_CONFIG TDS_STATIC_CAST(CS_INT, 16)
57 | #define CT_CONNECT TDS_STATIC_CAST(CS_INT, 17)
58 | #define CT_CURSOR TDS_STATIC_CAST(CS_INT, 18)
59 | #define CT_DATA_INFO TDS_STATIC_CAST(CS_INT, 19)
60 | #define CT_DEBUG TDS_STATIC_CAST(CS_INT, 20)
61 | #define CT_DESCRIBE TDS_STATIC_CAST(CS_INT, 21)
62 | #define CT_DIAG TDS_STATIC_CAST(CS_INT, 22)
63 | #define CT_DYNAMIC TDS_STATIC_CAST(CS_INT, 23)
64 | #define CT_DYNDESC TDS_STATIC_CAST(CS_INT, 24)
65 | #define CT_EXIT TDS_STATIC_CAST(CS_INT, 25)
66 | #define CT_FETCH TDS_STATIC_CAST(CS_INT, 26)
67 | #define CT_GET_DATA TDS_STATIC_CAST(CS_INT, 27)
68 | #define CT_GETFORMAT TDS_STATIC_CAST(CS_INT, 28)
69 | #define CT_GETLOGINFO TDS_STATIC_CAST(CS_INT, 29)
70 | #define CT_INIT TDS_STATIC_CAST(CS_INT, 30)
71 | #define CT_KEYDATA TDS_STATIC_CAST(CS_INT, 31)
72 | #define CT_OPTIONS TDS_STATIC_CAST(CS_INT, 32)
73 | #define CT_PARAM TDS_STATIC_CAST(CS_INT, 33)
74 | #define CT_POLL TDS_STATIC_CAST(CS_INT, 34)
75 | #define CT_RECVPASSTHRU TDS_STATIC_CAST(CS_INT, 35)
76 | #define CT_REMOTE_PWD TDS_STATIC_CAST(CS_INT, 36)
77 | #define CT_RES_INFO TDS_STATIC_CAST(CS_INT, 37)
78 | #define CT_RESULTS TDS_STATIC_CAST(CS_INT, 38)
79 | #define CT_SEND TDS_STATIC_CAST(CS_INT, 39)
80 | #define CT_SEND_DATA TDS_STATIC_CAST(CS_INT, 40)
81 | #define CT_SENDPASSTHRU TDS_STATIC_CAST(CS_INT, 41)
82 | #define CT_SETLOGINFO TDS_STATIC_CAST(CS_INT, 42)
83 | #define CT_WAKEUP TDS_STATIC_CAST(CS_INT, 43)
84 | #define CT_LABELS TDS_STATIC_CAST(CS_INT, 44)
85 | #define CT_DS_LOOKUP TDS_STATIC_CAST(CS_INT, 45)
86 | #define CT_DS_DROP TDS_STATIC_CAST(CS_INT, 46)
87 | #define CT_DS_OBJINFO TDS_STATIC_CAST(CS_INT, 47)
88 | #define CT_SETPARAM TDS_STATIC_CAST(CS_INT, 48)
89 | #define CT_DYNSQLDA TDS_STATIC_CAST(CS_INT, 49)
90 | #define CT_NOTIFICATION TDS_STATIC_CAST(CS_INT, 1000)
91 |
92 | static const char rcsid_ctpublic_h[] = "$Id: ctpublic.h,v 1.14 2005-05-28 10:48:26 freddy77 Exp $";
93 | static const void *const no_unused_ctpublic_h_warn[] = { rcsid_ctpublic_h, no_unused_ctpublic_h_warn };
94 |
95 |
96 | CS_RETCODE ct_init(CS_CONTEXT * ctx, CS_INT version);
97 | CS_RETCODE ct_con_alloc(CS_CONTEXT * ctx, CS_CONNECTION ** con);
98 | CS_RETCODE ct_con_props(CS_CONNECTION * con, CS_INT action, CS_INT property, CS_VOID * buffer, CS_INT buflen, CS_INT * out_len);
99 | CS_RETCODE ct_connect(CS_CONNECTION * con, CS_CHAR * servername, CS_INT snamelen);
100 | CS_RETCODE ct_cmd_alloc(CS_CONNECTION * con, CS_COMMAND ** cmd);
101 | CS_RETCODE ct_cancel(CS_CONNECTION * conn, CS_COMMAND * cmd, CS_INT type);
102 | CS_RETCODE ct_cmd_drop(CS_COMMAND * cmd);
103 | CS_RETCODE ct_close(CS_CONNECTION * con, CS_INT option);
104 | CS_RETCODE ct_con_drop(CS_CONNECTION * con);
105 | CS_RETCODE ct_exit(CS_CONTEXT * ctx, CS_INT unused);
106 | CS_RETCODE ct_command(CS_COMMAND * cmd, CS_INT type, const CS_VOID * buffer, CS_INT buflen, CS_INT option);
107 | CS_RETCODE ct_send(CS_COMMAND * cmd);
108 | CS_RETCODE ct_results(CS_COMMAND * cmd, CS_INT * result_type);
109 | CS_RETCODE ct_bind(CS_COMMAND * cmd, CS_INT item, CS_DATAFMT * datafmt, CS_VOID * buffer, CS_INT * copied, CS_SMALLINT * indicator);
110 | CS_RETCODE ct_fetch(CS_COMMAND * cmd, CS_INT type, CS_INT offset, CS_INT option, CS_INT * rows_read);
111 | CS_RETCODE ct_res_info_dyn(CS_COMMAND * cmd, CS_INT type, CS_VOID * buffer, CS_INT buflen, CS_INT * out_len);
112 | CS_RETCODE ct_res_info(CS_COMMAND * cmd, CS_INT type, CS_VOID * buffer, CS_INT buflen, CS_INT * out_len);
113 | CS_RETCODE ct_describe(CS_COMMAND * cmd, CS_INT item, CS_DATAFMT * datafmt);
114 | CS_RETCODE ct_callback(CS_CONTEXT * ctx, CS_CONNECTION * con, CS_INT action, CS_INT type, CS_VOID * func);
115 | CS_RETCODE ct_send_dyn(CS_COMMAND * cmd);
116 | CS_RETCODE ct_results_dyn(CS_COMMAND * cmd, CS_INT * result_type);
117 | CS_RETCODE ct_config(CS_CONTEXT * ctx, CS_INT action, CS_INT property, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
118 | CS_RETCODE ct_cmd_props(CS_COMMAND * cmd, CS_INT action, CS_INT property, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
119 | CS_RETCODE ct_compute_info(CS_COMMAND * cmd, CS_INT type, CS_INT colnum, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
120 | CS_RETCODE ct_get_data(CS_COMMAND * cmd, CS_INT item, CS_VOID * buffer, CS_INT buflen, CS_INT * outlen);
121 | CS_RETCODE ct_send_data(CS_COMMAND * cmd, CS_VOID * buffer, CS_INT buflen);
122 | CS_RETCODE ct_data_info(CS_COMMAND * cmd, CS_INT action, CS_INT colnum, CS_IODESC * iodesc);
123 | CS_RETCODE ct_capability(CS_CONNECTION * con, CS_INT action, CS_INT type, CS_INT capability, CS_VOID * value);
124 | CS_RETCODE ct_dynamic(CS_COMMAND * cmd, CS_INT type, CS_CHAR * id, CS_INT idlen, CS_CHAR * buffer, CS_INT buflen);
125 | CS_RETCODE ct_param(CS_COMMAND * cmd, CS_DATAFMT * datafmt, CS_VOID * data, CS_INT datalen, CS_SMALLINT indicator);
126 | CS_RETCODE ct_setparam(CS_COMMAND * cmd, CS_DATAFMT * datafmt, CS_VOID * data, CS_INT * datalen, CS_SMALLINT * indicator);
127 | CS_RETCODE ct_options(CS_CONNECTION * con, CS_INT action, CS_INT option, CS_VOID * param, CS_INT paramlen, CS_INT * outlen);
128 | CS_RETCODE ct_poll(CS_CONTEXT * ctx, CS_CONNECTION * connection, CS_INT milliseconds, CS_CONNECTION ** compconn,
129 | CS_COMMAND ** compcmd, CS_INT * compid, CS_INT * compstatus);
130 | CS_RETCODE ct_cursor(CS_COMMAND * cmd, CS_INT type, CS_CHAR * name, CS_INT namelen, CS_CHAR * text, CS_INT tlen, CS_INT option);
131 | CS_RETCODE ct_diag(CS_CONNECTION * conn, CS_INT operation, CS_INT type, CS_INT idx, CS_VOID * buffer);
132 |
133 | #ifdef __cplusplus
134 | #if 0
135 | {
136 | #endif
137 | }
138 | #endif
139 |
140 | #endif
141 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/libsybdb.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/martinrybak/SQLClient/6a84468d4a2707fcaa81ba0c01b046846cdad1d7/SQLClient/SQLClient/SQLClient/libsybdb.a
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/odbcss.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 2008 Frediano Ziglio
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef _odbcss_h_
21 | #define _odbcss_h_
22 |
23 | #ifdef TDSODBC_BCP
24 | #include
25 | #endif
26 |
27 | #ifdef __cplusplus
28 | extern "C" {
29 | #endif
30 |
31 | #define SQL_DIAG_SS_MSGSTATE (-1150)
32 | #define SQL_DIAG_SS_LINE (-1154)
33 |
34 | #define SQL_SOPT_SS_QUERYNOTIFICATION_TIMEOUT 1233
35 | #define SQL_SOPT_SS_QUERYNOTIFICATION_MSGTEXT 1234
36 | #define SQL_SOPT_SS_QUERYNOTIFICATION_OPTIONS 1235
37 |
38 | #ifndef SQL_SS_LENGTH_UNLIMITED
39 | #define SQL_SS_LENGTH_UNLIMITED 0
40 | #endif
41 |
42 | #ifndef SQL_COPT_SS_BASE
43 | #define SQL_COPT_SS_BASE 1200
44 | #endif
45 |
46 | #ifndef SQL_COPT_SS_MARS_ENABLED
47 | #define SQL_COPT_SS_MARS_ENABLED (SQL_COPT_SS_BASE+24)
48 | #endif
49 |
50 | #ifndef SQL_COPT_SS_OLDPWD
51 | #define SQL_COPT_SS_OLDPWD (SQL_COPT_SS_BASE+26)
52 | #endif
53 |
54 | #define SQL_INFO_FREETDS_TDS_VERSION 1300
55 |
56 | #ifndef SQL_MARS_ENABLED_NO
57 | #define SQL_MARS_ENABLED_NO 0
58 | #endif
59 |
60 | #ifndef SQL_MARS_ENABLED_YES
61 | #define SQL_MARS_ENABLED_YES 1
62 | #endif
63 |
64 | #ifndef SQL_SS_VARIANT
65 | #define SQL_SS_VARIANT (-150)
66 | #endif
67 |
68 | #ifndef SQL_SS_UDT
69 | #define SQL_SS_UDT (-151)
70 | #endif
71 |
72 | #ifndef SQL_SS_XML
73 | #define SQL_SS_XML (-152)
74 | #endif
75 |
76 | #ifndef SQL_SS_TABLE
77 | #define SQL_SS_TABLE (-153)
78 | #endif
79 |
80 | #ifndef SQL_SS_TIME2
81 | #define SQL_SS_TIME2 (-154)
82 | #endif
83 |
84 | #ifndef SQL_SS_TIMESTAMPOFFSET
85 | #define SQL_SS_TIMESTAMPOFFSET (-155)
86 | #endif
87 |
88 | /*
89 | * these types are used from conversion from client to server
90 | */
91 | #ifndef SQL_C_SS_TIME2
92 | #define SQL_C_SS_TIME2 (0x4000)
93 | #endif
94 |
95 | #ifndef SQL_C_SS_TIMESTAMPOFFSET
96 | #define SQL_C_SS_TIMESTAMPOFFSET (0x4001)
97 | #endif
98 |
99 | #ifndef SQL_CA_SS_BASE
100 | #define SQL_CA_SS_BASE 1200
101 | #endif
102 |
103 | #ifndef SQL_CA_SS_UDT_CATALOG_NAME
104 | #define SQL_CA_SS_UDT_CATALOG_NAME (SQL_CA_SS_BASE+18)
105 | #endif
106 |
107 | #ifndef SQL_CA_SS_UDT_SCHEMA_NAME
108 | #define SQL_CA_SS_UDT_SCHEMA_NAME (SQL_CA_SS_BASE+19)
109 | #endif
110 |
111 | #ifndef SQL_CA_SS_UDT_TYPE_NAME
112 | #define SQL_CA_SS_UDT_TYPE_NAME (SQL_CA_SS_BASE+20)
113 | #endif
114 |
115 | #ifndef SQL_CA_SS_UDT_ASSEMBLY_TYPE_NAME
116 | #define SQL_CA_SS_UDT_ASSEMBLY_TYPE_NAME (SQL_CA_SS_BASE+21)
117 | #endif
118 |
119 | #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME
120 | #define SQL_CA_SS_XML_SCHEMACOLLECTION_CATALOG_NAME (SQL_CA_SS_BASE+22)
121 | #endif
122 |
123 | #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME
124 | #define SQL_CA_SS_XML_SCHEMACOLLECTION_SCHEMA_NAME (SQL_CA_SS_BASE+23)
125 | #endif
126 |
127 | #ifndef SQL_CA_SS_XML_SCHEMACOLLECTION_NAME
128 | #define SQL_CA_SS_XML_SCHEMACOLLECTION_NAME (SQL_CA_SS_BASE+24)
129 | #endif
130 |
131 | typedef struct tagSS_TIME2_STRUCT {
132 | SQLUSMALLINT hour;
133 | SQLUSMALLINT minute;
134 | SQLUSMALLINT second;
135 | SQLUINTEGER fraction;
136 | } SQL_SS_TIME2_STRUCT;
137 |
138 | typedef struct tagSS_TIMESTAMPOFFSET_STRUCT {
139 | SQLSMALLINT year;
140 | SQLUSMALLINT month;
141 | SQLUSMALLINT day;
142 | SQLUSMALLINT hour;
143 | SQLUSMALLINT minute;
144 | SQLUSMALLINT second;
145 | SQLUINTEGER fraction;
146 | SQLSMALLINT timezone_hour;
147 | SQLSMALLINT timezone_minute;
148 | } SQL_SS_TIMESTAMPOFFSET_STRUCT;
149 |
150 |
151 | #ifdef TDSODBC_BCP
152 |
153 | #ifndef SUCCEED
154 | #define SUCCEED 1
155 | #endif
156 | #ifndef FAIL
157 | #define FAIL 0
158 | #endif
159 |
160 | #ifndef BCPKEEPIDENTITY
161 | #define BCPKEEPIDENTITY 8
162 | #endif
163 | #ifndef BCPHINTS
164 | #define BCPHINTS 6
165 | #endif
166 |
167 | #define BCP_DIRECTION_IN 1
168 |
169 | #define SQL_COPT_SS_BCP (SQL_COPT_SS_BASE+19)
170 | #define SQL_BCP_OFF 0
171 | #define SQL_BCP_ON 1
172 |
173 | #define SQL_COPT_TDSODBC_IMPL_BASE 1500
174 | #define SQL_COPT_TDSODBC_IMPL_BCP_INITA (SQL_COPT_TDSODBC_IMPL_BASE)
175 | #define SQL_COPT_TDSODBC_IMPL_BCP_CONTROL (SQL_COPT_TDSODBC_IMPL_BASE+1)
176 | #define SQL_COPT_TDSODBC_IMPL_BCP_COLPTR (SQL_COPT_TDSODBC_IMPL_BASE+2)
177 | #define SQL_COPT_TDSODBC_IMPL_BCP_SENDROW (SQL_COPT_TDSODBC_IMPL_BASE+3)
178 | #define SQL_COPT_TDSODBC_IMPL_BCP_BATCH (SQL_COPT_TDSODBC_IMPL_BASE+4)
179 | #define SQL_COPT_TDSODBC_IMPL_BCP_DONE (SQL_COPT_TDSODBC_IMPL_BASE+5)
180 | #define SQL_COPT_TDSODBC_IMPL_BCP_BIND (SQL_COPT_TDSODBC_IMPL_BASE+6)
181 | #define SQL_COPT_TDSODBC_IMPL_BCP_INITW (SQL_COPT_TDSODBC_IMPL_BASE+7)
182 |
183 | #define SQL_VARLEN_DATA -10
184 |
185 | /* copied from sybdb.h which was copied from tds.h */
186 | /* TODO find a much better way... */
187 | enum
188 | {
189 | BCP_TYPE_SQLCHAR = 47, /* 0x2F */
190 | #define BCP_TYPE_SQLCHAR BCP_TYPE_SQLCHAR
191 | BCP_TYPE_SQLVARCHAR = 39, /* 0x27 */
192 | #define BCP_TYPE_SQLVARCHAR BCP_TYPE_SQLVARCHAR
193 | BCP_TYPE_SQLINTN = 38, /* 0x26 */
194 | #define BCP_TYPE_SQLINTN BCP_TYPE_SQLINTN
195 | BCP_TYPE_SQLINT1 = 48, /* 0x30 */
196 | #define BCP_TYPE_SQLINT1 BCP_TYPE_SQLINT1
197 | BCP_TYPE_SQLINT2 = 52, /* 0x34 */
198 | #define BCP_TYPE_SQLINT2 BCP_TYPE_SQLINT2
199 | BCP_TYPE_SQLINT4 = 56, /* 0x38 */
200 | #define BCP_TYPE_SQLINT4 BCP_TYPE_SQLINT4
201 | BCP_TYPE_SQLINT8 = 127, /* 0x7F */
202 | #define BCP_TYPE_SQLINT8 BCP_TYPE_SQLINT8
203 | BCP_TYPE_SQLFLT8 = 62, /* 0x3E */
204 | #define BCP_TYPE_SQLFLT8 BCP_TYPE_SQLFLT8
205 | BCP_TYPE_SQLDATETIME = 61, /* 0x3D */
206 | #define BCP_TYPE_SQLDATETIME BCP_TYPE_SQLDATETIME
207 | BCP_TYPE_SQLBIT = 50, /* 0x32 */
208 | #define BCP_TYPE_SQLBIT BCP_TYPE_SQLBIT
209 | BCP_TYPE_SQLBITN = 104, /* 0x68 */
210 | #define BCP_TYPE_SQLBITN BCP_TYPE_SQLBITN
211 | BCP_TYPE_SQLTEXT = 35, /* 0x23 */
212 | #define BCP_TYPE_SQLTEXT BCP_TYPE_SQLTEXT
213 | BCP_TYPE_SQLNTEXT = 99, /* 0x63 */
214 | #define BCP_TYPE_SQLNTEXT BCP_TYPE_SQLNTEXT
215 | BCP_TYPE_SQLIMAGE = 34, /* 0x22 */
216 | #define BCP_TYPE_SQLIMAGE BCP_TYPE_SQLIMAGE
217 | BCP_TYPE_SQLMONEY4 = 122, /* 0x7A */
218 | #define BCP_TYPE_SQLMONEY4 BCP_TYPE_SQLMONEY4
219 | BCP_TYPE_SQLMONEY = 60, /* 0x3C */
220 | #define BCP_TYPE_SQLMONEY BCP_TYPE_SQLMONEY
221 | BCP_TYPE_SQLDATETIME4 = 58, /* 0x3A */
222 | #define BCP_TYPE_SQLDATETIME4 BCP_TYPE_SQLDATETIME4
223 | BCP_TYPE_SQLREAL = 59, /* 0x3B */
224 | BCP_TYPE_SQLFLT4 = 59, /* 0x3B */
225 | #define BCP_TYPE_SQLREAL BCP_TYPE_SQLREAL
226 | #define BCP_TYPE_SQLFLT4 BCP_TYPE_SQLFLT4
227 | BCP_TYPE_SQLBINARY = 45, /* 0x2D */
228 | #define BCP_TYPE_SQLBINARY BCP_TYPE_SQLBINARY
229 | BCP_TYPE_SQLVOID = 31, /* 0x1F */
230 | #define BCP_TYPE_SQLVOID BCP_TYPE_SQLVOID
231 | BCP_TYPE_SQLVARBINARY = 37, /* 0x25 */
232 | #define BCP_TYPE_SQLVARBINARY BCP_TYPE_SQLVARBINARY
233 | BCP_TYPE_SQLNUMERIC = 108, /* 0x6C */
234 | #define BCP_TYPE_SQLNUMERIC BCP_TYPE_SQLNUMERIC
235 | BCP_TYPE_SQLDECIMAL = 106, /* 0x6A */
236 | #define BCP_TYPE_SQLDECIMAL BCP_TYPE_SQLDECIMAL
237 | BCP_TYPE_SQLFLTN = 109, /* 0x6D */
238 | #define BCP_TYPE_SQLFLTN BCP_TYPE_SQLFLTN
239 | BCP_TYPE_SQLMONEYN = 110, /* 0x6E */
240 | #define BCP_TYPE_SQLMONEYN BCP_TYPE_SQLMONEYN
241 | BCP_TYPE_SQLDATETIMN = 111, /* 0x6F */
242 | #define BCP_TYPE_SQLDATETIMN BCP_TYPE_SQLDATETIMN
243 | BCP_TYPE_SQLNVARCHAR = 103, /* 0x67 */
244 | #define BCP_TYPE_SQLNVARCHAR BCP_TYPE_SQLNVARCHAR
245 | BCP_TYPE_SQLUNIQUEID = 36, /* 0x24 */
246 | #define BCP_TYPE_SQLUNIQUEID BCP_TYPE_SQLUNIQUEID
247 | BCP_TYPE_SQLDATETIME2 = 42, /* 0x2a */
248 | #define BCP_TYPE_SQLDATETIME2 BCP_TYPE_SQLDATETIME2
249 | };
250 |
251 | typedef struct
252 | {
253 | int dtdays;
254 | int dttime;
255 | } DBDATETIME;
256 |
257 | #ifdef _MSC_VER
258 | #define TDSODBC_INLINE __inline
259 | #else
260 | #define TDSODBC_INLINE __inline__
261 | #endif
262 |
263 | struct tdsodbc_impl_bcp_init_params
264 | {
265 | const void *tblname;
266 | const void *hfile;
267 | const void *errfile;
268 | int direction;
269 | };
270 |
271 | static TDSODBC_INLINE RETCODE SQL_API
272 | bcp_initA(HDBC hdbc, const char *tblname, const char *hfile, const char *errfile, int direction)
273 | {
274 | struct tdsodbc_impl_bcp_init_params params = {tblname, hfile, errfile, direction};
275 | return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_INITA, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
276 | }
277 |
278 | static TDSODBC_INLINE RETCODE SQL_API
279 | bcp_initW(HDBC hdbc, const SQLWCHAR *tblname, const SQLWCHAR *hfile, const SQLWCHAR *errfile, int direction)
280 | {
281 | struct tdsodbc_impl_bcp_init_params params = {tblname, hfile, errfile, direction};
282 | return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_INITW, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
283 | }
284 |
285 | struct tdsodbc_impl_bcp_control_params
286 | {
287 | int field;
288 | void *value;
289 | };
290 |
291 | static TDSODBC_INLINE RETCODE SQL_API
292 | bcp_control(HDBC hdbc, int field, void *value)
293 | {
294 | struct tdsodbc_impl_bcp_control_params params = {field, value};
295 | return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_CONTROL, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
296 | }
297 |
298 | struct tdsodbc_impl_bcp_colptr_params
299 | {
300 | const unsigned char * colptr;
301 | int table_column;
302 | };
303 |
304 | static TDSODBC_INLINE RETCODE SQL_API
305 | bcp_colptr(HDBC hdbc, const unsigned char * colptr, int table_column)
306 | {
307 | struct tdsodbc_impl_bcp_colptr_params params = {colptr, table_column};
308 | return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_COLPTR, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
309 | }
310 |
311 | static TDSODBC_INLINE RETCODE SQL_API
312 | bcp_sendrow(HDBC hdbc)
313 | {
314 | return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_SENDROW, NULL, SQL_IS_POINTER)) ? SUCCEED : FAIL;
315 | }
316 |
317 | struct tdsodbc_impl_bcp_batch_params
318 | {
319 | int rows;
320 | };
321 |
322 | static TDSODBC_INLINE int SQL_API
323 | bcp_batch(HDBC hdbc)
324 | {
325 | struct tdsodbc_impl_bcp_batch_params params = {-1};
326 | return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_BATCH, ¶ms, SQL_IS_POINTER)) ? params.rows : -1;
327 | }
328 |
329 | struct tdsodbc_impl_bcp_done_params
330 | {
331 | int rows;
332 | };
333 |
334 | static TDSODBC_INLINE int SQL_API
335 | bcp_done(HDBC hdbc)
336 | {
337 | struct tdsodbc_impl_bcp_done_params params = {-1};
338 | return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_DONE, ¶ms, SQL_IS_POINTER)) ? params.rows : -1;
339 | }
340 |
341 | struct tdsodbc_impl_bcp_bind_params
342 | {
343 | const unsigned char * varaddr;
344 | int prefixlen;
345 | int varlen;
346 | const unsigned char * terminator;
347 | int termlen;
348 | int vartype;
349 | int table_column;
350 | };
351 |
352 | static TDSODBC_INLINE RETCODE SQL_API
353 | bcp_bind(HDBC hdbc, const unsigned char * varaddr, int prefixlen, int varlen,
354 | const unsigned char * terminator, int termlen, int vartype, int table_column)
355 | {
356 | struct tdsodbc_impl_bcp_bind_params params = {varaddr, prefixlen, varlen, terminator, termlen, vartype, table_column};
357 | return SQL_SUCCEEDED(SQLSetConnectAttr(hdbc, SQL_COPT_TDSODBC_IMPL_BCP_BIND, ¶ms, SQL_IS_POINTER)) ? SUCCEED : FAIL;
358 | }
359 |
360 | #ifdef UNICODE
361 | #define bcp_init bcp_initW
362 | #else
363 | #define bcp_init bcp_initA
364 | #endif
365 |
366 | #endif /* TDSODBC_BCP */
367 |
368 | #ifdef __cplusplus
369 | }
370 | #endif
371 |
372 | #endif /* _odbcss_h_ */
373 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/sqldb.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998-1999 Brian Bruns
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef SQLDB_h
21 | #define SQLDB_h
22 |
23 | #include "./sybdb.h"
24 |
25 | #define SQLCHAR SYBCHAR
26 | #define SQLVARCHAR SYBVARCHAR
27 | #define SQLINTN SYBINTN
28 | #define SQLINT1 SYBINT1
29 | #define SQLINT2 SYBINT2
30 | #define SQLINT4 SYBINT4
31 | #define SQLINT8 SYBINT8
32 | #define SQLFLT8 SYBFLT8
33 | #define SQLDATETIME SYBDATETIME
34 | #define SQLBIT SYBBIT
35 | #define SQLTEXT SYBTEXT
36 | #define SQLIMAGE SYBIMAGE
37 | #define SQLMONEY4 SYBMONEY4
38 | #define SQLMONEY SYBMONEY
39 | #define SQLDATETIM4 SYBDATETIME4
40 | #define SQLFLT4 SYBREAL
41 | #define SQLBINARY SYBBINARY
42 | #define SQLVARBINARY SYBVARBINARY
43 | #define SQLNUMERIC SYBNUMERIC
44 | #define SQLDECIMAL SYBDECIMAL
45 | #define SQLFLTN SYBFLTN
46 | #define SQLMONEYN SYBMONEYN
47 | #define SQLDATETIMN SYBDATETIMN
48 | #define SQLVOID SYBVOID
49 |
50 | #define SMALLDATETIBIND SMALLDATETIMEBIND
51 |
52 | #define DBERRHANDLE_PROC EHANDLEFUNC
53 | #define DBMSGHANDLE_PROC MHANDLEFUNC
54 |
55 | /* DB-Library errors as defined by Microsoft */
56 | #define SQLEMEM SYBEMEM
57 | #define SQLENULL SYBENULL
58 | #define SQLENLOG SYBENLOG
59 | #define SQLEPWD SYBEPWD
60 | #define SQLECONN SYBECONN
61 | #define SQLEDDNE SYBEDDNE
62 | #define SQLENULLO SYBENULLO
63 | #define SQLESMSG SYBESMSG
64 | #define SQLEBTOK SYBEBTOK
65 | #define SQLENSPE SYBENSPE
66 | #define SQLEREAD SYBEREAD
67 | #define SQLECNOR SYBECNOR
68 | #define SQLETSIT SYBETSIT
69 | #define SQLEPARM SYBEPARM
70 | #define SQLEAUTN SYBEAUTN
71 | #define SQLECOFL SYBECOFL
72 | #define SQLERDCN SYBERDCN
73 | #define SQLEICN SYBEICN
74 | #define SQLECLOS SYBECLOS
75 | #define SQLENTXT SYBENTXT
76 | #define SQLEDNTI SYBEDNTI
77 | #define SQLETMTD SYBETMTD
78 | #define SQLEASEC SYBEASEC
79 | #define SQLENTLL SYBENTLL
80 | #define SQLETIME SYBETIME
81 | #define SQLEWRIT SYBEWRIT
82 | #define SQLEMODE SYBEMODE
83 | #define SQLEOOB SYBEOOB
84 | #define SQLEITIM SYBEITIM
85 | #define SQLEDBPS SYBEDBPS
86 | #define SQLEIOPT SYBEIOPT
87 | #define SQLEASNL SYBEASNL
88 | #define SQLEASUL SYBEASUL
89 | #define SQLENPRM SYBENPRM
90 | #define SQLEDBOP SYBEDBOP
91 | #define SQLENSIP SYBENSIP
92 | #define SQLECNULL SYBECNULL
93 | #define SQLESEOF SYBESEOF
94 | #define SQLERPND SYBERPND
95 | #define SQLECSYN SYBECSYN
96 | #define SQLENONET SYBENONET
97 | #define SQLEBTYP SYBEBTYP
98 | #define SQLEABNC SYBEABNC
99 | #define SQLEABMT SYBEABMT
100 | #define SQLEABNP SYBEABNP
101 | #define SQLEBNCR SYBEBNCR
102 | #define SQLEAAMT SYBEAAMT
103 | #define SQLENXID SYBENXID
104 | #define SQLEIFNB SYBEIFNB
105 | #define SQLEKBCO SYBEKBCO
106 | #define SQLEBBCI SYBEBBCI
107 | #define SQLEKBCI SYBEKBCI
108 | #define SQLEBCWE SYBEBCWE
109 | #define SQLEBCNN SYBEBCNN
110 | #define SQLEBCOR SYBEBCOR
111 | #define SQLEBCPI SYBEBCPI
112 | #define SQLEBCPN SYBEBCPN
113 | #define SQLEBCPB SYBEBCPB
114 | #define SQLEVDPT SYBEVDPT
115 | #define SQLEBIVI SYBEBIVI
116 | #define SQLEBCBC SYBEBCBC
117 | #define SQLEBCFO SYBEBCFO
118 | #define SQLEBCVH SYBEBCVH
119 | #define SQLEBCUO SYBEBCUO
120 | #define SQLEBUOE SYBEBUOE
121 | #define SQLEBWEF SYBEBWEF
122 | #define SQLEBTMT SYBEBTMT
123 | #define SQLEBEOF SYBEBEOF
124 | #define SQLEBCSI SYBEBCSI
125 | #define SQLEPNUL SYBEPNUL
126 | #define SQLEBSKERR SYBEBSKERR
127 | #define SQLEBDIO SYBEBDIO
128 | #define SQLEBCNT SYBEBCNT
129 | #define SQLEMDBP SYBEMDBP
130 | #define SQLINIT SYBINIT
131 | #define SQLCRSINV SYBCRSINV
132 | #define SQLCRSCMD SYBCRSCMD
133 | #define SQLCRSNOIND SYBCRSNOIND
134 | #define SQLCRSDIS SYBCRSDIS
135 | #define SQLCRSAGR SYBCRSAGR
136 | #define SQLCRSORD SYBCRSORD
137 | #define SQLCRSMEM SYBCRSMEM
138 | #define SQLCRSBSKEY SYBCRSBSKEY
139 | #define SQLCRSNORES SYBCRSNORES
140 | #define SQLCRSVIEW SYBCRSVIEW
141 | #define SQLCRSBUFR SYBCRSBUFR
142 | #define SQLCRSFROWN SYBCRSFROWN
143 | #define SQLCRSBROL SYBCRSBROL
144 | #define SQLCRSFRAND SYBCRSFRAND
145 | #define SQLCRSFLAST SYBCRSFLAST
146 | #define SQLCRSRO SYBCRSRO
147 | #define SQLCRSTAB SYBCRSTAB
148 | #define SQLCRSUPDTAB SYBCRSUPDTAB
149 | #define SQLCRSUPDNB SYBCRSUPDNB
150 | #define SQLCRSVIIND SYBCRSVIIND
151 | #define SQLCRSNOUPD SYBCRSNOUPD
152 | #define SQLCRSOS SYBCRSOS
153 | #define SQLEBCSA SYBEBCSA
154 | #define SQLEBCRO SYBEBCRO
155 | #define SQLEBCNE SYBEBCNE
156 | #define SQLEBCSK SYBEBCSK
157 | #define SQLEUVBF SYBEUVBF
158 | #define SQLEBIHC SYBEBIHC
159 | #define SQLEBWFF SYBEBWFF
160 | #define SQLNUMVAL SYBNUMVAL
161 | #define SQLEOLDVR SYBEOLDVR
162 | #define SQLEBCPS SYBEBCPS
163 | #define SQLEDTC SYBEDTC
164 | #define SQLENOTIMPL SYBENOTIMPL
165 | #define SQLENONFLOAT SYBENONFLOAT
166 | #define SQLECONNFB SYBECONNFB
167 |
168 |
169 | #define dbfreelogin(x) dbloginfree((x))
170 |
171 | #define dbprocerrhandle(p, h) dberrhandle((h))
172 | #define dbprocmsghandle(p, h) dbmsghandle((h))
173 |
174 | #define dbwinexit()
175 |
176 | static const char rcsid_sqldb_h[] = "$Id: sqldb.h,v 1.6 2009-12-02 22:35:18 jklowden Exp $";
177 | static const void *const no_unused_sqldb_h_warn[] = { rcsid_sqldb_h, no_unused_sqldb_h_warn };
178 |
179 |
180 | #endif
181 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/sqlfront.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998-1999 Brian Bruns
3 | * Copyright (C) 2011 Frediano Ziglio
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | */
20 |
21 | #ifndef SQLFRONT_h
22 | #define SQLFRONT_h
23 |
24 | #include "./sybfront.h"
25 |
26 | static const char rcsid_sqlfront_h[] = "$Id: sqlfront.h,v 1.10 2011-07-13 11:06:31 freddy77 Exp $";
27 | static const void *const no_unused_sqlfront_h_warn[] = { rcsid_sqlfront_h, no_unused_sqlfront_h_warn };
28 |
29 | typedef DBPROCESS * PDBPROCESS;
30 | typedef LOGINREC * PLOGINREC;
31 | typedef DBCURSOR * PDBCURSOR;
32 |
33 | typedef int * LPINT;
34 | typedef char * LPSTR;
35 | #if !defined(PHP_MSSQL_H) || !defined(PHP_MSSQL_API)
36 | typedef BYTE * LPBYTE;
37 | #endif
38 | typedef void * LPVOID;
39 | typedef const char * LPCSTR;
40 |
41 | typedef const LPINT LPCINT;
42 | #ifndef _LPCBYTE_DEFINED
43 | #define _LPCBYTE_DEFINED
44 | typedef const BYTE * LPCBYTE;
45 | #endif
46 | typedef USHORT * LPUSHORT;
47 | typedef const LPUSHORT LPCUSHORT;
48 | typedef DBINT * LPDBINT;
49 | typedef const LPDBINT LPCDBINT;
50 | typedef DBBINARY * LPDBBINARY;
51 | typedef const LPDBBINARY LPCDBBINARY;
52 | typedef DBDATEREC * LPDBDATEREC;
53 | typedef const LPDBDATEREC LPCDBDATEREC;
54 | typedef DBDATETIME * LPDBDATETIME;
55 | typedef const LPDBDATETIME LPCDBDATETIME;
56 |
57 | #endif
58 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/syberror.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998-1999 Brian Bruns
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef _syberror_h_
21 | #define _syberror_h_
22 |
23 | #ifdef __cplusplus
24 | extern "C"
25 | {
26 | #if 0
27 | }
28 | #endif
29 | #endif
30 |
31 | static const char rcsid_syberror_h[] = "$Id: syberror.h,v 1.4 2004-10-28 12:42:12 freddy77 Exp $";
32 | static const void *const no_unused_syberror_h_warn[] = { rcsid_syberror_h, no_unused_syberror_h_warn };
33 |
34 | /* severity levels, gleaned from google */
35 | #define EXINFO 1
36 | #define EXUSER 2
37 | #define EXNONFATAL 3
38 | #define EXCONVERSION 4
39 | #define EXSERVER 5
40 | #define EXTIME 6
41 | #define EXPROGRAM 7
42 | #define EXRESOURCE 8
43 | #define EXCOMM 9
44 | #define EXFATAL 10
45 | #define EXCONSISTENCY 11
46 |
47 | #ifdef __cplusplus
48 | #if 0
49 | {
50 | #endif
51 | }
52 | #endif
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/sybfront.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998-1999 Brian Bruns
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef SYBFRONT_h
21 | #define SYBFRONT_h
22 |
23 | #include "sybdb.h"
24 |
25 | #ifdef __cplusplus
26 | extern "C"
27 | {
28 | #if 0
29 | }
30 | #endif
31 | #endif
32 |
33 | static const char rcsid_sybfront_h[] = "$Id: sybfront.h,v 1.3 2004-10-28 12:42:12 freddy77 Exp $";
34 | static const void *const no_unused_sybfront_h_warn[] = { rcsid_sybfront_h, no_unused_sybfront_h_warn };
35 |
36 |
37 |
38 | #ifdef __cplusplus
39 | #if 0
40 | {
41 | #endif
42 | }
43 | #endif
44 |
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLClient/tds_sysdep_public.h:
--------------------------------------------------------------------------------
1 | /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 | * Copyright (C) 1998-2011 Brian Bruns
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Library General Public
6 | * License as published by the Free Software Foundation; either
7 | * version 2 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Library General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Library General Public
15 | * License along with this library; if not, write to the
16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 | * Boston, MA 02111-1307, USA.
18 | */
19 |
20 | #ifndef _tds_sysdep_public_h_
21 | #define _tds_sysdep_public_h_
22 |
23 | /*
24 | ** This is where platform-specific changes need to be made.
25 | */
26 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
27 | #include
28 | #include
29 | #include
30 | #define tds_sysdep_int16_type short /* 16-bit int */
31 | #define tds_sysdep_int32_type int /* 32-bit int */
32 | #define tds_sysdep_int64_type __int64 /* 64-bit int */
33 | #define tds_sysdep_real32_type float /* 32-bit real */
34 | #define tds_sysdep_real64_type double /* 64-bit real */
35 | #if !defined(WIN64) && !defined(_WIN64)
36 | #define tds_sysdep_intptr_type int /* 32-bit int */
37 | #else
38 | #define tds_sysdep_intptr_type __int64 /* 64-bit int */
39 | #endif
40 | #endif /* defined(WIN32) || defined(_WIN32) || defined(__WIN32__) */
41 |
42 | #ifndef tds_sysdep_int16_type
43 | #define tds_sysdep_int16_type short /* 16-bit int */
44 | #endif /* !tds_sysdep_int16_type */
45 |
46 | #ifndef tds_sysdep_int32_type
47 | #define tds_sysdep_int32_type int /* 32-bit int */
48 | #endif /* !tds_sysdep_int32_type */
49 |
50 | #ifndef tds_sysdep_int64_type
51 | #define tds_sysdep_int64_type long long /* 64-bit int */
52 | #endif /* !tds_sysdep_int64_type */
53 |
54 | #ifndef tds_sysdep_real32_type
55 | #define tds_sysdep_real32_type float /* 32-bit real */
56 | #endif /* !tds_sysdep_real32_type */
57 |
58 | #ifndef tds_sysdep_real64_type
59 | #define tds_sysdep_real64_type double /* 64-bit real */
60 | #endif /* !tds_sysdep_real64_type */
61 |
62 | #ifndef tds_sysdep_intptr_type
63 | #define tds_sysdep_intptr_type int
64 | #endif /* !tds_sysdep_intptr_type */
65 |
66 | #if !defined(MSDBLIB) && !defined(SYBDBLIB)
67 | #define SYBDBLIB 1
68 | #endif
69 | #if defined(MSDBLIB) && defined(SYBDBLIB)
70 | #error MSDBLIB and SYBDBLIB cannot both be defined
71 | #endif
72 |
73 | #endif /* _tds_sysdep_public_h_ */
74 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // SQLViewController.h
3 | // SQLClient
4 | //
5 | // Created by Martin Rybak on 10/14/13.
6 | // Copyright (c) 2013 Martin Rybak. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SQLClient.h"
11 |
12 | @interface SQLViewController : UIViewController
13 |
14 | @end
--------------------------------------------------------------------------------
/SQLClient/SQLClient/SQLViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // SQLViewController.m
3 | // SQLClient
4 | //
5 | // Created by Martin Rybak on 10/14/13.
6 | // Copyright (c) 2013 Martin Rybak. All rights reserved.
7 | //
8 |
9 | #import "SQLViewController.h"
10 | #import "SQLClient.h"
11 |
12 | @interface SQLViewController ()
13 |
14 | @property (strong, nonatomic) UITextView* textView;
15 | @property (strong, nonatomic) UIActivityIndicatorView* spinner;
16 |
17 | @end
18 |
19 | @implementation SQLViewController
20 |
21 | #pragma mark - NSObject
22 |
23 | - (instancetype)init
24 | {
25 | if (self = [super init]) {
26 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(error:) name:SQLClientErrorNotification object:nil];
27 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(message:) name:SQLClientMessageNotification object:nil];
28 | }
29 | return self;
30 | }
31 |
32 | - (void)dealloc
33 | {
34 | [[NSNotificationCenter defaultCenter] removeObserver:self];
35 | }
36 |
37 | #pragma mark - UIViewController
38 |
39 | - (void)loadView
40 | {
41 | self.view = [[UIView alloc] init];
42 |
43 | //Load textView
44 | UITextView* textView = [[UITextView alloc] init];
45 | textView.editable = NO;
46 | textView.translatesAutoresizingMaskIntoConstraints = NO;
47 | [self.view addSubview:textView];
48 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[textView]|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
49 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[textView]|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
50 | self.textView = textView;
51 |
52 | //Load spinner
53 | UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
54 | spinner.hidesWhenStopped = YES;
55 | spinner.translatesAutoresizingMaskIntoConstraints = NO;
56 | [self.view addSubview:spinner];
57 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[spinner]-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(spinner)]];
58 | [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[spinner]-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(spinner)]];
59 | self.spinner = spinner;
60 | }
61 |
62 | - (void)viewDidLoad
63 | {
64 | [super viewDidLoad];
65 | [self connect];
66 | }
67 |
68 | #pragma mark - Private
69 |
70 | - (void)connect
71 | {
72 | SQLClient* client = [SQLClient sharedInstance];
73 | [self.spinner startAnimating];
74 | [client connect:@"server\\instance:port" username:@"user" password:@"pass" database:@"db" completion:^(BOOL success) {
75 | [self.spinner stopAnimating];
76 | if (success) {
77 | [self execute];
78 | }
79 | }];
80 | }
81 |
82 | - (void)execute
83 | {
84 | SQLClient* client = [SQLClient sharedInstance];
85 | [self.spinner startAnimating];
86 | [client execute:@"SELECT * FROM Table" completion:^(NSArray* results) {
87 | [self.spinner stopAnimating];
88 | [self process:results];
89 | [client disconnect];
90 | }];
91 | }
92 |
93 | - (void)process:(NSArray*)results
94 | {
95 | NSMutableString* output = [[NSMutableString alloc] init];
96 | for (NSArray* table in results) {
97 | for (NSDictionary* row in table) {
98 | for (NSString* column in row) {
99 | [output appendFormat:@"\n%@=%@", column, row[column]];
100 | }
101 | }
102 | }
103 | self.textView.text = output;
104 | }
105 |
106 | #pragma mark - SQLClientErrorNotification
107 |
108 | - (void)error:(NSNotification*)notification
109 | {
110 | NSNumber* code = notification.userInfo[SQLClientCodeKey];
111 | NSString* message = notification.userInfo[SQLClientMessageKey];
112 | NSNumber* severity = notification.userInfo[SQLClientSeverityKey];
113 |
114 | NSLog(@"Error #%@: %@ (Severity %@)", code, message, severity);
115 | [[[UIAlertView alloc] initWithTitle:@"Error" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
116 | }
117 |
118 | #pragma mark - SQLClientMessageNotification
119 |
120 | - (void)message:(NSNotification*)notification
121 | {
122 | NSString* message = notification.userInfo[SQLClientMessageKey];
123 | NSLog(@"Message: %@", message);
124 | }
125 |
126 | @end
127 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/SQLClient/SQLClient/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // SQLClient
4 | //
5 | // Created by Martin Rybak on 10/15/13.
6 | // Copyright (c) 2013 Martin Rybak. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "SQLAppDelegate.h"
12 |
13 | int main(int argc, char * argv[])
14 | {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([SQLAppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/SQLClient/SQLClientTests/SQLClientTests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/SQLClient/SQLClientTests/SQLClientTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // SQLClientTests.m
3 | // SQLClientTests
4 | //
5 | // Created by Martin Rybak on 10/15/13.
6 | // Copyright (c) 2013 Martin Rybak. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "SQLClient.h"
11 |
12 | @interface SQLClientTests : XCTestCase
13 |
14 | @end
15 |
16 | @implementation SQLClientTests
17 |
18 | #pragma mark - CRUD
19 |
20 | - (void)testSelectWithError
21 | {
22 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
23 | [self execute:@"SELECT" completion:^(NSArray* results) {
24 | XCTAssertNil(results);
25 | [expectation fulfill];
26 | }];
27 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
28 | }
29 |
30 | - (void)testSelectWithOneTable
31 | {
32 | NSString* sql = @"SELECT 'Foo' AS Bar";
33 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
34 | [self execute:sql completion:^(NSArray* results) {
35 | XCTAssertNotNil(results);
36 | XCTAssertEqual(results.count, 1);
37 | XCTAssertEqual([results[0] count], 1);
38 | XCTAssertEqualObjects(results[0][0][@"Bar"], @"Foo");
39 | [expectation fulfill];
40 | }];
41 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
42 | }
43 |
44 | - (void)testSelectWithTwoTables
45 | {
46 | NSMutableString* sql = [NSMutableString string];
47 | [sql appendString:@"SELECT 'Foo' AS Bar;"];
48 | [sql appendString:@"SELECT * FROM (VALUES (1), (2), (3)) AS Table1(a)"];
49 |
50 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
51 | [self execute:sql completion:^(NSArray* results) {
52 | XCTAssertNotNil(results);
53 | XCTAssertEqual(results.count, 2);
54 | XCTAssertEqual([results[0] count], 1);
55 | XCTAssertEqual([results[1] count], 3);
56 | XCTAssertEqualObjects(results[0][0][@"Bar"], @"Foo");
57 | XCTAssertEqualObjects(results[1][0][@"a"], @(1));
58 | XCTAssertEqualObjects(results[1][1][@"a"], @(2));
59 | XCTAssertEqualObjects(results[1][2][@"a"], @(3));
60 | [expectation fulfill];
61 | }];
62 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
63 | }
64 |
65 | - (void)testInsert
66 | {
67 | NSMutableString* sql = [NSMutableString string];
68 | [sql appendString:@"CREATE TABLE #Temp(Id INT IDENTITY, Name CHAR(20));"];
69 | [sql appendString:@"INSERT INTO #Temp (Name) VALUES ('Foo');"];
70 | [sql appendString:@"DROP TABLE #Temp;"];
71 |
72 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
73 | [self execute:sql completion:^(NSArray* results) {
74 | XCTAssertNotNil(results);
75 | XCTAssertEqual(results.count, 0);
76 | [expectation fulfill];
77 | }];
78 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
79 | }
80 |
81 | - (void)testInsertWithSelect
82 | {
83 | NSMutableString* sql = [NSMutableString string];
84 | [sql appendString:@"CREATE TABLE #Temp(Id INT IDENTITY, Name CHAR(20));"];
85 | [sql appendString:@"INSERT INTO #Temp (Name) VALUES ('Foo');"];
86 | [sql appendString:@"SELECT @@IDENTITY AS Id;"];
87 | [sql appendString:@"DROP TABLE #Temp;"];
88 |
89 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
90 | [self execute:sql completion:^(NSArray* results) {
91 | XCTAssertNotNil(results);
92 | XCTAssertEqual(results.count, 1);
93 | XCTAssertEqual([results[0] count], 1);
94 | XCTAssertEqualObjects(results[0][0][@"Id"], @(1));
95 | [expectation fulfill];
96 | }];
97 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
98 | }
99 |
100 | - (void)testUpdate
101 | {
102 | NSMutableString* sql = [NSMutableString string];
103 | [sql appendString:@"CREATE TABLE #Temp(Id INT IDENTITY, Name CHAR(20));"];
104 | [sql appendString:@"INSERT INTO #Temp (Name) VALUES ('Foo');"];
105 | [sql appendString:@"UPDATE #Temp SET Name = 'Bar';"];
106 | [sql appendString:@"DROP TABLE #Temp;"];
107 |
108 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
109 | [self execute:sql completion:^(NSArray* results) {
110 | XCTAssertNotNil(results);
111 | XCTAssertEqual(results.count, 0);
112 | [expectation fulfill];
113 | }];
114 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
115 | }
116 |
117 | - (void)testUpdateWithSelect
118 | {
119 | NSMutableString* sql = [NSMutableString string];
120 | [sql appendString:@"CREATE TABLE #Temp(Id INT IDENTITY, Name CHAR(20));"];
121 | [sql appendString:@"INSERT INTO #Temp (Name) VALUES ('Foo');"];
122 | [sql appendString:@"UPDATE #Temp SET Name = 'Bar';"];
123 | [sql appendString:@"SELECT * FROM #Temp;"];
124 | [sql appendString:@"DROP TABLE #Temp;"];
125 |
126 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
127 | [self execute:sql completion:^(NSArray* results) {
128 | XCTAssertNotNil(results);
129 | XCTAssertEqual(results.count, 1);
130 | XCTAssertEqual([results[0] count], 1);
131 | XCTAssertEqualObjects(results[0][0][@"Id"], @(1));
132 | XCTAssertEqualObjects(results[0][0][@"Name"], @"Bar");
133 | [expectation fulfill];
134 | }];
135 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
136 | }
137 |
138 | - (void)testDelete
139 | {
140 | NSMutableString* sql = [NSMutableString string];
141 | [sql appendString:@"CREATE TABLE #Temp(Id INT IDENTITY, Name CHAR(20));"];
142 | [sql appendString:@"INSERT INTO #Temp (Name) VALUES ('Foo');"];
143 | [sql appendString:@"DELETE FROM #Temp;"];
144 | [sql appendString:@"DROP TABLE #Temp;"];
145 |
146 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
147 | [self execute:sql completion:^(NSArray* results) {
148 | XCTAssertNotNil(results);
149 | XCTAssertEqual(results.count, 0);
150 | [expectation fulfill];
151 | }];
152 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
153 | }
154 |
155 | - (void)testDeleteWithSelect
156 | {
157 | NSMutableString* sql = [NSMutableString string];
158 | [sql appendString:@"CREATE TABLE #Temp(Id INT IDENTITY, Name CHAR(20));"];
159 | [sql appendString:@"INSERT INTO #Temp (Name) VALUES ('Foo');"];
160 | [sql appendString:@"DELETE FROM #Temp;"];
161 | [sql appendString:@"SELECT * FROM #Temp;"];
162 | [sql appendString:@"DROP TABLE #Temp;"];
163 |
164 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
165 | [self execute:sql completion:^(NSArray* results) {
166 | XCTAssertNotNil(results);
167 | XCTAssertEqual(results.count, 1);
168 | XCTAssertEqual([results[0] count], 0);
169 | [expectation fulfill];
170 | }];
171 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
172 | }
173 |
174 | #pragma mark - Bit
175 |
176 | - (void)testBitWithNull
177 | {
178 | id value = [NSNull null];
179 | [self testValue:nil ofType:@"BIT" convertsTo:value];
180 | }
181 |
182 | - (void)testBitWithTrue
183 | {
184 | id value = @(YES);
185 | [self testValue:value ofType:@"BIT" convertsTo:value];
186 | }
187 |
188 | - (void)testBitWithFalse
189 | {
190 | id value = @(YES);
191 | [self testValue:value ofType:@"BIT" convertsTo:value];
192 | }
193 |
194 | #pragma mark - Tiny Int
195 |
196 | - (void)testTinyIntWithNull
197 | {
198 | id value = [NSNull null];
199 | [self testValue:nil ofType:@"TINYINT" convertsTo:value];
200 | }
201 |
202 | - (void)testTinyIntWithMinimum
203 | {
204 | id value = @(0);
205 | [self testValue:value ofType:@"TINYINT" convertsTo:value];
206 | }
207 |
208 | - (void)testTinyIntWithMaximum
209 | {
210 | id value = @(UCHAR_MAX);
211 | [self testValue:value ofType:@"TINYINT" convertsTo:value];
212 | }
213 |
214 | #pragma mark - Small Int
215 |
216 | - (void)testSmallIntWithNull
217 | {
218 | id value = [NSNull null];
219 | [self testValue:nil ofType:@"SMALLINT" convertsTo:value];
220 | }
221 |
222 | - (void)testSmallIntWithMinimum
223 | {
224 | id value = @(SHRT_MIN);
225 | [self testValue:value ofType:@"SMALLINT" convertsTo:value];
226 | }
227 |
228 | - (void)testSmallIntWithMaximum
229 | {
230 | id value = @(SHRT_MAX);
231 | [self testValue:value ofType:@"SMALLINT" convertsTo:value];
232 | }
233 |
234 | #pragma mark - Int
235 |
236 | - (void)testIntWithNull
237 | {
238 | id value = [NSNull null];
239 | [self testValue:nil ofType:@"INT" convertsTo:value];
240 | }
241 |
242 | - (void)testIntWithMinimum
243 | {
244 | id value = @(SHRT_MIN);
245 | [self testValue:value ofType:@"INT" convertsTo:value];
246 | }
247 |
248 | - (void)testIntWithMaximum
249 | {
250 | id value = @(SHRT_MAX);
251 | [self testValue:value ofType:@"INT" convertsTo:value];
252 | }
253 |
254 | #pragma mark - Big Int
255 |
256 | - (void)testBigIntWithNull
257 | {
258 | id value = [NSNull null];
259 | [self testValue:nil ofType:@"BIGINT" convertsTo:value];
260 | }
261 |
262 | - (void)testBigIntWithMinimum
263 | {
264 | id value = @(LLONG_MIN);
265 | [self testValue:value ofType:@"BIGINT" convertsTo:value];
266 | }
267 |
268 | - (void)testBigIntWithMaximum
269 | {
270 | id value = @(LLONG_MAX);
271 | [self testValue:value ofType:@"BIGINT" convertsTo:value];
272 | }
273 |
274 | #pragma mark - Float
275 |
276 | - (void)testFloatWithNull
277 | {
278 | id value = [NSNull null];
279 | [self testValue:nil ofType:@"FLOAT" convertsTo:value];
280 | }
281 |
282 | - (void)testFloatWithMinimum
283 | {
284 | id value = @(-1.79e+308);
285 | [self testValue:value ofType:@"FLOAT" convertsTo:value];
286 | }
287 |
288 | - (void)testFloatWithMaximum
289 | {
290 | id value = @(1.79e+308);
291 | [self testValue:value ofType:@"FLOAT" convertsTo:value];
292 | }
293 |
294 | #pragma mark - Real
295 |
296 | - (void)testRealWithNull
297 | {
298 | id value = [NSNull null];
299 | [self testValue:nil ofType:@"REAL" convertsTo:value];
300 | }
301 |
302 | - (void)testRealWithMinimum
303 | {
304 | id value = [NSNumber numberWithFloat:-3.4e+38];
305 | [self testValue:value ofType:@"REAL" convertsTo:value];
306 | }
307 |
308 | - (void)testRealWithMaximum
309 | {
310 | id value = [NSNumber numberWithFloat:3.4e+38];
311 | [self testValue:value ofType:@"REAL" convertsTo:value];
312 | }
313 |
314 | #pragma mark - Decimal
315 |
316 | - (void)testDecimalWithNull
317 | {
318 | id value = [NSNull null];
319 | [self testValue:nil ofType:@"DECIMAL" convertsTo:value];
320 | }
321 |
322 | - (void)testDecimalWithMinimum
323 | {
324 | id value = [[NSDecimalNumber decimalNumberWithMantissa:1 exponent:38 isNegative:YES] decimalNumberByAdding:[NSDecimalNumber one]];
325 | [self testValue:value ofType:@"DECIMAL(38,0)" convertsTo:value];
326 | }
327 |
328 | - (void)testDecimalWithMaximum
329 | {
330 | id value = [[NSDecimalNumber decimalNumberWithMantissa:1 exponent:38 isNegative:NO] decimalNumberBySubtracting:[NSDecimalNumber one]];
331 | [self testValue:value ofType:@"DECIMAL(38,0)" convertsTo:value];
332 | }
333 |
334 | #pragma mark - Numeric
335 |
336 | - (void)testNumericWithNull
337 | {
338 | id value = [NSNull null];
339 | [self testValue:nil ofType:@"NUMERIC" convertsTo:value];
340 | }
341 |
342 | - (void)testNumericWithMinimum
343 | {
344 | id value = [[NSDecimalNumber decimalNumberWithMantissa:1 exponent:38 isNegative:YES] decimalNumberByAdding:[NSDecimalNumber one]];
345 | [self testValue:value ofType:@"NUMERIC(38,0)" convertsTo:value];
346 | }
347 |
348 | - (void)testNumericWithMaximum
349 | {
350 | id value = [[NSDecimalNumber decimalNumberWithMantissa:1 exponent:38 isNegative:NO] decimalNumberBySubtracting:[NSDecimalNumber one]];
351 | [self testValue:value ofType:@"NUMERIC(38,0)" convertsTo:value];
352 | }
353 |
354 | #pragma mark - Small Money
355 |
356 | - (void)testSmallMoneyWithNull
357 | {
358 | id value = [NSNull null];
359 | [self testValue:nil ofType:@"SMALLMONEY" convertsTo:value];
360 | }
361 |
362 | - (void)testSmallMoneyWithMinimum
363 | {
364 | id value = [NSDecimalNumber decimalNumberWithString:@"-214748.3648"];
365 | [self testValue:value ofType:@"SMALLMONEY" convertsTo:value];
366 | }
367 |
368 | - (void)testSmallMoneyWithMaximum
369 | {
370 | id value = [NSDecimalNumber decimalNumberWithString:@"214748.3647"];
371 | [self testValue:value ofType:@"SMALLMONEY" convertsTo:value];
372 | }
373 |
374 | #pragma mark - Money
375 |
376 | - (void)testMoneyWithNull
377 | {
378 | id value = [NSNull null];
379 | [self testValue:nil ofType:@"MONEY" convertsTo:value];
380 | }
381 |
382 | - (void)testMoneyWithMinimum
383 | {
384 | //TODO: fix last 2 digits, i.e. -922337203685477.5808 returns -922337203685477.58
385 | id value = [NSDecimalNumber decimalNumberWithString:@"-922337203685477.58"];
386 | [self testValue:value ofType:@"MONEY" convertsTo:value];
387 | }
388 |
389 | - (void)testMoneyWithMaximum
390 | {
391 | //TODO: fix last 2 digits, i.e. 922337203685477.5807 returns 922337203685477.58
392 | id value = [NSDecimalNumber decimalNumberWithString:@"922337203685477.58"];
393 | [self testValue:value ofType:@"MONEY" convertsTo:value];
394 | }
395 |
396 | #pragma mark - Small DateTime
397 |
398 | - (void)testSmallDateTimeWithNull
399 | {
400 | id value = [NSNull null];
401 | [self testValue:nil ofType:@"SMALLDATETIME" convertsTo:value];
402 | }
403 |
404 | - (void)testSmallDateTimeWithMinimum
405 | {
406 | id input = @"01-01-1900 00:00:00";
407 | id output = [self dateWithYear:1900 month:1 day:1 hour:0 minute:0 second:0 nanosecond:0 timezone:0];
408 | [self testValue:input ofType:@"SMALLDATETIME" convertsTo:output];
409 | }
410 |
411 | - (void)testSmallDateTimeWithMaximum
412 | {
413 | id input = @"06-06-2079 23:59:00";
414 | id output = [self dateWithYear:2079 month:6 day:6 hour:23 minute:59 second:0 nanosecond:0 timezone:0];
415 | [self testValue:input ofType:@"SMALLDATETIME" convertsTo:output];
416 | }
417 |
418 | #pragma mark - DateTime
419 |
420 | - (void)testDateTimeWithNull
421 | {
422 | id value = [NSNull null];
423 | [self testValue:nil ofType:@"DATETIME" convertsTo:value];
424 | }
425 |
426 | - (void)testDateTimeWithMinimum
427 | {
428 | id input = @"01-01-1753 00:00:00:000";
429 | id output = [self dateWithYear:1753 month:1 day:1 hour:0 minute:0 second:0 nanosecond:0 timezone:0];
430 | [self testValue:input ofType:@"DATETIME" convertsTo:output];
431 | }
432 |
433 | - (void)testDateTimeWithMaximum
434 | {
435 | id input = @"12-31-9999 23:59:59:997";
436 | id output = [self dateWithYear:9999 month:12 day:31 hour:23 minute:59 second:59 nanosecond:997000000 timezone:0];
437 | [self testValue:input ofType:@"DATETIME" convertsTo:output];
438 | }
439 |
440 | #pragma mark - DateTime2
441 |
442 | //If these tests fail, you must tell FreeTDS to use the TDS protocol >= 7.3.
443 | //Add an environment variable to the test scheme with name TDSVER and value auto
444 |
445 | - (void)testDateTime2WithNull
446 | {
447 | id value = [NSNull null];
448 | [self testValue:nil ofType:@"DATETIME2" convertsTo:value];
449 | }
450 |
451 | - (void)testDateTime2WithMinimum
452 | {
453 | id input = @"01-01-0001 00:00:00.0000000";
454 | id output = [self dateWithYear:1 month:1 day:1 hour:0 minute:0 second:0 nanosecond:0 timezone:0];
455 | [self testValue:input ofType:@"DATETIME2" convertsTo:output];
456 | }
457 |
458 | - (void)testDateTime2WithMaximum
459 | {
460 | id input = @"12-31-9999 23:59:59.9999999";
461 | id output = [self dateWithYear:9999 month:12 day:31 hour:23 minute:59 second:59 nanosecond:999999900 timezone:0];
462 | [self testValue:input ofType:@"DATETIME2" convertsTo:output];
463 | }
464 |
465 | #pragma mark - DateTimeOffset
466 |
467 | //If these tests fail, you must tell FreeTDS to use the TDS protocol >= 7.3.
468 | //Add an environment variable to the test scheme with name TDSVER and value auto
469 |
470 | - (void)testDateTimeOffsetWithNull
471 | {
472 | id value = [NSNull null];
473 | [self testValue:nil ofType:@"DATETIMEOFFSET" convertsTo:value];
474 | }
475 |
476 | - (void)testDateTimeOffsetWithMinimum
477 | {
478 | id input = @"01-01-0001 00:00:00.0000000 -14:00";
479 | id output = [self dateWithYear:1 month:1 day:1 hour:0 minute:0 second:0 nanosecond:0 timezone:-840];
480 | [self testValue:input ofType:@"DATETIMEOFFSET" convertsTo:output];
481 | }
482 |
483 | - (void)testDateTimeOffsetWithMaximum
484 | {
485 | id input = @"12-31-9999 23:59:59.9999999 +14:00";
486 | id output = [self dateWithYear:9999 month:12 day:31 hour:23 minute:59 second:59 nanosecond:999999900 timezone:840];
487 | [self testValue:input ofType:@"DATETIMEOFFSET" convertsTo:output];
488 | }
489 |
490 | #pragma mark - Date
491 |
492 | //If these tests fail, you must tell FreeTDS to use the TDS protocol >= 7.3.
493 | //Add an environment variable to the test scheme with name TDSVER and value auto
494 |
495 | - (void)testDateWithNull
496 | {
497 | id value = [NSNull null];
498 | [self testValue:nil ofType:@"DATE" convertsTo:value];
499 | }
500 |
501 | - (void)testDateWithMinimum
502 | {
503 | id input = @"01-01-0001";
504 | id output = [self dateWithYear:1 month:1 day:1 hour:0 minute:0 second:0 nanosecond:0 timezone:0];
505 | [self testValue:input ofType:@"DATE" convertsTo:output];
506 | }
507 |
508 | - (void)testDateWithMaximum
509 | {
510 | id input = @"12-31-9999";
511 | id output = [self dateWithYear:9999 month:12 day:31 hour:0 minute:0 second:0 nanosecond:0 timezone:0];
512 | [self testValue:input ofType:@"DATE" convertsTo:output];
513 | }
514 |
515 | #pragma mark - Time
516 |
517 | //If these tests fail, you must tell FreeTDS to use the TDS protocol >= 7.3.
518 | //Add an environment variable to the test scheme with name TDSVER and value auto
519 |
520 | - (void)testTimeWithNull
521 | {
522 | id value = [NSNull null];
523 | [self testValue:nil ofType:@"TIME" convertsTo:value];
524 | }
525 |
526 | - (void)testTimeWithMinimum
527 | {
528 | id input = @"00:00:00.0000000";
529 | id output = [self dateWithYear:1900 month:1 day:1 hour:0 minute:0 second:0 nanosecond:0 timezone:0];
530 | [self testValue:input ofType:@"TIME" convertsTo:output];
531 | }
532 |
533 | - (void)testTimeWithMaximum
534 | {
535 | id input = @"23:59:59.9999999";
536 | id output = [self dateWithYear:1900 month:1 day:1 hour:23 minute:59 second:59 nanosecond:999999900 timezone:0];
537 | [self testValue:input ofType:@"TIME" convertsTo:output];
538 | }
539 |
540 | #pragma mark - Char
541 |
542 | - (void)testCharWithNull
543 | {
544 | id value = [NSNull null];
545 | [self testValue:nil ofType:@"CHAR(1)" convertsTo:value];
546 | }
547 |
548 | - (void)testCharWithMinimum
549 | {
550 | //TODO: Fix (32 doesn't work)
551 | //33 = minimum ASCII value
552 | id value = [NSString stringWithFormat:@"%c", 33];
553 | [self testValue:value ofType:@"CHAR(1)" convertsTo:value];
554 | }
555 |
556 | - (void)testCharWithMaximum
557 | {
558 | //127 = maximum printable ASCII value
559 | id value = [NSString stringWithFormat:@"%c", 127];
560 | [self testValue:value ofType:@"CHAR(1)" convertsTo:value];
561 | }
562 |
563 | #pragma mark - VarChar(Max)
564 |
565 | - (void)testVarCharMaxWithNull
566 | {
567 | id value = [NSNull null];
568 | [self testValue:nil ofType:@"VARCHAR(MAX)" convertsTo:value];
569 | }
570 |
571 | - (void)testVarCharMaxWithMinimum
572 | {
573 | //TODO: Fix (32 doesn't work)
574 | //33 = minimum ASCII value
575 | id value = [NSString stringWithFormat:@"%c", 33];
576 | [self testValue:value ofType:@"VARCHAR(MAX)" convertsTo:value];
577 | }
578 |
579 | - (void)testVarCharMaxWithMaximum
580 | {
581 | id input = [self stringWithLength:[SQLClient sharedInstance].maxTextSize + 1];
582 | id output = [input substringToIndex:[SQLClient sharedInstance].maxTextSize - 1];
583 | [self testValue:input ofType:@"VARCHAR(MAX)" convertsTo:output];
584 | }
585 |
586 | #pragma mark - Text
587 |
588 | - (void)testTextWithNull
589 | {
590 | id value = [NSNull null];
591 | [self testValue:nil ofType:@"TEXT" convertsTo:value];
592 | }
593 |
594 | - (void)testTextWithMinimum
595 | {
596 | //TODO: Fix (32 doesn't work)
597 | //33 = minimum ASCII value
598 | id value = [NSString stringWithFormat:@"%c", 33];
599 | [self testValue:value ofType:@"TEXT" convertsTo:value];
600 | }
601 |
602 | - (void)testTextWithMaximum
603 | {
604 | id input = [self stringWithLength:[SQLClient sharedInstance].maxTextSize + 1];
605 | id output = [input substringToIndex:[SQLClient sharedInstance].maxTextSize - 1];
606 | [self testValue:input ofType:@"TEXT" convertsTo:output];
607 | }
608 |
609 | #pragma mark - UniqueIdentifier
610 |
611 | - (void)testUniqueIdentifierWithNull
612 | {
613 | id value = [NSNull null];
614 | [self testValue:nil ofType:@"UNIQUEIDENTIFIER" convertsTo:value];
615 | }
616 |
617 | - (void)testUniqueIdentifierWithValue
618 | {
619 | id output = [NSUUID UUID];
620 | id input = [output UUIDString];
621 | [self testValue:input ofType:@"UNIQUEIDENTIFIER" convertsTo:output];
622 | }
623 |
624 | #pragma mark - Binary
625 |
626 | - (void)testBinaryWithNull
627 | {
628 | id value = [NSNull null];
629 | [self testBinaryValue:nil ofType:@"BINARY" convertsTo:value withStyle:1];
630 | }
631 |
632 | - (void)testBinaryWithValue
633 | {
634 | NSString* string = [self stringWithLength:30];
635 | NSData* output = [string dataUsingEncoding:NSASCIIStringEncoding];
636 | NSString* input = [self hexStringWithData:output];
637 | [self testBinaryValue:input ofType:@"BINARY" convertsTo:output withStyle:1];
638 | }
639 |
640 | #pragma mark - VarBinary
641 |
642 | - (void)testVarBinaryWithNull
643 | {
644 | id value = [NSNull null];
645 | [self testBinaryValue:nil ofType:@"VARBINARY" convertsTo:value withStyle:1];
646 | }
647 |
648 | - (void)testVarBinaryWithValue
649 | {
650 | NSString* string = [self stringWithLength:30];
651 | NSData* output = [string dataUsingEncoding:NSASCIIStringEncoding];
652 | NSString* input = [self hexStringWithData:output];
653 | [self testBinaryValue:input ofType:@"VARBINARY" convertsTo:output withStyle:1];
654 | }
655 |
656 | #pragma mark - Private
657 |
658 | - (void)testValue:(id)input ofType:(NSString*)type convertsTo:(id)output
659 | {
660 | NSString* sql;
661 | if (input) {
662 | sql = [NSString stringWithFormat:@"SELECT CAST('%@' AS %@) AS Value", input, type];
663 | } else {
664 | sql = [NSString stringWithFormat:@"SELECT CAST(NULL AS %@) AS Value", type];
665 | }
666 |
667 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
668 | [self execute:sql completion:^(NSArray* results) {
669 | XCTAssertEqualObjects(results[0][0][@"Value"], output);
670 | [expectation fulfill];
671 | }];
672 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
673 | }
674 |
675 | - (void)testBinaryValue:(id)input ofType:(NSString*)type convertsTo:(id)output withStyle:(int)style
676 | {
677 | NSString* sql;
678 | if (input) {
679 | sql = [NSString stringWithFormat:@"SELECT CONVERT(%@, '%@', %d) AS Value", type, input, style];
680 | } else {
681 | sql = [NSString stringWithFormat:@"SELECT CONVERT(%@, NULL, %d) AS Value", type, style];
682 | }
683 |
684 | XCTestExpectation* expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
685 | [self execute:sql completion:^(NSArray* results) {
686 | XCTAssertEqualObjects(results[0][0][@"Value"], output);
687 | [expectation fulfill];
688 | }];
689 | [self waitForExpectationsWithTimeout:[SQLClient sharedInstance].timeout handler:nil];
690 | }
691 |
692 | - (void)execute:(NSString*)sql completion:(void (^)(NSArray* results))completion
693 | {
694 | //Environment variables from the Test Debug Scheme
695 | NSDictionary* environment = [[NSProcessInfo processInfo] environment];
696 | NSString* host = environment[@"HOST"];
697 | NSString* username = environment[@"USERNAME"];
698 | NSString* password = environment[@"PASSWORD"];
699 | NSString* database = environment[@"DATABASE"];
700 |
701 | NSParameterAssert(host);
702 | NSParameterAssert(username);
703 | NSParameterAssert(password);
704 |
705 | SQLClient* client = [SQLClient sharedInstance];
706 | [client connect:host username:username password:password database:database completion:^(BOOL success) {
707 | [client execute:sql completion:^(NSArray* results) {
708 | [client disconnect];
709 | if (completion) {
710 | completion(results);
711 | }
712 | }];
713 | }];
714 | }
715 |
716 | - (NSDate*)dateWithYear:(int)year month:(int)month day:(int)day hour:(int)hour minute:(int)minute second:(int)second nanosecond:(int)nanosecond timezone:(int)timezone
717 | {
718 | NSCalendar* calendar = [NSCalendar currentCalendar];
719 | NSDateComponents* dateComponents = [[NSDateComponents alloc] init];
720 | dateComponents.year = year;
721 | dateComponents.month = month;
722 | dateComponents.day = day;
723 | dateComponents.hour = hour;
724 | dateComponents.minute = minute;
725 | dateComponents.second = second;
726 | dateComponents.nanosecond = nanosecond;
727 | dateComponents.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:timezone * 60];
728 | return [calendar dateFromComponents:dateComponents];
729 | }
730 |
731 | - (NSString*)stringWithLength:(NSUInteger)length
732 | {
733 | NSMutableString* output = [NSMutableString string];
734 | for (NSUInteger i = 0; i < length; i++) {
735 | //65-122 == alphanumeric ASCII values
736 | char character = arc4random_uniform(65) + 57;
737 | [output appendString:[NSString stringWithFormat:@"%c", character]];
738 | }
739 | //Sanitize
740 | return [output stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
741 | }
742 |
743 | - (NSString*)hexStringWithData:(NSData*)data
744 | {
745 | const unsigned char* dataBuffer = (const unsigned char*)[data bytes];
746 | if (!dataBuffer) {
747 | return [NSString string];
748 | }
749 |
750 | NSMutableString* output = [NSMutableString stringWithCapacity:(data.length * 2)];
751 | for (int i = 0; i < data.length; ++i) {
752 | [output appendString:[NSString stringWithFormat:@"%02lx", (unsigned long)dataBuffer[i]]];
753 | }
754 | return [NSString stringWithFormat:@"0x%@", output];
755 | }
756 |
757 | @end
758 |
--------------------------------------------------------------------------------
/SQLClient/SQLClientTests/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------