├── Sequel Pro
├── en.lproj
│ ├── InfoPlist.strings
│ ├── NTMasterViewController.xib
│ └── NTDetailViewController.xib
├── Frameworks
│ └── SPMySQLFramework
│ │ ├── English.lproj
│ │ └── InfoPlist.strings
│ │ ├── MySQL Client Libraries
│ │ ├── lib
│ │ │ └── libmysqlclient.a
│ │ └── include
│ │ │ ├── mysql_version.h
│ │ │ ├── my_list.h
│ │ │ ├── my_alloc.h
│ │ │ ├── mysql_time.h
│ │ │ └── typelib.h
│ │ ├── SPMySQLFramework
│ │ ├── SPMySQLFramework-Prefix.pch
│ │ ├── SPMySQLFramework.m
│ │ └── SPMySQLFramework.h
│ │ ├── SPMySQLFrameworkIOS
│ │ ├── SPMySQLFrameworkIOS-Prefix.pch
│ │ ├── SPMySQLFrameworkIOS.m
│ │ └── SPMySQLFrameworkIOS.h
│ │ ├── Source
│ │ ├── SPMySQLFramework_Prefix.pch
│ │ ├── SPMySQLConnection Categories
│ │ │ ├── Copying.h
│ │ │ ├── Locking.h
│ │ │ ├── Max Packet Size.h
│ │ │ ├── Delegate & Proxy.h
│ │ │ ├── Databases & Tables.h
│ │ │ ├── Server Info.h
│ │ │ ├── Encoding.h
│ │ │ ├── Ping & KeepAlive.h
│ │ │ ├── Conversion.h
│ │ │ ├── Copying.m
│ │ │ ├── Locking.m
│ │ │ ├── Conversion.m
│ │ │ ├── Querying & Preparation.h
│ │ │ ├── Delegate & Proxy.m
│ │ │ ├── Server Info.m
│ │ │ ├── Max Packet Size.m
│ │ │ ├── Ping & KeepAlive.m
│ │ │ └── Databases & Tables.m
│ │ ├── SPMySQLResult Categories
│ │ │ ├── Convenience Methods.h
│ │ │ ├── Field Definitions.h
│ │ │ └── Convenience Methods.m
│ │ ├── SPMySQLStringAdditions.h
│ │ ├── SPMySQLKeepAliveTimer.h
│ │ ├── SPMySQLFastStreamingResult.h
│ │ ├── SPMySQLUtilities.h
│ │ ├── SPMySQLGeometryData.h
│ │ ├── SPMySQLStreamingResult.h
│ │ ├── SPMySQLStringAdditions.m
│ │ ├── SPMySQLArrayAdditions.h
│ │ ├── SPMySQLConnectionProxy.h
│ │ ├── SPMySQL.h
│ │ ├── SPMySQLConstants.h
│ │ ├── SPMySQLKeepAliveTimer.m
│ │ ├── SPMySQL Private APIs.h
│ │ ├── SPMySQLConnectionDelegate.h
│ │ ├── SPMySQLResult.h
│ │ ├── SPMySQLConnection.h
│ │ ├── SPMySQLStreamingResult.m
│ │ └── SPMySQLFastStreamingResult.m
│ │ ├── Resources
│ │ └── Info.plist
│ │ ├── SPMySQLFramework.xcodeproj
│ │ └── xcuserdata
│ │ │ └── matt.xcuserdatad
│ │ │ └── xcschemes
│ │ │ ├── xcschememanagement.plist
│ │ │ ├── SPMySQL.framework.xcscheme
│ │ │ └── SPMySQLFramework.xcscheme
│ │ ├── Readme.txt
│ │ └── build-mysql-client.sh
├── Sequel Pro-Prefix.pch
├── main.m
├── NTAppDelegate.h
├── NTMasterViewController.h
├── NTDetailViewController.h
├── Sequel Pro-Info.plist
├── NTDetailViewController.m
├── NTAppDelegate.m
└── NTMasterViewController.m
├── README
└── Sequel Pro.xcodeproj
├── project.xcworkspace
├── contents.xcworkspacedata
└── xcuserdata
│ └── matt.xcuserdatad
│ ├── UserInterfaceState.xcuserstate
│ └── WorkspaceSettings.xcsettings
└── xcuserdata
└── matt.xcuserdatad
└── xcschemes
├── xcschememanagement.plist
└── Sequel Pro.xcscheme
/Sequel Pro/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/English.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Experimental iOS project for getting MySQL and SPMySQLFramework (as used in Sequel Pro) compiling. N.B - SPMySQLFramework isn't currently compiling on iOS.
2 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/MySQL Client Libraries/lib/libmysqlclient.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattlangtree/SPMySQLFramework-iOS/master/Sequel Pro/Frameworks/SPMySQLFramework/MySQL Client Libraries/lib/libmysqlclient.a
--------------------------------------------------------------------------------
/Sequel Pro.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Sequel Pro.xcodeproj/project.xcworkspace/xcuserdata/matt.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mattlangtree/SPMySQLFramework-iOS/master/Sequel Pro.xcodeproj/project.xcworkspace/xcuserdata/matt.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFramework/SPMySQLFramework-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'SPMySQLFramework' target in the 'SPMySQLFramework' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFrameworkIOS/SPMySQLFrameworkIOS-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'SPMySQLFrameworkIOS' target in the 'SPMySQLFrameworkIOS' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFramework/SPMySQLFramework.m:
--------------------------------------------------------------------------------
1 | //
2 | // SPMySQLFramework.m
3 | // SPMySQLFramework
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | //
7 | //
8 |
9 | #import "SPMySQLFramework.h"
10 |
11 | @implementation SPMySQLFramework
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFramework/SPMySQLFramework.h:
--------------------------------------------------------------------------------
1 | //
2 | // SPMySQLFramework.h
3 | // SPMySQLFramework
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | //
7 | //
8 |
9 | #import
10 |
11 | @interface SPMySQLFramework : NSObject
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFrameworkIOS/SPMySQLFrameworkIOS.m:
--------------------------------------------------------------------------------
1 | //
2 | // SPMySQLFrameworkIOS.m
3 | // SPMySQLFrameworkIOS
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | //
7 | //
8 |
9 | #import "SPMySQLFrameworkIOS.h"
10 |
11 | @implementation SPMySQLFrameworkIOS
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFrameworkIOS/SPMySQLFrameworkIOS.h:
--------------------------------------------------------------------------------
1 | //
2 | // SPMySQLFrameworkIOS.h
3 | // SPMySQLFrameworkIOS
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | //
7 | //
8 |
9 | #import
10 |
11 | @interface SPMySQLFrameworkIOS : NSObject
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLFramework_Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'SPMySQLFramework' target in the 'SPMySQLFramework' project.
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
9 | #import "mysql.h"
10 | #import "SPMySQL.h"
11 | #import "SPMySQLUtilities.h"
--------------------------------------------------------------------------------
/Sequel Pro/Sequel Pro-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'Sequel Pro' target in the 'Sequel Pro' project
3 | //
4 |
5 | #import
6 |
7 | #ifndef __IPHONE_4_0
8 | #warning "This project uses features only available in iOS SDK 4.0 and later."
9 | #endif
10 |
11 | #ifdef __OBJC__
12 | #import
13 | #import
14 | #endif
15 |
--------------------------------------------------------------------------------
/Sequel Pro/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Sequel Pro
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | // Copyright (c) 2012 North of Three. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "NTAppDelegate.h"
12 |
13 | int main(int argc, char *argv[])
14 | {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([NTAppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Sequel Pro/NTAppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // NTAppDelegate.h
3 | // Sequel Pro
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | // Copyright (c) 2012 North of Three. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NTAppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 | @property (strong, nonatomic) UISplitViewController *splitViewController;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/Sequel Pro/NTMasterViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // NTMasterViewController.h
3 | // Sequel Pro
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | // Copyright (c) 2012 North of Three. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class NTDetailViewController;
12 |
13 | @interface NTMasterViewController : UITableViewController
14 |
15 | @property (strong, nonatomic) NTDetailViewController *detailViewController;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/Sequel Pro.xcodeproj/project.xcworkspace/xcuserdata/matt.xcuserdatad/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges
6 |
7 | SnapshotAutomaticallyBeforeSignificantChanges
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Sequel Pro/NTDetailViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // NTDetailViewController.h
3 | // Sequel Pro
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | // Copyright (c) 2012 North of Three. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NTDetailViewController : UIViewController
12 |
13 | @property (strong, nonatomic) id detailItem;
14 |
15 | @property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/Sequel Pro.xcodeproj/xcuserdata/matt.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Sequel Pro.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | C9589BB9158DB6A400467F7C
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Resources/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | SPMySQL
9 | CFBundleIdentifier
10 | com.sequelpro.spmysql
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | FMWK
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | SPDT
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/MySQL Client Libraries/include/mysql_version.h:
--------------------------------------------------------------------------------
1 | /* Copyright Abandoned 1996, 1999, 2001 MySQL AB
2 | This file is public domain and comes with NO WARRANTY of any kind */
3 |
4 | /* Version numbers for protocol & mysqld */
5 |
6 | #ifndef _mysql_version_h
7 | #define _mysql_version_h
8 | #ifdef _CUSTOMCONFIG_
9 | #include
10 | #else
11 | #define PROTOCOL_VERSION 10
12 | #define MYSQL_SERVER_VERSION "5.5.22"
13 | #define MYSQL_BASE_VERSION "mysqld-5.5"
14 | #define MYSQL_SERVER_SUFFIX_DEF ""
15 | #define FRM_VER 6
16 | #define MYSQL_VERSION_ID 50522
17 | #define MYSQL_PORT 3306
18 | #define MYSQL_PORT_DEFAULT 0
19 | #define MYSQL_UNIX_ADDR "/tmp/mysql.sock"
20 | #define MYSQL_CONFIG_NAME "my"
21 | #define MYSQL_COMPILATION_COMMENT "MySQL Community Server (GPL)"
22 |
23 | /* mysqld compile time options */
24 | #endif /* _CUSTOMCONFIG_ */
25 |
26 | #ifndef LICENSE
27 | #define LICENSE GPL
28 | #endif /* LICENSE */
29 |
30 | #endif /* _mysql_version_h */
31 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFramework.xcodeproj/xcuserdata/matt.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | SPMySQL.framework.xcscheme
8 |
9 | orderHint
10 | 1
11 |
12 | SPMySQLFramework.xcscheme
13 |
14 | orderHint
15 | 2
16 |
17 |
18 | SuppressBuildableAutocreation
19 |
20 | 8DC2EF4F0486A6940098B216
21 |
22 | primary
23 |
24 |
25 | C9589C49158DB71000467F7C
26 |
27 | primary
28 |
29 |
30 | C9589C5C158DB73D00467F7C
31 |
32 | primary
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Copying.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Copying.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Copying.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on March 8, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLConnection (Copying)
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/Sequel Pro/Sequel Pro-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIdentifier
12 | com.northofthree.${PRODUCT_NAME:rfc1034identifier}
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 | 1.0
25 | LSRequiresIPhoneOS
26 |
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Convenience Methods.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Convenience Methods.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Convenience Methods.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 20, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLResult (Convenience_Methods)
35 |
36 | - (NSArray *)getAllRows;
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Field Definitions.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Field Definitions.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Field Definitions.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 2, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLResult (Field_Definitions)
35 |
36 | - (NSArray *)fieldDefinitions;
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/MySQL Client Libraries/include/my_list.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2 |
3 | This program is free software; you can redistribute it and/or modify
4 | it under the terms of the GNU General Public License as published by
5 | the Free Software Foundation; version 2 of the License.
6 |
7 | This program is distributed in the hope that it will be useful,
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | GNU General Public License for more details.
11 |
12 | You should have received a copy of the GNU General Public License
13 | along with this program; if not, write to the Free Software
14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 |
16 | #ifndef _list_h_
17 | #define _list_h_
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif
22 |
23 | typedef struct st_list {
24 | struct st_list *prev,*next;
25 | void *data;
26 | } LIST;
27 |
28 | typedef int (*list_walk_action)(void *,void *);
29 |
30 | extern LIST *list_add(LIST *root,LIST *element);
31 | extern LIST *list_delete(LIST *root,LIST *element);
32 | extern LIST *list_cons(void *data,LIST *root);
33 | extern LIST *list_reverse(LIST *root);
34 | extern void list_free(LIST *root,unsigned int free_data);
35 | extern unsigned int list_length(LIST *);
36 | extern int list_walk(LIST *,list_walk_action action,unsigned char * argument);
37 |
38 | #define list_rest(a) ((a)->next)
39 | #define list_push(a,b) (a)=list_cons((b),(a))
40 | #define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old); my_free(old); }
41 |
42 | #ifdef __cplusplus
43 | }
44 | #endif
45 | #endif
46 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLStringAdditions.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLStringAdditions.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 8, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface NSString (SPMySQLStringAdditions)
35 |
36 | - (NSString *)mySQLBacktickQuotedString;
37 | - (NSString *)mySQLTickQuotedString;
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Locking.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Locking.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Locking.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 22, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | // This class is private to the framework.
34 |
35 | @interface SPMySQLConnection (Locking)
36 |
37 | - (void)_lockConnection;
38 | - (BOOL)_tryLockConnection;
39 | - (void)_unlockConnection;
40 |
41 | @end
42 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Max Packet Size.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Max Packet Size.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Max Packet Size.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 9, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLConnection (Max_Packet_Size)
35 |
36 | - (NSUInteger)maxQuerySize;
37 | - (BOOL)isMaxQuerySizeEditable;
38 | - (NSUInteger)setGlobalMaxQuerySize:(NSUInteger)newMaxSize;
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLKeepAliveTimer.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLKeepAliveTimer.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on March 5, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLKeepAliveTimer : NSObject {
35 | id timerTarget;
36 | SEL timerSelector;
37 | NSTimeInterval timerRepeatInterval;
38 |
39 | NSTimer *wrappedTimer;
40 | }
41 |
42 | - (id)initWithInterval:(NSTimeInterval)anInterval target:(id)aTarget selector:(SEL)aSelector;
43 | - (void)invalidate;
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Delegate & Proxy.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Delegate & Proxy.h 3563 2012-03-29 23:55:09Z rowanb@gmail.com $
3 | //
4 | // Delegate & Proxy.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 9, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLConnection (Delegate_and_Proxy)
35 |
36 | // Connection delegage
37 | - (void)setDelegate:(NSObject *)aDelegate;
38 | - (NSObject *)delegate;
39 |
40 | // Connection proxy
41 | - (void)setProxy:(NSObject *)aProxy;
42 | - (NSObject *)proxy;
43 |
44 | @end
45 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLFastStreamingResult.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLFastStreamingResult.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLFastStreamingResult.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 2, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLFastStreamingResult : SPMySQLStreamingResult {
35 |
36 | // Linked list setup
37 | struct st_spmysqlstreamingrowdata *currentDataStoreEntry;
38 | struct st_spmysqlstreamingrowdata *lastDataStoreEntry;
39 |
40 | // Additional counts and memory length tracking
41 | NSUInteger processedRowCount;
42 |
43 | // Thread safety
44 | pthread_mutex_t dataLock;
45 | }
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLUtilities.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLUtilities.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Locking.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 6, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #include
34 |
35 | /**
36 | * Define a project function to make it easier to use mach_absolute_time()
37 | * to track monotonically increasing time.
38 | */
39 | static double _elapsedSecondsSinceAbsoluteTime(uint64_t comparisonTime)
40 | {
41 | uint64_t elapsedTime_t = mach_absolute_time() - comparisonTime;
42 | Nanoseconds elapsedTime = AbsoluteToNanoseconds(*(AbsoluteTime *)&(elapsedTime_t));
43 |
44 | return (((double)UnsignedWideToUInt64(elapsedTime)) * 1e-9);
45 | }
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLGeometryData.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLGeometryData.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLGeometryData.h
5 | // sequel-pro
6 | //
7 | // Created by Hans-Jörg Bibiko on October 07, 2010
8 | //
9 | // Permission is hereby granted, free of charge, to any person
10 | // obtaining a copy of this software and associated documentation
11 | // files (the "Software"), to deal in the Software without
12 | // restriction, including without limitation the rights to use,
13 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | // copies of the Software, and to permit persons to whom the
15 | // Software is furnished to do so, subject to the following
16 | // conditions:
17 | //
18 | // The above copyright notice and this permission notice shall be
19 | // included in all copies or substantial portions of the Software.
20 | //
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 | // OTHER DEALINGS IN THE SOFTWARE.
29 | //
30 | // More info at
31 |
32 |
33 | @interface SPMySQLGeometryData : NSObject
34 | {
35 | // Holds the WKB bytes coming from SQL server
36 | Byte *geoBuffer;
37 |
38 | // Holds the buffer length
39 | NSUInteger bufferLength;
40 |
41 | }
42 |
43 | - (id)initWithBytes:(const void *)geoData length:(NSUInteger)length;
44 | + (id)dataWithBytes:(const void *)geoData length:(NSUInteger)length;
45 | - (NSString *)description;
46 | - (NSUInteger)length;
47 | - (NSData *)data;
48 | - (NSString *)wktString;
49 | - (NSDictionary *)coordinates;
50 | - (NSInteger)wkbType;
51 | - (NSString *)wktType;
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Databases & Tables.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Databases & Tables.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Databases & Tables.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 11, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLConnection (Databases_and_Tables)
35 |
36 | // Database selection
37 | - (BOOL)selectDatabase:(NSString *)aDatabase;
38 |
39 | // Database lists
40 | - (NSArray *)databases;
41 | - (NSArray *)databasesLike:(NSString *)nameLikeString;
42 |
43 | // Table lists
44 | - (NSArray *)tables;
45 | - (NSArray *)tablesLike:(NSString *)nameLikeString;
46 | - (NSArray *)tablesFromDatabase:(NSString *)aDatabase;
47 | - (NSArray *)tablesLike:(NSString *)nameLikeString fromDatabase:(NSString *)aDatabase;
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Server Info.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Server Info.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 14, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | @class SPMySQLResult;
34 |
35 | @interface SPMySQLConnection (Server_Info)
36 |
37 | // Server version information
38 | - (NSString *)serverVersionString;
39 | - (NSUInteger)serverMajorVersion;
40 | - (NSUInteger)serverMinorVersion;
41 | - (NSUInteger)serverReleaseVersion;
42 |
43 | // Server version comparisons
44 | - (BOOL)serverVersionIsGreaterThanOrEqualTo:(NSUInteger)aMajorVersion minorVersion:(NSUInteger)aMinorVersion releaseVersion:(NSUInteger)aReleaseVersion;
45 |
46 | // Server tasks & processes
47 | - (SPMySQLResult *)listProcesses;
48 | - (BOOL)killQueryOnThreadID:(unsigned long)theThreadID;
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/MySQL Client Libraries/include/my_alloc.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2 |
3 | This program is free software; you can redistribute it and/or modify
4 | it under the terms of the GNU General Public License as published by
5 | the Free Software Foundation; version 2 of the License.
6 |
7 | This program is distributed in the hope that it will be useful,
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | GNU General Public License for more details.
11 |
12 | You should have received a copy of the GNU General Public License
13 | along with this program; if not, write to the Free Software
14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 |
16 | /*
17 | Data structures for mysys/my_alloc.c (root memory allocator)
18 | */
19 |
20 | #ifndef _my_alloc_h
21 | #define _my_alloc_h
22 |
23 | #define ALLOC_MAX_BLOCK_TO_DROP 4096
24 | #define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP 10
25 |
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 |
30 | typedef struct st_used_mem
31 | { /* struct for once_alloc (block) */
32 | struct st_used_mem *next; /* Next block in use */
33 | unsigned int left; /* memory left in block */
34 | unsigned int size; /* size of block */
35 | } USED_MEM;
36 |
37 |
38 | typedef struct st_mem_root
39 | {
40 | USED_MEM *free; /* blocks with free memory in it */
41 | USED_MEM *used; /* blocks almost without free memory */
42 | USED_MEM *pre_alloc; /* preallocated block */
43 | /* if block have less memory it will be put in 'used' list */
44 | size_t min_malloc;
45 | size_t block_size; /* initial block size */
46 | unsigned int block_num; /* allocated blocks counter */
47 | /*
48 | first free block in queue test counter (if it exceed
49 | MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)
50 | */
51 | unsigned int first_block_usage;
52 |
53 | void (*error_handler)(void);
54 | } MEM_ROOT;
55 |
56 | #ifdef __cplusplus
57 | }
58 | #endif
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLStreamingResult.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLStreamingResult.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 18, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | @interface SPMySQLStreamingResult : SPMySQLResult {
34 |
35 | // Keep a link to the parent connection for locking purposes
36 | SPMySQLConnection *parentConnection;
37 |
38 | // Streaming result information and tracking
39 | BOOL connectionUnlocked;
40 | BOOL dataDownloaded;
41 |
42 | // Counts and memory length tracking
43 | NSUInteger downloadedRowCount;
44 |
45 | IMP isConnectedPtr;
46 | SEL isConnectedSelector;
47 | }
48 |
49 | - (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection;
50 |
51 | // Allow result fetching to be cancelled
52 | - (void)cancelResultLoad;
53 |
54 | @end
55 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Encoding.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Encoding.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Encoding.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 14, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLConnection (Encoding)
35 |
36 | // Current connection encoding information
37 | - (NSString *)encoding;
38 | - (NSStringEncoding)stringEncoding;
39 | - (BOOL)encodingUsesLatin1Transport;
40 |
41 | // Setting connection encoding
42 | - (BOOL)setEncoding:(NSString *)theEncoding;
43 | - (BOOL)setEncodingUsesLatin1Transport:(BOOL)useLatin1;
44 |
45 | // Encoding storage and restoration
46 | - (void)storeEncodingForRestoration;
47 | - (void)restoreStoredEncoding;
48 |
49 | // Encoding conversion
50 | + (NSStringEncoding)stringEncodingForMySQLCharset:(const char *)mysqlCharset;
51 | + (NSString *)mySQLCharsetForStringEncoding:(NSStringEncoding)aStringEncoding;
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Ping & KeepAlive.h 3658 2012-05-15 23:40:08Z rowanb@gmail.com $
3 | //
4 | // Ping & KeepAlive.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 14, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | // This class is private to the framework.
34 |
35 | typedef struct {
36 | MYSQL *mySQLConnection;
37 | BOOL *keepAlivePingActivePointer;
38 | BOOL *keepAliveLastPingSuccessPointer;
39 | } SPMySQLConnectionPingDetails;
40 |
41 | @interface SPMySQLConnection (Ping_and_KeepAlive)
42 |
43 | // Keepalive ping initialisation
44 | - (void)_keepAlive;
45 | - (void)_threadedKeepAlive;
46 |
47 | // Master ping method
48 | - (BOOL)_pingConnectionUsingLoopDelay:(NSUInteger)loopDelay;
49 |
50 | // Ping thread internals
51 | void _backgroundPingTask(void *ptr);
52 | void _forceThreadExit(int signalNumber);
53 | void _pingThreadCleanup(void *pingDetails);
54 |
55 | // Cancellation
56 | - (void)_cancelKeepAlives;
57 |
58 | @end
59 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/MySQL Client Libraries/include/mysql_time.h:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 2004 MySQL AB
2 |
3 | This program is free software; you can redistribute it and/or modify
4 | it under the terms of the GNU General Public License as published by
5 | the Free Software Foundation; version 2 of the License.
6 |
7 | This program is distributed in the hope that it will be useful,
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | GNU General Public License for more details.
11 |
12 | You should have received a copy of the GNU General Public License
13 | along with this program; if not, write to the Free Software
14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15 |
16 | #ifndef _mysql_time_h_
17 | #define _mysql_time_h_
18 |
19 | /*
20 | Time declarations shared between the server and client API:
21 | you should not add anything to this header unless it's used
22 | (and hence should be visible) in mysql.h.
23 | If you're looking for a place to add new time-related declaration,
24 | it's most likely my_time.h. See also "C API Handling of Date
25 | and Time Values" chapter in documentation.
26 | */
27 |
28 | enum enum_mysql_timestamp_type
29 | {
30 | MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1,
31 | MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2
32 | };
33 |
34 |
35 | /*
36 | Structure which is used to represent datetime values inside MySQL.
37 |
38 | We assume that values in this structure are normalized, i.e. year <= 9999,
39 | month <= 12, day <= 31, hour <= 23, hour <= 59, hour <= 59. Many functions
40 | in server such as my_system_gmt_sec() or make_time() family of functions
41 | rely on this (actually now usage of make_*() family relies on a bit weaker
42 | restriction). Also functions that produce MYSQL_TIME as result ensure this.
43 | There is one exception to this rule though if this structure holds time
44 | value (time_type == MYSQL_TIMESTAMP_TIME) days and hour member can hold
45 | bigger values.
46 | */
47 | typedef struct st_mysql_time
48 | {
49 | unsigned int year, month, day, hour, minute, second;
50 | unsigned long second_part;
51 | my_bool neg;
52 | enum enum_mysql_timestamp_type time_type;
53 | } MYSQL_TIME;
54 |
55 | #endif /* _mysql_time_h_ */
56 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFramework.xcodeproj/xcuserdata/matt.xcuserdatad/xcschemes/SPMySQL.framework.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
42 |
43 |
44 |
45 |
51 |
52 |
54 |
55 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/SPMySQLFramework.xcodeproj/xcuserdata/matt.xcuserdatad/xcschemes/SPMySQLFramework.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
42 |
43 |
44 |
45 |
51 |
52 |
54 |
55 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLStringAdditions.m 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLStringAdditions.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 8, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #import "SPMySQLStringAdditions.h"
34 |
35 | @implementation NSString (SPMySQLStringAdditions)
36 |
37 | /**
38 | * Returns the string quoted with backticks as required for MySQL identifiers
39 | * eg.: tablename => `tablename`
40 | * my`table => `my``table`
41 | */
42 | - (NSString *)mySQLBacktickQuotedString
43 | {
44 | return [NSString stringWithFormat: @"`%@`", [self stringByReplacingOccurrencesOfString:@"`" withString:@"``"]];
45 | }
46 |
47 | /**
48 | * Returns the string quoted with ticks as required for MySQL identifiers
49 | * eg.: tablename => 'tablename'
50 | * my'table => 'my''table'
51 | */
52 | - (NSString *)mySQLTickQuotedString
53 | {
54 | return [NSString stringWithFormat: @"'%@'", [self stringByReplacingOccurrencesOfString:@"'" withString:@"''"]];
55 | }
56 |
57 | @end
58 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLArrayAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLArrayAdditions.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLArrayAdditions.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 23, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | /**
34 | * Set up a static function to allow fast mutable array insertion using
35 | * cached selectors.
36 | * At least in 10.7, inserting items into an array at a known point
37 | * using NSMutableArray methods appears to be the fastest way of adding
38 | * items to a CF/NSMutableArray.
39 | */
40 | static inline void SPMySQLMutableArrayInsertObject(NSMutableArray *self, id anObject, NSUInteger anIndex)
41 | {
42 | typedef id (*SPMySQLMutableArrayInsertObjectPtr)(NSMutableArray*, SEL, id, NSUInteger);
43 | static SPMySQLMutableArrayInsertObjectPtr cachedMethodPointer;
44 | static SEL cachedSelector;
45 |
46 | if (!cachedSelector) cachedSelector = @selector(insertObject:atIndex:);
47 | if (!cachedMethodPointer) cachedMethodPointer = (SPMySQLMutableArrayInsertObjectPtr)[self methodForSelector:cachedSelector];
48 |
49 | cachedMethodPointer(self, cachedSelector, anObject, anIndex);
50 | }
51 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/MySQL Client Libraries/include/typelib.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2 |
3 | This program is free software; you can redistribute it and/or modify
4 | it under the terms of the GNU General Public License as published by
5 | the Free Software Foundation; version 2 of the License.
6 |
7 | This program is distributed in the hope that it will be useful,
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | GNU General Public License for more details.
11 |
12 | You should have received a copy of the GNU General Public License
13 | along with this program; if not, write to the Free Software
14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15 |
16 |
17 | #ifndef _typelib_h
18 | #define _typelib_h
19 |
20 | #include "my_alloc.h"
21 |
22 | typedef struct st_typelib { /* Different types saved here */
23 | unsigned int count; /* How many types */
24 | const char *name; /* Name of typelib */
25 | const char **type_names;
26 | unsigned int *type_lengths;
27 | } TYPELIB;
28 |
29 | extern my_ulonglong find_typeset(char *x, TYPELIB *typelib,int *error_position);
30 | extern int find_type_or_exit(const char *x, TYPELIB *typelib,
31 | const char *option);
32 | #define FIND_TYPE_BASIC 0
33 | /** makes @c find_type() require the whole name, no prefix */
34 | #define FIND_TYPE_NO_PREFIX (1 << 0)
35 | /** always implicitely on, so unused, but old code may pass it */
36 | #define FIND_TYPE_NO_OVERWRITE (1 << 1)
37 | /** makes @c find_type() accept a number */
38 | #define FIND_TYPE_ALLOW_NUMBER (1 << 2)
39 | /** makes @c find_type() treat ',' as terminator */
40 | #define FIND_TYPE_COMMA_TERM (1 << 3)
41 |
42 | extern int find_type(const char *x, const TYPELIB *typelib, unsigned int flags);
43 | extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
44 | extern const char *get_type(TYPELIB *typelib,unsigned int nr);
45 | extern TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from);
46 |
47 | extern TYPELIB sql_protocol_typelib;
48 |
49 | my_ulonglong find_set_from_flags(const TYPELIB *lib, unsigned int default_name,
50 | my_ulonglong cur_set, my_ulonglong default_set,
51 | const char *str, unsigned int length,
52 | char **err_pos, unsigned int *err_len);
53 |
54 | #endif /* _typelib_h */
55 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionProxy.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLConnectionProxy.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLConnectionProxy.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Stuart Connolly (stuconnolly.com) on July 2, 2009.
8 | // Copyright (c) 2009 Stuart Connolly. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | /**
35 | * Connection proxy state constants.
36 | */
37 | typedef enum {
38 | SPMySQLProxyIdle = 0,
39 | SPMySQLProxyConnecting = 1,
40 | SPMySQLProxyWaitingForAuth = 2,
41 | SPMySQLProxyConnected = 3,
42 | SPMySQLProxyForwardingFailed = 4
43 | } SPMySQLConnectionProxyState;
44 |
45 |
46 | @protocol SPMySQLConnectionProxy
47 |
48 | /**
49 | * All the methods for this protocol are required.
50 | */
51 |
52 | /**
53 | * Connect the proxy.
54 | */
55 | - (void)connect;
56 |
57 | /**
58 | * Disconnect the proxy.
59 | */
60 | - (void)disconnect;
61 |
62 | /**
63 | * Get the current state of the proxy.
64 | */
65 | - (SPMySQLConnectionProxyState)state;
66 |
67 | /**
68 | * Get the local port being provided by the proxy.
69 | */
70 | - (NSUInteger)localPort;
71 |
72 | /**
73 | * Sets the method the proxy should call whenever the state of the connection changes.
74 | */
75 | - (BOOL)setConnectionStateChangeSelector:(SEL)theStateChangeSelector delegate:(id)theDelegate;
76 |
77 | @end
78 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQL.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQL.h 3551 2012-03-27 21:02:15Z sqlprodev@gmail.com $
3 | //
4 | // SPMySQL.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 22, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | @class SPMySQLConnection, SPMySQLResult, SPMySQLStreamingResult, SPMySQLFastStreamingResult;
34 |
35 | // Global include file for the framework.
36 | // Constants
37 | #import "SPMySQLConstants.h"
38 |
39 | // Required category additions
40 | #ifndef SP_REFACTOR
41 | #import "SPMySQLStringAdditions.h"
42 | #else
43 | #import
44 | #endif
45 |
46 | // MySQL Connection Delegate and Proxy protocols
47 | #import "SPMySQLConnectionDelegate.h"
48 | #import "SPMySQLConnectionProxy.h"
49 |
50 | // MySQL Connection class and public categories
51 | #import "SPMySQLConnection.h"
52 | #import "Delegate & Proxy.h"
53 | #import "Databases & Tables.h"
54 | #import "Max Packet Size.h"
55 | #import "Querying & Preparation.h"
56 | #import "Encoding.h"
57 | #import "Server Info.h"
58 |
59 | // MySQL result set, streaming subclasses of same, and associated categories
60 | #import "SPMySQLResult.h"
61 | #import "SPMySQLStreamingResult.h"
62 | #import "SPMySQLFastStreamingResult.h"
63 | #import "Field Definitions.h"
64 | #import "Convenience Methods.h"
65 |
66 | // Result data objects
67 | #import "SPMySQLGeometryData.h"
68 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Conversion.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Conversion.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Encoding.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 22, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 | //
32 | // More info at
33 |
34 | // This class is private to the framework.
35 |
36 | @interface SPMySQLConnection (Conversion)
37 |
38 | + (const char *)_cStringForString:(NSString *)aString usingEncoding:(NSStringEncoding)anEncoding returningLengthAs:(NSUInteger *)cStringLengthPointer;
39 |
40 | - (const char *)_cStringForString:(NSString *)aString;
41 | - (NSString *)_stringForCString:(const char *)cString;
42 |
43 | @end
44 |
45 |
46 | /**
47 | * Set up a static function to allow fast calling with cached selectors
48 | */
49 | static inline const char* _cStringForStringWithEncoding(NSString* aString, NSStringEncoding anEncoding, NSUInteger *cStringLengthPointer)
50 | {
51 | static Class cachedClass;
52 | static IMP cachedMethodPointer;
53 | static SEL cachedSelector;
54 |
55 | if (!cachedClass) cachedClass = [SPMySQLConnection class];
56 | if (!cachedSelector) cachedSelector = @selector(_cStringForString:usingEncoding:returningLengthAs:);
57 | if (!cachedMethodPointer) cachedMethodPointer = [SPMySQLConnection methodForSelector:cachedSelector];
58 |
59 | return (const char *)(*cachedMethodPointer)(cachedClass, cachedSelector, aString, anEncoding, cStringLengthPointer);
60 | }
61 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLConstants.h 3631 2012-05-08 01:03:31Z rowanb@gmail.com $
3 | //
4 | // SPMySQLConstants.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 14, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | // Connection state
35 | typedef enum {
36 | SPMySQLDisconnected = 0,
37 | SPMySQLConnecting = 1,
38 | SPMySQLConnected = 2,
39 | SPMySQLConnectionLostInBackground = 3,
40 | SPMySQLDisconnecting = 4
41 | } SPMySQLConnectionState;
42 |
43 | // Connection lock state
44 | typedef enum {
45 | SPMySQLConnectionIdle = 0,
46 | SPMySQLConnectionBusy = 1
47 | } SPMySQLConnectionLockState;
48 |
49 | // Decision on how to handle lost connections
50 | // Connection check constants
51 | typedef enum {
52 | SPMySQLConnectionLostDisconnect = 0,
53 | SPMySQLConnectionLostReconnect = 1
54 | } SPMySQLConnectionLostDecision;
55 |
56 | // Result set row types
57 | typedef enum {
58 | SPMySQLResultRowAsDefault = 0,
59 | SPMySQLResultRowAsArray = 1,
60 | SPMySQLResultRowAsDictionary = 2
61 | } SPMySQLResultRowType;
62 |
63 | // Result charset list
64 | typedef struct {
65 | NSUInteger nr;
66 | const char *name;
67 | const char *collation;
68 | NSUInteger char_minlen;
69 | NSUInteger char_maxlen;
70 | } SPMySQLResultCharset;
71 |
72 | // Query result types
73 | typedef enum {
74 | SPMySQLResultAsResult = 0,
75 | SPMySQLResultAsFastStreamingResult = 1,
76 | SPMySQLResultAsLowMemStreamingResult = 2
77 | } SPMySQLResultType;
78 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Convenience Methods.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Convenience Methods.m 3583 2012-04-12 23:48:20Z rowanb@gmail.com $
3 | //
4 | // Convenience Methods.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 20, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #import "Convenience Methods.h"
34 |
35 | @implementation SPMySQLResult (Convenience_Methods)
36 |
37 | /**
38 | * Iterates over the result set, retrieving all the rows, and returns them
39 | * as an array.
40 | * The rows are in the default format for this instance, as controlled via
41 | * -setDefaultRowReturnType:.
42 | * Returns nil if there are no rows to return.
43 | */
44 | - (NSArray *)getAllRows
45 | {
46 | unsigned long long previousSeekPosition = currentRowIndex;
47 |
48 | NSMutableArray *rowsToReturn;
49 |
50 | // If the number of rows is known, pre-set the size; otherwise just create an array
51 | if (numberOfRows != NSNotFound) {
52 | rowsToReturn = [[NSMutableArray alloc] initWithCapacity:(NSUInteger)numberOfRows];
53 | } else {
54 | rowsToReturn = [[NSMutableArray alloc] init];
55 | }
56 |
57 | // Loop through the rows in the instance-specified return format
58 | for (id eachRow in self) {
59 | [rowsToReturn addObject:eachRow];
60 | }
61 |
62 | // Seek to the previous position if appropriate
63 | if (previousSeekPosition) [self seekToRow:previousSeekPosition];
64 |
65 | // Instead of empty arrays, return nil if there are no rows.
66 | if (![rowsToReturn count]) return nil;
67 |
68 | return [rowsToReturn autorelease];
69 | }
70 |
71 | @end
72 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Copying.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Copying.m 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Copying.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on March 8, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #import "Copying.h"
34 |
35 | @implementation SPMySQLConnection (Copying)
36 |
37 | /**
38 | * Provide a copy of the SPMySQLConnection instance.
39 | * The copy should inherit the full setup, but will not inherit
40 | * the connection state - it will not be connected, and any connection
41 | * details such as the selected database/encoding will not be inherited.
42 | * Note that any proxy will not be referenced in the new connection, and
43 | * should also be set if desired.
44 | */
45 | - (id)copyWithZone:(NSZone *)zone
46 | {
47 | SPMySQLConnection *copy = [[[self class] allocWithZone:zone] init];
48 |
49 | // Synthesized details
50 | [copy setDelegate:delegate];
51 | [copy setHost:host];
52 | [copy setUsername:username];
53 | [copy setPassword:password];
54 | [copy setPort:port];
55 | [copy setUseSocket:useSocket];
56 | [copy setSocketPath:socketPath];
57 | [copy setUseSSL:useSSL];
58 | [copy setSslKeyFilePath:sslKeyFilePath];
59 | [copy setSslCertificatePath:sslCertificatePath];
60 | [copy setSslCACertificatePath:sslCACertificatePath];
61 | [copy setTimeout:timeout];
62 | [copy setUseKeepAlive:useKeepAlive];
63 | [copy setRetryQueriesOnConnectionFailure:retryQueriesOnConnectionFailure];
64 | [copy setDelegateQueryLogging:delegateQueryLogging];
65 |
66 | // Active connection state details, like selected database and encoding, are *not* copied.
67 |
68 | return copy;
69 | }
70 |
71 | @end
72 |
--------------------------------------------------------------------------------
/Sequel Pro/NTDetailViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // NTDetailViewController.m
3 | // Sequel Pro
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | // Copyright (c) 2012 North of Three. All rights reserved.
7 | //
8 |
9 | #import "NTDetailViewController.h"
10 |
11 | @interface NTDetailViewController ()
12 | @property (strong, nonatomic) UIPopoverController *masterPopoverController;
13 | - (void)configureView;
14 | @end
15 |
16 | @implementation NTDetailViewController
17 |
18 | - (void)dealloc
19 | {
20 | [_detailItem release];
21 | [_detailDescriptionLabel release];
22 | [_masterPopoverController release];
23 | [super dealloc];
24 | }
25 |
26 | #pragma mark - Managing the detail item
27 |
28 | - (void)setDetailItem:(id)newDetailItem
29 | {
30 | if (_detailItem != newDetailItem) {
31 | [_detailItem release];
32 | _detailItem = [newDetailItem retain];
33 |
34 | // Update the view.
35 | [self configureView];
36 | }
37 |
38 | if (self.masterPopoverController != nil) {
39 | [self.masterPopoverController dismissPopoverAnimated:YES];
40 | }
41 | }
42 |
43 | - (void)configureView
44 | {
45 | // Update the user interface for the detail item.
46 |
47 | if (self.detailItem) {
48 | self.detailDescriptionLabel.text = [self.detailItem description];
49 | }
50 | }
51 |
52 | - (void)viewDidLoad
53 | {
54 | [super viewDidLoad];
55 | // Do any additional setup after loading the view, typically from a nib.
56 | [self configureView];
57 | }
58 |
59 | - (void)didReceiveMemoryWarning
60 | {
61 | [super didReceiveMemoryWarning];
62 | // Dispose of any resources that can be recreated.
63 | }
64 |
65 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
66 | {
67 | return YES;
68 | }
69 |
70 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
71 | {
72 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
73 | if (self) {
74 | self.title = NSLocalizedString(@"Detail", @"Detail");
75 | }
76 | return self;
77 | }
78 |
79 | #pragma mark - Split view
80 |
81 | - (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
82 | {
83 | barButtonItem.title = NSLocalizedString(@"Master", @"Master");
84 | [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
85 | self.masterPopoverController = popoverController;
86 | }
87 |
88 | - (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
89 | {
90 | // Called when the view is shown again in the split view, invalidating the button and popover controller.
91 | [self.navigationItem setLeftBarButtonItem:nil animated:YES];
92 | self.masterPopoverController = nil;
93 | }
94 |
95 | @end
96 |
--------------------------------------------------------------------------------
/Sequel Pro.xcodeproj/xcuserdata/matt.xcuserdatad/xcschemes/Sequel Pro.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/Sequel Pro/NTAppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // NTAppDelegate.m
3 | // Sequel Pro
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | // Copyright (c) 2012 North of Three. All rights reserved.
7 | //
8 |
9 | #import "NTAppDelegate.h"
10 |
11 | #import "NTMasterViewController.h"
12 |
13 | #import "NTDetailViewController.h"
14 |
15 | @implementation NTAppDelegate
16 |
17 | - (void)dealloc
18 | {
19 | [_window release];
20 | [_splitViewController release];
21 | [super dealloc];
22 | }
23 |
24 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
25 | {
26 | self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
27 | // Override point for customization after application launch.
28 |
29 | NTMasterViewController *masterViewController = [[[NTMasterViewController alloc] initWithNibName:@"NTMasterViewController" bundle:nil] autorelease];
30 | UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
31 |
32 | NTDetailViewController *detailViewController = [[[NTDetailViewController alloc] initWithNibName:@"NTDetailViewController" bundle:nil] autorelease];
33 | UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
34 |
35 | masterViewController.detailViewController = detailViewController;
36 |
37 | self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
38 | self.splitViewController.delegate = detailViewController;
39 | self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
40 | self.window.rootViewController = self.splitViewController;
41 | [self.window makeKeyAndVisible];
42 | return YES;
43 | }
44 |
45 | - (void)applicationWillResignActive:(UIApplication *)application
46 | {
47 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
48 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
49 | }
50 |
51 | - (void)applicationDidEnterBackground:(UIApplication *)application
52 | {
53 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
54 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
55 | }
56 |
57 | - (void)applicationWillEnterForeground:(UIApplication *)application
58 | {
59 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
60 | }
61 |
62 | - (void)applicationDidBecomeActive:(UIApplication *)application
63 | {
64 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
65 | }
66 |
67 | - (void)applicationWillTerminate:(UIApplication *)application
68 | {
69 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
70 | }
71 |
72 | @end
73 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Readme.txt:
--------------------------------------------------------------------------------
1 | The SPMySQL Framework is intended to provide a stable MySQL connection framework, with the ability to run text-based queries and rapidly retrieve result sets with conversion from MySQL data types to Cocoa objects.
2 |
3 | SPMySQL.framework has an interface loosely based around that provided by MCPKit by Serge Cohen and Bertrand Mansion (http://mysql-cocoa.sourceforge.net/), and in particular the heavily modified Sequel Pro version (http://www.sequelpro.com/). It is a full rewrite of the original framework, although it includes code from patches implementing the following Sequel Pro functionality, largely contributed by Hans-Jörg Bibiko, Stuart Connolly, Jakob Egger, and Rowan Beentje:
4 | - Connection locking (Jakob et al)
5 | - Ping & keepalive (Rowan et al)
6 | - Query cancellation (Rowan et al)
7 | - Delegate setup (Stuart et al)
8 | - SSL support (Rowan et al)
9 | - Connection checking (Rowan et al)
10 | - Version state (Stuart et al)
11 | - Maximum packet size control (Hans et al)
12 | - Result multithreading and streaming (Rowan et al)
13 | - Improved encoding support & switching (Rowan et al)
14 | - Database structure; moved to inside the app (Hans et al)
15 | - Query reattempts and error-handling approach (Rowan et al)
16 | - Geometry result class (Hans et al)
17 | - Connection proxy (Stuart et al)
18 |
19 |
20 | INTEGRATION
21 |
22 | SPMySQL.framework can be added to your project as a standard Cocoa framework, or the entire project can be added as a subproject in Xcode.
23 | To add as a subproject in Xcode:
24 | 1) Add the SPMySQL framework's .xcodeproj to your current project
25 | 2) Choose an existing target, Get Info, and under direct dependenies add a new dependency. Choose the SPMySQL.framework target from the sub-project
26 | 3) Expand the subproject to see its child target - SPMySQL.framework. Drag this to the "Link Binary With Libraries" build phase of any targets using the framework.
27 | 4) If you don't have a Copy Frameworks phase, add one; drag the SPMySQL.framework child target to this phase.
28 | 5) In your build settings, add a User Header Search Path; make it a recursive path to the SPMySQL project folder location (for example ${PROJECT_DIR}/Frameworks/SPMySQLFramework). This should allow you to #include "SPMySQL.h" and have everything function.
29 |
30 | As a last resort jump onto IRC and join #sequel-pro on irc.freenode.net and any of the
31 | developers will be more than happy to help you out.
32 |
33 |
34 | LICENSE
35 |
36 | Copyright (c) 2012 Rowan Beentje (rowan.beent.je) and the Sequel Pro team.
37 |
38 | The SPMySQL framework is offered under the MIT license:
39 |
40 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
41 |
42 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
43 |
44 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Locking.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Locking.m 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Locking.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 22, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | // This class is private to the framework.
34 |
35 | #import "Locking.h"
36 | #import "SPMySQL Private APIs.h"
37 |
38 | @implementation SPMySQLConnection (Locking)
39 |
40 |
41 | /**
42 | * Lock the connection. This must be done before performing any operation
43 | * that is not thread safe, eg. performing queries or pinging.
44 | */
45 | - (void)_lockConnection
46 | {
47 |
48 | // We can only start a query when the condition is SPMySQLConnectionIdle
49 | [connectionLock lockWhenCondition:SPMySQLConnectionIdle];
50 |
51 | // Set the condition to SPMySQLConnectionBusy
52 | [connectionLock unlockWithCondition:SPMySQLConnectionBusy];
53 | }
54 |
55 | /**
56 | * Attempt to lock the connection. If the connection is idle (unlocked), this method
57 | * locks the connection and returns YES for success. The connection must afterward
58 | * be unlocked using unlockConnection. If the connection is currently busy (locked),
59 | * this method immediately returns NO and doesn't lock the connection.
60 | */
61 | - (BOOL)_tryLockConnection
62 | {
63 |
64 | // If the connection is already is use, return failure
65 | if (![connectionLock tryLockWhenCondition:SPMySQLConnectionIdle]) {
66 | return NO;
67 | }
68 |
69 | // We're allowed to use the connection; set it to busy, and return success
70 | [connectionLock unlockWithCondition:SPMySQLConnectionBusy];
71 | return YES;
72 | }
73 |
74 |
75 | /**
76 | * Unlock the connection.
77 | */
78 | - (void)_unlockConnection
79 | {
80 |
81 | // Always lock the conditional lock before proceeding
82 | [connectionLock lock];
83 |
84 | // Check if the connection actually was busy. If it wasn't busy,
85 | // it means the connection may have been unlocked twice. This is
86 | // potentially dangerous, so we log this to the console
87 | if ([connectionLock condition] != SPMySQLConnectionBusy) {
88 | NSLog(@"SPMySQLConnection: Tried to unlock the connection, but it wasn't locked.");
89 | }
90 |
91 | // Since we connected with CLIENT_MULTI_RESULT, we must make sure there are not more results!
92 | // This is still a bit of a dirty hack
93 | if (state == SPMySQLConnected
94 | && mySQLConnection && mySQLConnection->net.vio && mySQLConnection->net.buff && mysql_more_results(mySQLConnection))
95 | {
96 | NSLog(@"SPMySQLConnection: Discarding unretrieved results. This is currently normal when using CALL.");
97 | [self _flushMultipleResultSets];
98 | }
99 |
100 | // Tell everyone that the connection is available again
101 | [connectionLock unlockWithCondition:SPMySQLConnectionIdle];
102 | }
103 |
104 | @end
105 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Conversion.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Conversion.m 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Encoding.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 22, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | // This class is private to the framework.
34 |
35 | #import "Conversion.h"
36 |
37 | @implementation SPMySQLConnection (Conversion)
38 |
39 | /**
40 | * Converts an NSString to a null-terminated C string, using the supplied encoding.
41 | * Uses lossy conversion, so if a string cannot be entirely converted using
42 | * the current encoding, a representation will be returned rather than null.
43 | * The returned cString will correctly preserve any nul characters within the string,
44 | * which prevents the use of faster functions like [NSString cStringUsingEncoding:].
45 | * Pass in the third parameter to receive the length of the converted string, or pass
46 | * in NULL if you do not want this information.
47 | */
48 | + (const char *)_cStringForString:(NSString *)aString usingEncoding:(NSStringEncoding)anEncoding returningLengthAs:(NSUInteger *)cStringLengthPointer
49 | {
50 |
51 | // Don't try and convert nil strings
52 | if (!aString) return NULL;
53 |
54 | // Perform a lossy conversion, using NSData to do the hard work
55 | NSData *convertedData = [aString dataUsingEncoding:anEncoding allowLossyConversion:YES];
56 | NSUInteger convertedDataLength = [convertedData length];
57 |
58 | // Take the converted data - not null-terminated - and copy it to a null-terminated buffer
59 | char *cStringBytes = malloc(convertedDataLength + 1);
60 | memcpy(cStringBytes, [convertedData bytes], convertedDataLength);
61 | cStringBytes[convertedDataLength] = 0L;
62 |
63 | if (cStringLengthPointer) *cStringLengthPointer = convertedDataLength+1;
64 |
65 | // Ensure the memory is autoreleased when needed, and return.
66 | [NSData dataWithBytesNoCopy:cStringBytes length:convertedDataLength+1 freeWhenDone:YES];
67 | return cStringBytes;
68 | }
69 |
70 | /**
71 | * Converts an NSString to a null-terminated C string, using the current
72 | * connection encoding.
73 | */
74 | - (const char *)_cStringForString:(NSString *)aString
75 | {
76 |
77 | // Use a cached reference to avoid dynamic method overhead
78 | return _cStringForStringWithEncoding(aString, stringEncoding, NULL);
79 | }
80 |
81 | /**
82 | * Converts a C string to an NSString using the supplied encoding.
83 | * This method *will not* correctly preserve nul characters within c strings; instead
84 | * the first nul character within the string will be treated as the line ending. This
85 | * is unavoidable without supplying a string length, so this method should not be widely
86 | * used for actual data conversion.
87 | */
88 | - (NSString *)_stringForCString:(const char *)cString
89 | {
90 |
91 | // Don't try and convert null strings
92 | if (cString == NULL) return nil;
93 |
94 | return [NSString stringWithCString:cString encoding:stringEncoding];
95 | }
96 |
97 | @end
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLKeepAliveTimer.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLKeepAliveTimer.m 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLKeepAliveTimer.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on March 5, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | #import "SPMySQLKeepAliveTimer.h"
35 | #import "SPMySQL Private APIs.h"
36 |
37 | @interface SPMySQLKeepAliveTimer (Private_API)
38 |
39 | - (void)_initKeepAliveTimer;
40 | - (void)_forwardPing;
41 |
42 | @end
43 |
44 | #pragma mark -
45 |
46 | @implementation SPMySQLKeepAliveTimer
47 |
48 | /**
49 | * Prevent SPMySQLKeepAliveTimer from being init'd normally.
50 | */
51 | - (id)init
52 | {
53 | [NSException raise:NSInternalInconsistencyException format:@"SPMySQLKeepAliveTimers should not be init'd directly; use initWithInterval:target:selector: instead."];
54 | return nil;
55 | }
56 |
57 | /**
58 | * Initialise the SPMySQLKeepAliveTimer. This also sets up the contained timer,
59 | * which has to be wrapped in this class to prevent retain cycles preventing the
60 | * parent connection from being released.
61 | *
62 | * After initialisation, the delegate should be set to ensure that the timer events
63 | * are received.
64 | */
65 | - (id)initWithInterval:(NSTimeInterval)anInterval target:(id)aTarget selector:(SEL)aSelector
66 | {
67 | if ((self = [super init])) {
68 | wrappedTimer = nil;
69 |
70 | // Keep a weak reference to the target
71 | timerTarget = aTarget;
72 | timerSelector = aSelector;
73 | timerRepeatInterval = anInterval;
74 |
75 | // Ensure the timer is set up on the main thread
76 | if ([NSThread isMainThread]) {
77 | [self _initKeepAliveTimer];
78 | } else {
79 | [self performSelectorOnMainThread:@selector(_initKeepAliveTimer) withObject:nil waitUntilDone:YES];
80 | }
81 | }
82 |
83 | return self;
84 | }
85 |
86 | /**
87 | * Invalidate the wrapped timer, which also releases the reference to the timer
88 | * target (this object), breaking retain loops.
89 | */
90 | - (void)invalidate
91 | {
92 | if ([NSThread isMainThread]) {
93 | [wrappedTimer invalidate];
94 | } else {
95 | [wrappedTimer performSelectorOnMainThread:@selector(invalidate) withObject:nil waitUntilDone:YES];
96 | }
97 | }
98 |
99 | - (void)dealloc
100 | {
101 | [wrappedTimer dealloc];
102 | [super dealloc];
103 | }
104 |
105 | @end
106 |
107 | @implementation SPMySQLKeepAliveTimer (Private_API)
108 |
109 | /**
110 | * Set up the timer to tickle the target. This must be set up on the main thread
111 | * to ensure the timer events keep firing.
112 | */
113 | - (void)_initKeepAliveTimer
114 | {
115 | wrappedTimer = [[NSTimer scheduledTimerWithTimeInterval:timerRepeatInterval target:self selector:@selector(_forwardPing) userInfo:nil repeats:YES] retain];
116 | }
117 |
118 | /**
119 | * Forward the NSTimer-fired ping to the target object. Performing this forwarding
120 | * breaks the retain cycle.
121 | */
122 | - (void)_forwardPing
123 | {
124 | [timerTarget performSelector:timerSelector];
125 | }
126 |
127 | @end
128 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQL Private APIs.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQL Private APIs.h 3631 2012-05-08 01:03:31Z rowanb@gmail.com $
3 | //
4 | // SPMySQLConnection_PrivateAPI.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 12, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | /**
34 | * A collection of Private APIs from the various categories, to simplify
35 | * inclusion across the categories.
36 | */
37 |
38 | #import "Ping & KeepAlive.h"
39 | #import "Locking.h"
40 | #import "Conversion.h"
41 |
42 | @interface SPMySQLConnection (PrivateAPI)
43 |
44 | - (MYSQL *)_makeRawMySQLConnectionWithEncoding:(NSString *)encodingName isMasterConnection:(BOOL)isMaster;
45 | - (BOOL)_reconnectAllowingRetries:(BOOL)canRetry;
46 | - (BOOL)_reconnectAfterBackgroundConnectionLoss;
47 | - (BOOL)_waitForNetworkConnectionWithTimeout:(double)timeoutSeconds;
48 | - (void)_updateConnectionVariables;
49 | - (void)_restoreConnectionVariables;
50 | - (BOOL)_checkConnectionIfNecessary;
51 | - (void)_validateThreadSetup;
52 | + (void)_removeThreadVariables:(NSNotification *)aNotification;
53 |
54 | @end
55 |
56 |
57 | @interface SPMySQLConnection (Delegate_and_Proxy_Private_API)
58 |
59 | - (void)_proxyStateChange:(NSObject *)aProxy;
60 | - (SPMySQLConnectionLostDecision)_delegateDecisionForLostConnection;
61 |
62 | @end
63 |
64 |
65 | @interface SPMySQLConnection (Databases_and_Tables_Private_API)
66 |
67 | - (BOOL)_storeAndAlterEncodingToUTF8IfRequired;
68 |
69 | @end
70 |
71 |
72 | @interface SPMySQLConnection (Max_Packet_Size_Private_API)
73 |
74 | - (void)_updateMaxQuerySize;
75 | - (void)_updateMaxQuerySizeEditability;
76 | - (BOOL)_attemptMaxQuerySizeIncreaseTo:(NSUInteger)targetSize;
77 | - (void)_restoreMaximumQuerySizeAfterQuery;
78 |
79 | @end
80 |
81 |
82 | @interface SPMySQLConnection (Querying_and_Preparation_Private_API)
83 |
84 | - (void)_flushMultipleResultSets;
85 | - (void)_updateLastErrorMessage:(NSString *)theErrorMessage;
86 | - (void)_updateLastErrorID:(NSUInteger)theErrorID;
87 |
88 | @end
89 |
90 |
91 | // SPMySQLResult Private API
92 | @interface SPMySQLResult (Private_API)
93 |
94 | - (NSString *)_stringWithBytes:(const void *)bytes length:(NSUInteger)length;
95 | - (void)_setQueryExecutionTime:(double)theExecutionTime;
96 | - (id)_getObjectFromBytes:(char *)bytes ofLength:(NSUInteger)length fieldType:(unsigned int)fieldType fieldDefinitionIndex:(NSUInteger)fieldIndex;
97 |
98 | @end
99 |
100 | /**
101 | * Set up a static function to allow fast calling of SPMySQLResult data conversion with cached selectors
102 | */
103 | static inline id SPMySQLResultGetObject(SPMySQLResult* self, char* bytes, NSUInteger length, unsigned int fieldType, NSUInteger fieldIndex)
104 | {
105 | typedef id (*SPMySQLResultGetObjectMethodPtr)(SPMySQLResult*, SEL, char*, NSUInteger, unsigned int, NSUInteger);
106 | static SPMySQLResultGetObjectMethodPtr cachedMethodPointer;
107 | static SEL cachedSelector;
108 |
109 | if (!cachedSelector) cachedSelector = @selector(_getObjectFromBytes:ofLength:fieldType:fieldDefinitionIndex:);
110 | if (!cachedMethodPointer) cachedMethodPointer = (SPMySQLResultGetObjectMethodPtr)[self methodForSelector:cachedSelector];
111 |
112 | return cachedMethodPointer(self, cachedSelector, bytes, length, fieldType, fieldIndex);
113 | }
--------------------------------------------------------------------------------
/Sequel Pro/NTMasterViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // NTMasterViewController.m
3 | // Sequel Pro
4 | //
5 | // Created by Matt Langtree on 17/06/12.
6 | // Copyright (c) 2012 North of Three. All rights reserved.
7 | //
8 |
9 | #import "NTMasterViewController.h"
10 |
11 | #import "NTDetailViewController.h"
12 |
13 | @interface NTMasterViewController () {
14 | NSMutableArray *_objects;
15 | }
16 | @end
17 |
18 | @implementation NTMasterViewController
19 |
20 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
21 | {
22 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
23 | if (self) {
24 | self.title = NSLocalizedString(@"Master", @"Master");
25 | self.clearsSelectionOnViewWillAppear = NO;
26 | self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
27 | }
28 | return self;
29 | }
30 |
31 | - (void)dealloc
32 | {
33 | [_detailViewController release];
34 | [_objects release];
35 | [super dealloc];
36 | }
37 |
38 | - (void)viewDidLoad
39 | {
40 | [super viewDidLoad];
41 | // Do any additional setup after loading the view, typically from a nib.
42 | self.navigationItem.leftBarButtonItem = self.editButtonItem;
43 |
44 | UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)] autorelease];
45 | self.navigationItem.rightBarButtonItem = addButton;
46 | }
47 |
48 | - (void)didReceiveMemoryWarning
49 | {
50 | [super didReceiveMemoryWarning];
51 | // Dispose of any resources that can be recreated.
52 | }
53 |
54 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
55 | {
56 | return YES;
57 | }
58 |
59 | - (void)insertNewObject:(id)sender
60 | {
61 | if (!_objects) {
62 | _objects = [[NSMutableArray alloc] init];
63 | }
64 | [_objects insertObject:[NSDate date] atIndex:0];
65 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
66 | [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
67 | }
68 |
69 | #pragma mark - Table View
70 |
71 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
72 | {
73 | return 1;
74 | }
75 |
76 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
77 | {
78 | return _objects.count;
79 | }
80 |
81 | // Customize the appearance of table view cells.
82 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
83 | {
84 | static NSString *CellIdentifier = @"Cell";
85 |
86 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
87 | if (cell == nil) {
88 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
89 | }
90 |
91 |
92 | NSDate *object = _objects[indexPath.row];
93 | cell.textLabel.text = [object description];
94 | return cell;
95 | }
96 |
97 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
98 | {
99 | // Return NO if you do not want the specified item to be editable.
100 | return YES;
101 | }
102 |
103 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
104 | {
105 | if (editingStyle == UITableViewCellEditingStyleDelete) {
106 | [_objects removeObjectAtIndex:indexPath.row];
107 | [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
108 | } else if (editingStyle == UITableViewCellEditingStyleInsert) {
109 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
110 | }
111 | }
112 |
113 | /*
114 | // Override to support rearranging the table view.
115 | - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
116 | {
117 | }
118 | */
119 |
120 | /*
121 | // Override to support conditional rearranging of the table view.
122 | - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
123 | {
124 | // Return NO if you do not want the item to be re-orderable.
125 | return YES;
126 | }
127 | */
128 |
129 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
130 | {
131 | NSDate *object = _objects[indexPath.row];
132 | self.detailViewController.detailItem = object;
133 | }
134 |
135 | @end
136 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnectionDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLConnectionDelegate.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLConnectionDelegate.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Stuart Connolly (stuconnolly.com) on October 20, 2010.
8 | // Copyright (c) 2010 Stuart Connolly. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #import "SPMySQLConstants.h"
34 |
35 | @protocol SPMySQLConnectionDelegate
36 | @optional
37 |
38 | /**
39 | * Notifies the delegate that a query will be performed.
40 | *
41 | * @param query The query string that will be sent to the MySQL server
42 | * @param connection The connection instance performing the query
43 | */
44 | - (void)willQueryString:(NSString *)query connection:(id)connection;
45 |
46 | /**
47 | * Notifies the delegate that a query that was just performed gave
48 | * an error.
49 | *
50 | * @param error The query error, as a string
51 | * @param connection The connection instance which received the error
52 | */
53 | - (void)queryGaveError:(NSString *)error connection:(id)connection;
54 |
55 | /**
56 | * Notifies the delegate that it should display the supplied error.
57 | * The connection may sometimes want to notify the user directly
58 | * about certain issues, and will use this method to allow the
59 | * delegate to do so.
60 | *
61 | * @param title The title of the message to display to the user
62 | * @param message The main text of the message to display to the user
63 | */
64 | - (void)showErrorWithTitle:(NSString *)title message:(NSString *)message;
65 |
66 | /**
67 | * Requests the keychain password for the connection.
68 | * When a connection is being made to a server, it is best not to
69 | * set the password on the class; instead, it should be kept within
70 | * the secure store, and the other connection details (user, host)
71 | * can be used to look it up and supplied on demand.
72 | *
73 | * @param connection The connection instance to supply the password for
74 | */
75 | - (NSString *)keychainPasswordForConnection:(id)connection;
76 |
77 | /**
78 | * Notifies the delegate that no underlying connection is available,
79 | * typically when the connection has been asked to perform a query
80 | * or some other action for which a connection must be present.
81 | * Those actions will still return false or error states as appropriate,
82 | * but the delegate may wish to perform actions as a result of a total
83 | * loss of connection.
84 | *
85 | * @param connection The connection instance which has lost the connection to the host
86 | */
87 | - (void)noConnectionAvailable:(id)connection;
88 |
89 | /**
90 | * Notifies the delegate that although a SSL connection was requested,
91 | * MySQL made the connection without using SSL. This can happen because
92 | * the server connected to doesn't support SSL or had it disabled, or
93 | * that insufficient details were provided to make the connection over
94 | * SSL.
95 | */
96 | - (void)connectionFellBackToNonSSL:(id)connection;
97 |
98 | /**
99 | * Notifies the delegate that the connection has been temporarily lost,
100 | * and asks the delegate for guidance on how to proceed. If the delegate
101 | * does not implement this method, reconnections will automatically be
102 | * attempted - up to a small limit of attempts.
103 | *
104 | * @param connection The connection instance that requires a decision on how to proceed
105 | */
106 | - (SPMySQLConnectionLostDecision)connectionLost:(id)connection;
107 |
108 | @end
109 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLResult.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLResult.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // SPMySQLResult.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 26, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | typedef enum {
35 | SPMySQLResultFieldAsUnhandled = 0,
36 | SPMySQLResultFieldAsString = 1,
37 | SPMySQLResultFieldAsStringOrBlob = 2,
38 | SPMySQLResultFieldAsBlob = 3,
39 | SPMySQLResultFieldAsBit = 4,
40 | SPMySQLResultFieldAsGeometry = 5,
41 | SPMySQLResultFieldAsNull = 6
42 | } SPMySQLResultFieldProcessor;
43 |
44 | @interface SPMySQLResult : NSObject {
45 |
46 | // Wrapped MySQL result set and its encoding
47 | struct st_mysql_res *resultSet;
48 | NSStringEncoding stringEncoding;
49 |
50 | // Number of fields in the result set, and the field names and information
51 | NSUInteger numberOfFields;
52 | struct st_mysql_field *fieldDefinitions;
53 | unsigned int *fieldTypes;
54 | NSString **fieldNames;
55 |
56 | // Number of rows in the result set and an internal data position counter
57 | unsigned long long numberOfRows;
58 | unsigned long long currentRowIndex;
59 |
60 | // How long it took to execute the query that produced this result
61 | double queryExecutionTime;
62 |
63 | // The target result set type for fast enumeration and unspecified row retrieval
64 | SPMySQLResultRowType defaultRowReturnType;
65 |
66 | // Whether all data should be returned as strings - useful for working with some older server types
67 | BOOL returnDataAsStrings;
68 | }
69 |
70 | // Master init method
71 | - (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding;
72 |
73 | // Result set information
74 | - (NSUInteger)numberOfFields;
75 | - (unsigned long long)numberOfRows;
76 | - (double)queryExecutionTime;
77 |
78 | // Column information
79 | - (NSArray *)fieldNames;
80 |
81 | // Data retrieval (note that fast enumeration is also supported, using instance-default format)
82 | - (void)seekToRow:(unsigned long long)targetRow;
83 | - (id)getRow;
84 | - (NSArray *)getRowAsArray;
85 | - (NSDictionary *)getRowAsDictionary;
86 | - (id)getRowAsType:(SPMySQLResultRowType)theType;
87 |
88 | // Data conversion
89 | + (NSString *)bitStringWithBytes:(const char *)bytes length:(NSUInteger)length padToLength:(NSUInteger)padLength;
90 |
91 | #pragma mark -
92 | #pragma mark Synthesized properties
93 |
94 | /**
95 | * Set whether the result should return data types as strings. This may be useful
96 | * for queries where the result may be returned in either string or data form, but
97 | * will be converted to string for display and use anyway.
98 | * Note that certain MySQL versions also return data types for strings - eg SHOW
99 | * commands like SHOW CREATE TABLE or SHOW VARIABLES, and this conversion can be
100 | * necessary there.
101 | */
102 | @property (readwrite, assign) BOOL returnDataAsStrings;
103 |
104 | @property (readwrite, assign) SPMySQLResultRowType defaultRowReturnType;
105 |
106 | @end
107 |
108 | /**
109 | * Set up a static function to allow fast calling with cached selectors
110 | */
111 | static inline id SPMySQLResultGetRow(SPMySQLResult* self, SPMySQLResultRowType rowType)
112 | {
113 | typedef id (*SPMySQLResultGetRowMethodPtr)(SPMySQLResult*, SEL, SPMySQLResultRowType);
114 | static SPMySQLResultGetRowMethodPtr cachedMethodPointer;
115 | static SEL cachedSelector;
116 |
117 | if (!cachedSelector) cachedSelector = @selector(getRowAsType:);
118 | if (!cachedMethodPointer) cachedMethodPointer = (SPMySQLResultGetRowMethodPtr)[self methodForSelector:cachedSelector];
119 |
120 | return cachedMethodPointer(self, cachedSelector, rowType);
121 | }
122 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Querying & Preparation.h 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Querying & Preparation.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 14, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | @interface SPMySQLConnection (Querying_and_Preparation)
35 |
36 | // Data preparation
37 | - (NSString *)escapeAndQuoteString:(NSString *)theString;
38 | - (NSString *)escapeString:(NSString *)theString includingQuotes:(BOOL)includeQuotes;
39 | - (NSString *)escapeAndQuoteData:(NSData *)theData;
40 | - (NSString *)escapeData:(NSData *)theData includingQuotes:(BOOL)includeQuotes;
41 |
42 | // Queries
43 | - (SPMySQLResult *)queryString:(NSString *)theQueryString;
44 | - (SPMySQLFastStreamingResult *)streamingQueryString:(NSString *)theQueryString;
45 | - (id)streamingQueryString:(NSString *)theQueryString useLowMemoryBlockingStreaming:(BOOL)fullStreaming;
46 | - (id)queryString:(NSString *)theQueryString usingEncoding:(NSStringEncoding)theEncoding withResultType:(SPMySQLResultType)theReturnType;
47 |
48 | // Query convenience functions
49 | - (NSArray *)getAllRowsFromQuery:(NSString *)theQueryString;
50 | - (id)getFirstFieldFromQuery:(NSString *)theQueryString;
51 |
52 | // Query information
53 | - (unsigned long long)rowsAffectedByLastQuery;
54 | - (unsigned long long)lastInsertID;
55 |
56 | // Connection and query error state
57 | - (BOOL)queryErrored;
58 | - (NSString *)lastErrorMessage;
59 | - (NSUInteger)lastErrorID;
60 | + (BOOL)isErrorIDConnectionError:(NSUInteger)theErrorID;
61 |
62 | // Query cancellation
63 | - (void)cancelCurrentQuery;
64 | - (BOOL)lastQueryWasCancelledUsingReconnect;
65 |
66 | @end
67 |
68 | /**
69 | * Set up static functions to allow fast calling with cached selectors
70 | */
71 |
72 | static inline id SPMySQLConnectionEscapeString(SPMySQLConnection* self, NSString *theString, BOOL encloseInQuotes)
73 | {
74 | typedef id (*SPMySQLConnectionEscapeStringMethodPtr)(SPMySQLConnection*, SEL, NSString *, BOOL);
75 | static SPMySQLConnectionEscapeStringMethodPtr cachedMethodPointer;
76 | static SEL cachedSelector;
77 |
78 | if (!cachedSelector) cachedSelector = @selector(escapeString:includingQuotes:);
79 | if (!cachedMethodPointer) cachedMethodPointer = (SPMySQLConnectionEscapeStringMethodPtr)[self methodForSelector:cachedSelector];
80 |
81 | return cachedMethodPointer(self, cachedSelector, theString, encloseInQuotes);
82 | }
83 |
84 | static inline id SPMySQLConnectionEscapeData(SPMySQLConnection* self, NSData *theData, BOOL encloseInQuotes)
85 | {
86 | typedef id (*SPMySQLConnectionEscapeDataMethodPtr)(SPMySQLConnection*, SEL, NSData *, BOOL);
87 | static SPMySQLConnectionEscapeDataMethodPtr cachedMethodPointer;
88 | static SEL cachedSelector;
89 |
90 | if (!cachedSelector) cachedSelector = @selector(escapeData:includingQuotes:);
91 | if (!cachedMethodPointer) cachedMethodPointer = (SPMySQLConnectionEscapeDataMethodPtr)[self methodForSelector:cachedSelector];
92 |
93 | return cachedMethodPointer(self, cachedSelector, theData, encloseInQuotes);
94 | }
95 |
96 | static inline id SPMySQLConnectionQueryString(SPMySQLConnection* self, NSString *theQueryString, NSStringEncoding theEncoding, SPMySQLResultType theReturnType)
97 | {
98 | typedef id (*SPMySQLConnectionQueryStringMethodPtr)(SPMySQLConnection*, SEL, NSString *, NSStringEncoding, SPMySQLResultType);
99 | static SPMySQLConnectionQueryStringMethodPtr cachedMethodPointer;
100 | static SEL cachedSelector;
101 |
102 | if (!cachedSelector) cachedSelector = @selector(queryString:usingEncoding:withResultType:);
103 | if (!cachedMethodPointer) cachedMethodPointer = (SPMySQLConnectionQueryStringMethodPtr)[self methodForSelector:cachedSelector];
104 |
105 | return cachedMethodPointer(self, cachedSelector, theQueryString, theEncoding, theReturnType);
106 | }
107 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLConnection.h 3658 2012-05-15 23:40:08Z rowanb@gmail.com $
3 | //
4 | // SPMySQLConnection.h
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 8, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | @class SPMySQLKeepAliveTimer;
34 |
35 | @interface SPMySQLConnection : NSObject {
36 |
37 | // Delegate
38 | NSObject *delegate;
39 | BOOL delegateSupportsWillQueryString;
40 | BOOL delegateSupportsConnectionLost;
41 | BOOL delegateQueryLogging; // Defaults to YES if protocol implemented
42 |
43 | // Basic connection details
44 | NSString *host;
45 | NSString *username;
46 | NSString *password;
47 | NSUInteger port;
48 | BOOL useSocket;
49 | NSString *socketPath;
50 |
51 | // SSL connection details
52 | BOOL useSSL;
53 | NSString *sslKeyFilePath;
54 | NSString *sslCertificatePath;
55 | NSString *sslCACertificatePath;
56 |
57 | // MySQL connection details and state
58 | struct st_mysql *mySQLConnection;
59 | SPMySQLConnectionState state;
60 | BOOL connectedWithSSL;
61 | BOOL userTriggeredDisconnect;
62 | BOOL isReconnecting;
63 | uint64_t initialConnectTime;
64 | unsigned long mysqlConnectionThreadId;
65 |
66 | // Connection proxy
67 | NSObject *proxy;
68 | SPMySQLConnectionProxyState previousProxyState;
69 | BOOL proxyStateChangeNotificationsIgnored;
70 |
71 | // Connection lock to prevent non-thread-safe query misuse
72 | NSConditionLock *connectionLock;
73 |
74 | // Currently selected database
75 | NSString *database, *databaseToRestore;
76 |
77 | // Delegate connection lost decisions
78 | NSUInteger reconnectionRetryAttempts;
79 | SPMySQLConnectionLostDecision lastDelegateDecisionForLostConnection;
80 | NSLock *delegateDecisionLock;
81 |
82 | // Timeout and keep-alive
83 | NSUInteger timeout;
84 | BOOL useKeepAlive;
85 | SPMySQLKeepAliveTimer *keepAliveTimer;
86 | CGFloat keepAliveInterval;
87 | uint64_t lastKeepAliveTime;
88 | NSUInteger keepAlivePingFailures;
89 | NSThread *keepAliveThread;
90 | pthread_t keepAlivePingThread_t;
91 | BOOL keepAlivePingThreadActive;
92 | BOOL keepAliveLastPingSuccess;
93 | BOOL keepAliveLastPingBlocked;
94 |
95 | // Encoding details - and also a record of any previous encoding to allow
96 | // switching back and forth
97 | NSString *encoding, *encodingToRestore;
98 | NSStringEncoding stringEncoding;
99 | BOOL encodingUsesLatin1Transport, encodingUsesLatin1TransportToRestore;
100 | NSString *previousEncoding;
101 | BOOL previousEncodingUsesLatin1Transport;
102 |
103 | // Server details
104 | NSString *serverVersionString;
105 |
106 | // Error state for the last query or connection state
107 | NSUInteger queryErrorID;
108 | NSString *queryErrorMessage;
109 |
110 | // Query details
111 | unsigned long long lastQueryAffectedRowCount;
112 | unsigned long long lastQueryInsertID;
113 |
114 | // Query cancellation details
115 | BOOL lastQueryWasCancelled;
116 | BOOL lastQueryWasCancelledUsingReconnect;
117 |
118 | // Timing details
119 | uint64_t lastConnectionUsedTime;
120 | double lastQueryExecutionTime;
121 |
122 | // Maximum query size
123 | NSUInteger maxQuerySize;
124 | BOOL maxQuerySizeIsEditable;
125 | BOOL maxQuerySizeEditabilityChecked;
126 | NSUInteger queryActionShouldRestoreMaxQuerySize;
127 |
128 | // Queries
129 | BOOL retryQueriesOnConnectionFailure;
130 | }
131 |
132 | #pragma mark -
133 | #pragma mark Synthesized properties
134 |
135 | @property (readwrite, retain) NSString *host;
136 | @property (readwrite, retain) NSString *username;
137 | @property (readwrite, retain) NSString *password;
138 | @property (readwrite, assign) NSUInteger port;
139 | @property (readwrite, assign) BOOL useSocket;
140 | @property (readwrite, retain) NSString *socketPath;
141 |
142 | @property (readwrite, assign) BOOL useSSL;
143 | @property (readwrite, retain) NSString *sslKeyFilePath;
144 | @property (readwrite, retain) NSString *sslCertificatePath;
145 | @property (readwrite, retain) NSString *sslCACertificatePath;
146 |
147 | @property (readwrite, assign) NSUInteger timeout;
148 | @property (readwrite, assign) BOOL useKeepAlive;
149 | @property (readwrite, assign) CGFloat keepAliveInterval;
150 |
151 | @property (readonly) unsigned long mysqlConnectionThreadId;
152 | @property (readwrite, assign) BOOL retryQueriesOnConnectionFailure;
153 |
154 | @property (readwrite, assign) BOOL delegateQueryLogging;
155 |
156 | @property (readwrite, assign) BOOL lastQueryWasCancelled;
157 |
158 | #pragma mark -
159 | #pragma mark Connection and disconnection
160 |
161 | - (BOOL)connect;
162 | - (BOOL)reconnect;
163 | - (void)disconnect;
164 |
165 | #pragma mark -
166 | #pragma mark Connection state
167 |
168 | - (BOOL)isConnected;
169 | - (BOOL)isConnectedViaSSL;
170 | - (BOOL)checkConnection;
171 | - (double)timeConnected;
172 | - (BOOL)userTriggeredDisconnect;
173 |
174 | #pragma mark -
175 | #pragma mark Connection utility
176 |
177 | + (NSString *)findSocketPath;
178 |
179 | @end
180 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Delegate & Proxy.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Delegate & Proxy.m 3631 2012-05-08 01:03:31Z rowanb@gmail.com $
3 | //
4 | // Delegate & Proxy.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 9, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #import "Delegate & Proxy.h"
34 | #import "SPMySQL Private APIs.h"
35 |
36 | @implementation SPMySQLConnection (Delegate_and_Proxy)
37 |
38 | #pragma mark -
39 | #pragma mark Connection delegate
40 |
41 | /**
42 | * Set the delegate of the connection object, precaching availability of
43 | * oft-called methods to allow optimisation.
44 | */
45 | - (void)setDelegate:(NSObject *)aDelegate
46 | {
47 | delegate = aDelegate;
48 |
49 | // Cache whether the delegate implements certain delegate methods
50 | delegateSupportsWillQueryString = [delegate respondsToSelector:@selector(willQueryString:connection:)];
51 | delegateSupportsConnectionLost = [delegate respondsToSelector:@selector(connectionLost:)];
52 | }
53 |
54 | /**
55 | * Return the current instance delegate.
56 | */
57 | - (NSObject *)delegate
58 | {
59 | return delegate;
60 | }
61 |
62 | #pragma mark -
63 | #pragma mark Connection proxy
64 |
65 | /**
66 | * Set the connection proxy, used by the class to set up a connection pre-requisite, and
67 | * monitored for state changes. This allows the MySQL connection to be routed over
68 | * another helper class providing a port or socket. This method also records the initial
69 | * state and sets the state change selector.
70 | */
71 | - (void)setProxy:(NSObject *)aProxy
72 | {
73 | proxy = [aProxy retain];
74 | previousProxyState = [aProxy state];
75 |
76 | [proxy setConnectionStateChangeSelector:@selector(_proxyStateChange:) delegate:self];
77 | }
78 |
79 | /**
80 | * Return the current instance proxy.
81 | */
82 | - (NSObject *)proxy
83 | {
84 | return proxy;
85 | }
86 |
87 | @end
88 |
89 | #pragma mark -
90 |
91 | @implementation SPMySQLConnection (Delegate_and_Proxy_Private_API)
92 |
93 | /**
94 | * Handle any state changes in the associated connection proxy.
95 | */
96 | - (void)_proxyStateChange:(NSObject *)aProxy
97 | {
98 |
99 | // Perform no actions if this isn't the current connection proxy, or if notifications
100 | // are currently set to be ignored
101 | if (aProxy != proxy || proxyStateChangeNotificationsIgnored) return;
102 |
103 | SPMySQLConnectionProxyState newState = [aProxy state];
104 |
105 | // If the connection proxy disconnects, trigger a reconnect; use a new thread to allow the
106 | // main thread to process events as required.
107 | if (state == SPMySQLConnected && newState == SPMySQLProxyIdle && previousProxyState == SPMySQLProxyConnected) {
108 |
109 | // Clear the state change selector on the proxy until a connection is re-established
110 | proxyStateChangeNotificationsIgnored = YES;
111 |
112 | // Trigger a reconnect depending on connection usage recently. If the connection has
113 | // actively been used in the last couple of minutes, trigger a full reconnection attempt.
114 | if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 60 * 2) {
115 | [NSThread detachNewThreadSelector:@selector(reconnect) toTarget:self withObject:nil];
116 |
117 | // If used within the last fifteen minutes, trigger a background/single reconnection attempt
118 | } else if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 60 * 15) {
119 | [NSThread detachNewThreadSelector:@selector(_reconnectAfterBackgroundConnectionLoss) toTarget:self withObject:nil];
120 |
121 | // Otherwise set the state to connection lost for automatic reconnect on next use
122 | } else {
123 | state = SPMySQLConnectionLostInBackground;
124 | }
125 | }
126 |
127 | // Update the state record
128 | previousProxyState = newState;
129 | }
130 |
131 | /**
132 | * Ask the delegate for the connection lost decision. This can be called from
133 | * any thread, and will call itself on the main thread if necessary, updating a global
134 | * variable which is then returned on the child thread.
135 | */
136 | - (SPMySQLConnectionLostDecision)_delegateDecisionForLostConnection
137 | {
138 | SPMySQLConnectionLostDecision theDecision = SPMySQLConnectionLostDisconnect;
139 |
140 | // If on the main thread, ask the delegate directly.
141 | if ([NSThread isMainThread]) {
142 | [delegateDecisionLock lock];
143 | lastDelegateDecisionForLostConnection = [delegate connectionLost:self];
144 | theDecision = lastDelegateDecisionForLostConnection;
145 | [delegateDecisionLock unlock];
146 |
147 | // Otherwise call ourself on the main thread, waiting until the reply is received.
148 | } else {
149 |
150 | // First check whether the application is in a modal state; if so, wait
151 | while ([NSApp modalWindow]) usleep(100000);
152 |
153 | [self performSelectorOnMainThread:@selector(_delegateDecisionForLostConnection) withObject:nil waitUntilDone:YES];
154 | [delegateDecisionLock lock];
155 | theDecision = lastDelegateDecisionForLostConnection;
156 | [delegateDecisionLock unlock];
157 | }
158 |
159 | return theDecision;
160 | }
161 |
162 | @end
163 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Server Info.m 3631 2012-05-08 01:03:31Z rowanb@gmail.com $
3 | //
4 | // Server Info.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 14, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | #import "Server Info.h"
35 | #import "SPMySQL Private APIs.h"
36 |
37 | @implementation SPMySQLConnection (Server_Info)
38 |
39 | #pragma mark -
40 | #pragma mark Server version information
41 |
42 | /**
43 | * Return the server version string, or nil on failure.
44 | */
45 | - (NSString *)serverVersionString
46 | {
47 | if (serverVersionString) {
48 | return [NSString stringWithString:serverVersionString];
49 | }
50 |
51 | return nil;
52 | }
53 |
54 | /**
55 | * Return the server major version or NSNotFound on failure
56 | */
57 | - (NSUInteger)serverMajorVersion
58 | {
59 |
60 | if (serverVersionString != nil) {
61 | NSString *s = [[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:0];
62 | return (NSUInteger)[s integerValue];
63 | }
64 |
65 | return NSNotFound;
66 | }
67 |
68 | /**
69 | * Return the server minor version or NSNotFound on failure
70 | */
71 | - (NSUInteger)serverMinorVersion
72 | {
73 | if (serverVersionString != nil) {
74 | NSString *s = [[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:1];
75 | return (NSUInteger)[s integerValue];
76 | }
77 |
78 | return NSNotFound;
79 | }
80 |
81 | /**
82 | * Return the server release version or NSNotFound on failure
83 | */
84 | - (NSUInteger)serverReleaseVersion
85 | {
86 | if (serverVersionString != nil) {
87 | NSString *s = [[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:2];
88 | return (NSUInteger)[[[s componentsSeparatedByString:@"-"] objectAtIndex:0] integerValue];
89 | }
90 |
91 | return NSNotFound;
92 | }
93 |
94 | #pragma mark -
95 | #pragma mark Server version comparisons
96 |
97 | /**
98 | * Returns whether the connected server version is greater than or equal to the
99 | * supplied version number. Returns NO if no connection is active.
100 | */
101 | - (BOOL)serverVersionIsGreaterThanOrEqualTo:(NSUInteger)aMajorVersion minorVersion:(NSUInteger)aMinorVersion releaseVersion:(NSUInteger)aReleaseVersion
102 | {
103 | if (!serverVersionString) return NO;
104 |
105 | NSArray *serverVersionParts = [serverVersionString componentsSeparatedByString:@"."];
106 |
107 | NSUInteger serverMajorVersion = (NSUInteger)[[serverVersionParts objectAtIndex:0] integerValue];
108 | if (serverMajorVersion < aMajorVersion) return NO;
109 | if (serverMajorVersion > aMajorVersion) return YES;
110 |
111 | NSUInteger serverMinorVersion = (NSUInteger)[[serverVersionParts objectAtIndex:1] integerValue];
112 | if (serverMinorVersion < aMinorVersion) return NO;
113 | if (serverMinorVersion > aMinorVersion) return YES;
114 |
115 | NSString *serverReleasePart = [serverVersionParts objectAtIndex:2];
116 | NSUInteger serverReleaseVersion = (NSUInteger)[[[serverReleasePart componentsSeparatedByString:@"-"] objectAtIndex:0] integerValue];
117 | if (serverReleaseVersion < aReleaseVersion) return NO;
118 | return YES;
119 | }
120 |
121 | #pragma mark -
122 | #pragma mark Server tasks & processes
123 |
124 | /**
125 | * Returns a result set describing the current server threads and their tasks. Note that
126 | * the resulting process list defaults to the short form; run a manual SHOW FULL PROCESSLIST
127 | * to retrieve tasks in non-truncated form.
128 | * Returns nil on error.
129 | */
130 | - (SPMySQLResult *)listProcesses
131 | {
132 | if (state != SPMySQLConnected) return nil;
133 |
134 | // Check the connection if appropriate
135 | if (![self _checkConnectionIfNecessary]) return nil;
136 |
137 | // Lock the connection before using it
138 | [self _lockConnection];
139 |
140 | // Ensure per-thread variables are set up
141 | [self _validateThreadSetup];
142 |
143 | // Get the process list
144 | MYSQL_RES *mysqlResult = mysql_list_processes(mySQLConnection);
145 | lastConnectionUsedTime = mach_absolute_time();
146 |
147 | // Convert to SPMySQLResult
148 | SPMySQLResult *theResult = [[SPMySQLResult alloc] initWithMySQLResult:mysqlResult stringEncoding:stringEncoding];
149 |
150 | // Unlock and return
151 | [self _unlockConnection];
152 | return [theResult autorelease];
153 | }
154 |
155 | /**
156 | * Kill the process with the supplied thread ID. On MySQL version 5 or later, this kills
157 | * the query; on older servers this kills the entire connection. Note that the SUPER
158 | * privilege is required to kill queries and processes not belonging to the currently
159 | * connected user, while only PROCESS is required to see other user's processes.
160 | * Returns a boolean indicating success or failure.
161 | */
162 | - (BOOL)killQueryOnThreadID:(unsigned long)theThreadID
163 | {
164 |
165 | // Note that mysql_kill has been deprecated, so use a query to perform this task.
166 | NSMutableString *killQuery = [NSMutableString stringWithString:@"KILL"];
167 | if ([self serverVersionIsGreaterThanOrEqualTo:5 minorVersion:0 releaseVersion:0]) {
168 | [killQuery appendString:@" QUERY"];
169 | }
170 | [killQuery appendFormat:@" %lu", theThreadID];
171 |
172 | // Run the query
173 | [self queryString:killQuery];
174 |
175 | // Return a value based on whether the query errored or not
176 | return ![self queryErrored];
177 | }
178 |
179 | @end
--------------------------------------------------------------------------------
/Sequel Pro/en.lproj/NTMasterViewController.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1536
5 | 12A206j
6 | 2519
7 | 1172.1
8 | 613.00
9 |
13 |
14 | IBProxyObject
15 | IBUITableView
16 |
17 |
18 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
19 |
20 |
24 |
25 |
29 |
33 |
77 |
78 |
79 |
80 |
81 |
82 | view
83 |
84 |
85 |
86 | 3
87 |
88 |
89 |
90 | dataSource
91 |
92 |
93 |
94 | 4
95 |
96 |
97 |
98 | delegate
99 |
100 |
101 |
102 | 5
103 |
104 |
105 |
106 |
107 |
108 | 0
109 |
110 |
111 |
112 |
113 |
114 | -1
115 |
116 |
117 | File's Owner
118 |
119 |
120 | -2
121 |
122 |
123 |
124 |
125 | 2
126 |
127 |
128 |
129 |
130 |
131 |
132 | NTMasterViewController
133 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
134 | UIResponder
135 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
136 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
137 |
138 |
139 |
140 |
141 |
142 | 5
143 |
144 |
145 | 0
146 | IBIPadFramework
147 | YES
148 | 3
149 | YES
150 | 1856
151 |
152 |
153 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/build-mysql-client.sh:
--------------------------------------------------------------------------------
1 | #! /bin/ksh
2 |
3 | #
4 | # $Id$
5 | #
6 | # build-mysql-client.sh
7 | # sequel-pro
8 | #
9 | # Created by Stuart Connolly (stuconnolly.com)
10 | # Copyright (c) 2009 Stuart Connolly. All rights reserved.
11 | #
12 | # This program is free software; you can redistribute it and/or modify
13 | # it under the terms of the GNU General Public License as published by
14 | # the Free Software Foundation; either version 2 of the License, or
15 | # (at your option) any later version.
16 | #
17 | # This program is distributed in the hope that it will be useful,
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | # GNU General Public License for more details.
21 | #
22 | # You should have received a copy of the GNU General Public License
23 | # along with this program; if not, write to the Free Software
24 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 | #
26 | # More info at
27 |
28 | # Builds the MySQL client libraries for distrubution in Sequel Pro's MySQL framework.
29 | #
30 | # Parameters: -s -- The path to the MySQL source directory.
31 | # -q -- Quiet. Don't output any compiler messages.
32 | # -c -- Clean the source instead of building it.
33 | # -d -- Debug. Output the build statements.
34 |
35 | QUIET='NO'
36 | DEBUG='NO'
37 | CLEAN='NO'
38 |
39 | # C/C++ compiler flags
40 | export CFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk -arch ppc -arch i386 -arch x86_64 -O3 -fno-omit-frame-pointer -fno-exceptions -mmacosx-version-min=10.5'
41 | export CXXFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk -arch ppc -arch i386 -arch x86_64 -O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti -mmacosx-version-min=10.5'
42 |
43 | CONFIGURE_OPTIONS='-DBUILD_CONFIG=mysql_release -DENABLED_LOCAL_INFILE=1 -DWITH_SSL=bundled -DWITH_MYSQLD_LDFLAGS="-all-static --disable-shared"'
44 | OUTPUT_DIR='SPMySQLFiles.build'
45 |
46 | set -A INCLUDE_HEADERS 'my_alloc.h' 'my_list.h' 'mysql_com.h' 'mysql_time.h' 'mysql_version.h' 'mysql.h' 'typelib.h'
47 | ESC=`printf '\033'`
48 |
49 | usage()
50 | {
51 | cat < [-q -c -d]
53 |
54 | Where: -s -- Path to the MySQL source directory
55 | -q -- Be quiet during the build. Suppress all compiler messages
56 | -c -- Clean the source directory instead of building
57 | -d -- Debug. Output all the build commands
58 | !EOF
59 | }
60 |
61 | # Test for cmake
62 | cmake --version > /dev/null 2>&1
63 | if [ ! $? -eq 0 ]
64 | then
65 | echo "$ESC[1;31mIn addition to the standard OS X build tools, '$ESC[0;1mcmake$ESC[1;31m' is required to compile the MySQL source. $ESC[0;1mcmake$ESC[1;31m is found at $ESC[0mcmake.org$ESC[1;31m, and a binary distribution is available from $ESC[0mhttp://www.cmake.org/cmake/resources/software.mhtml$ESC[1;31m ."
66 | echo "Exiting...$ESC[0m"
67 | exit 1
68 | fi
69 |
70 | if [ $# -eq 0 ]
71 | then
72 | echo "$ESC[1;31mInvalid number of arguments. I need the path to the MySQL source directory.$ESC[0m"
73 | echo ''
74 | usage
75 | exit 1
76 | fi
77 |
78 |
79 | while getopts ':s:qcd' OPTION
80 | do
81 | case "$OPTION" in
82 | s) MYSQL_SOURCE_DIR="$OPTARG";;
83 | q) QUIET='YES';;
84 | c) CLEAN='YES';;
85 | d) DEBUG='YES';;
86 | *) echo "$ESC[1;31mUnrecognised option$ESC[0m"; usage; exit 1;;
87 | esac
88 | done
89 |
90 | if [ ! -d "$MYSQL_SOURCE_DIR" ]
91 | then
92 | echo "$ESC[1;31mMySQL source directory does not exist at path '${MYSQL_SOURCE_DIR}'.$ESC[0m"
93 | echo "$ESC[1;31mExiting...$ESC[0m"
94 | exit 1
95 | fi
96 |
97 | # Change to source directory
98 | if [ "x${DEBUG}" == 'xYES' ]
99 | then
100 | echo "cd ${MYSQL_SOURCE_DIR}"
101 | fi
102 | cd "$MYSQL_SOURCE_DIR"
103 |
104 | # Perform a clean if requested
105 | if [ "x${CLEAN}" == 'xYES' ]
106 | then
107 | echo "$ESC[1mCleaning MySQL source and builds...$ESC[0m"
108 |
109 | if [ "x${QUIET}" == 'xYES' ]
110 | then
111 | make clean > /dev/null
112 | if [ -f 'CMakeCache.txt' ]; then rm 'CMakeCache.txt' > /dev/null; fi
113 | if [ -d "$OUTPUT_DIR" ]; then rm -rf "$OUTPUT_DIR" > /dev/null; fi
114 | else
115 | make clean
116 | if [ -f 'CMakeCache.txt' ]; then rm 'CMakeCache.txt'; fi
117 | if [ -d "$OUTPUT_DIR" ]; then rm -rf "$OUTPUT_DIR" > /dev/null; fi
118 | fi
119 |
120 | echo "$ESC[1mCleaning MySQL completed.$ESC[0m"
121 |
122 | exit 0
123 | fi
124 |
125 | echo ''
126 | echo "This script builds the MySQL client libraries for distribution in Sequel Pro's MySQL framework."
127 | echo 'They are all built as 3-way binaries (32 bit PPC, 32/64 bit i386).'
128 | echo ''
129 | echo -n "$ESC[1mThis may take a while, are you sure you want to continue [y | n]: $ESC[0m"
130 |
131 | read CONTINUE
132 |
133 | if [ "x${CONTINUE}" == 'xn' ]
134 | then
135 | echo "$ESC[31mAborting...$ESC[0m"
136 | exit 0
137 | fi
138 |
139 |
140 | echo "$ESC[1mConfiguring MySQL source...$ESC[0m"
141 |
142 | if [ "x${DEBUG}" == 'xYES' ]
143 | then
144 | echo "cmake ${CONFIGURE_OPTIONS} ."
145 | fi
146 |
147 | if [ "x${QUIET}" == 'xYES' ]
148 | then
149 | cmake $CONFIGURE_OPTIONS . > /dev/null
150 | else
151 | cmake $CONFIGURE_OPTIONS .
152 | fi
153 |
154 | if [ $? -eq 0 ]
155 | then
156 | echo "$ESC[1mConfigure successfully completed$ESC[0m"
157 | else
158 | echo "$ESC[1;31mConfigure failed. Exiting...$ESC[0m"
159 | exit 1
160 | fi
161 |
162 | if [ "x${DEBUG}" == 'xYES' ]
163 | then
164 | echo "make mysqlclient"
165 | fi
166 |
167 | echo "$ESC[1mBuilding client libraries...$ESC[0m"
168 |
169 | if [ "x${QUIET}" == 'xYES' ]
170 | then
171 | make mysqlclient > /dev/null
172 | else
173 | make mysqlclient
174 | fi
175 |
176 | if [ $? -eq 0 ]
177 | then
178 | echo "$ESC[1mBuilding libraries successfully completed$ESC[0m"
179 | else
180 | echo "$ESC[1;31mBuilding libraries failed. Exiting...$ESC[0m"
181 | exit 1
182 | fi
183 |
184 | echo "$ESC[1mPutting together files for distribution...$ESC[0m"
185 |
186 | # Create the appropriate directories
187 | if [ ! -d "$OUTPUT_DIR" ]
188 | then
189 | mkdir "$OUTPUT_DIR"
190 | if [ ! $? -eq 0 ]
191 | then
192 | echo "$ESC[1;31mCould not create $OUTPUT_DIR output directory!$ESC[0m"
193 | exit 1
194 | fi
195 | fi
196 | if [ ! -d "${OUTPUT_DIR}/lib" ]
197 | then
198 | mkdir "${OUTPUT_DIR}/lib"
199 | if [ ! $? -eq 0 ]
200 | then
201 | echo "$ESC[1;31mCould not create ${OUTPUT_DIR}/lib output directory!$ESC[0m"
202 | exit 1
203 | fi
204 | fi
205 | if [ ! -d "${OUTPUT_DIR}/include" ]
206 | then
207 | mkdir "${OUTPUT_DIR}/include"
208 | if [ ! $? -eq 0 ]
209 | then
210 | echo "$ESC[1;31mCould not create ${OUTPUT_DIR}/include output directory!$ESC[0m"
211 | exit 1
212 | fi
213 | fi
214 |
215 | # Copy the library
216 | cp 'libmysql/libmysqlclient.a' "${OUTPUT_DIR}/lib/"
217 | if [ ! $? -eq 0 ]
218 | then
219 | echo "$ESC[1;31mCould not copy libmysqlclient.a to output directory! (${MYSQL_SOURCE_DIR}/${OUTPUT_DIR}/lib)$ESC[0m"
220 | exit 1
221 | fi
222 |
223 | # Copy in the required headers
224 | for eachheader in ${INCLUDE_HEADERS[@]}
225 | do
226 | cp "include/${eachheader}" "${OUTPUT_DIR}/include/"
227 | if [ ! $? -eq 0 ]
228 | then
229 | echo "$ESC[1;31mCould not copy ${eachheader} to output directory! (${MYSQL_SOURCE_DIR}/${OUTPUT_DIR}/include)$ESC[0m"
230 | exit 1
231 | fi
232 | done
233 |
234 |
235 | echo "$ESC[1mBuilding MySQL client libraries successfully completed.$ESC[0m"
236 | echo "$ESC[1mSee ${MYSQL_SOURCE_DIR}/${OUTPUT_DIR}/ for the product.$ESC[0m"
237 |
238 | exit 0
239 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Max Packet Size.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Max Packet Size.m 3511 2012-03-17 15:32:00Z rowanb@gmail.com $
3 | //
4 | // Max Packet Size.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 9, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | #import "Max Packet Size.h"
35 | #import "SPMySQL Private APIs.h"
36 |
37 | @implementation SPMySQLConnection (Max_Packet_Size)
38 |
39 | /**
40 | * Retrieve the current maximum query size (MySQL's max_allowed_packet), as cached
41 | * by the class. If the connection has been unable to retrieve this value, the
42 | * default of 1MB will be returned.
43 | */
44 | - (NSUInteger)maxQuerySize
45 | {
46 | return maxQuerySize;
47 | }
48 |
49 | /**
50 | * Retrieve whether the server's maximum query size (MySQL's max_allowed_packet) is
51 | * editable by the current user.
52 | */
53 | - (BOOL)isMaxQuerySizeEditable
54 | {
55 | if (!maxQuerySizeEditabilityChecked) {
56 | [self _updateMaxQuerySizeEditability];
57 | }
58 |
59 | return maxQuerySizeIsEditable;
60 | }
61 |
62 | /**
63 | * Set the servers's global maximum query size - MySQL's max_allowed_packed - to the
64 | * supplied size. Note that this *does not* affect the current connection; a reconnection
65 | * is required to pick up the new size setting. As a result it may be important to restore
66 | * the connection size after use.
67 | * Validates the supplied size (eg 1GB limit) and applies it if appropriate, returning
68 | * the set query size or NSNotFound on error.
69 | */
70 | - (NSUInteger)setGlobalMaxQuerySize:(NSUInteger)newMaxSize
71 | {
72 |
73 | // Perform basic validation. First, ensure the max query size is editable
74 | if (![self isMaxQuerySizeEditable]) return NSNotFound;
75 |
76 | // Validate sizes
77 | if (newMaxSize < 1024) return NSNotFound;
78 | if (newMaxSize > (1024 * 1024 * 1024)) newMaxSize = 1024 * 1024 * 1024;
79 |
80 | // Perform a standard query to set the new size
81 | [self queryString:[NSString stringWithFormat:@"SET GLOBAL max_allowed_packet = %lu", newMaxSize]];
82 |
83 | // On failure, return NSNotFound - error state will have automatically been set
84 | if ([self queryErrored]) return NSNotFound;
85 |
86 | // Otherwise, set the local instance variable and return success
87 | maxQuerySize = newMaxSize;
88 | return maxQuerySize;
89 | }
90 |
91 | @end
92 |
93 | #pragma mark -
94 |
95 | @implementation SPMySQLConnection (Max_Packet_Size_Private_API)
96 |
97 | /**
98 | * Update the max_allowed_packet size - the largest supported query size - from the server.
99 | */
100 | - (void)_updateMaxQuerySize
101 | {
102 |
103 | // Determine which query to run based on server version
104 | NSString *packetQueryString;
105 | if ([self serverMajorVersion] == 3) {
106 | packetQueryString = @"SHOW VARIABLES LIKE 'max_allowed_packet'";
107 | } else {
108 | packetQueryString = @"SELECT @@global.max_allowed_packet";
109 | }
110 |
111 | // Make a standard query to the server to retrieve the information
112 | SPMySQLResult *result = [self queryString:packetQueryString];
113 | [result setReturnDataAsStrings:YES];
114 |
115 | // Get the maximum size string
116 | NSString *maxQuerySizeString = nil;
117 | if ([self serverMajorVersion] == 3) {
118 | maxQuerySizeString = [[result getRowAsArray] objectAtIndex:1];
119 | } else {
120 | maxQuerySizeString = [[result getRowAsArray] objectAtIndex:0];
121 | }
122 |
123 | // If a valid size was returned, update the instance variable
124 | if (maxQuerySizeString) {
125 | maxQuerySize = (NSUInteger)[maxQuerySizeString integerValue];
126 | }
127 | }
128 |
129 | /**
130 | * Perform a query to determine whether the current user has permission to edit the
131 | * max_allowed_packet setting for their connection.
132 | */
133 | - (void)_updateMaxQuerySizeEditability
134 | {
135 | [self queryString:@"SET GLOBAL max_allowed_packet = @@global.max_allowed_packet"];
136 | maxQuerySizeIsEditable = ![self queryErrored];
137 | maxQuerySizeEditabilityChecked = YES;
138 | }
139 |
140 | /**
141 | * Attempts to change the maximum query size in order to allow a query to be performed.
142 | * Returns whether the change was successfully made.
143 | */
144 | - (BOOL)_attemptMaxQuerySizeIncreaseTo:(NSUInteger)targetSize
145 | {
146 |
147 | // If the query size is editable, attempt to increase the size
148 | if ([self isMaxQuerySizeEditable]) {
149 | NSUInteger newSize = [self setGlobalMaxQuerySize:targetSize];
150 | if (newSize != NSNotFound) {
151 |
152 | // Successfully increased the global size - reconnect to use it, and return success
153 | [self reconnect];
154 | return YES;
155 | }
156 | }
157 |
158 | // Can not, or failed to, increase the max query size. Record an error message.
159 | NSString *errorMessage = [NSString stringWithFormat:NSLocalizedString(@"The query length of %lu bytes is larger than max_allowed_packet size (%lu).", @"error message if max_allowed_packet < query size"), targetSize, maxQuerySize];
160 | [self _updateLastErrorMessage:errorMessage];
161 |
162 | // Update delegate error if it supports the protocol
163 | if ([delegate respondsToSelector:@selector(queryGaveError:connection:)]) {
164 | [delegate queryGaveError:errorMessage connection:self];
165 | }
166 |
167 | // Display an alert as this is a special failure
168 | if ([delegate respondsToSelector:@selector(showErrorWithTitle:message:)]) {
169 | [delegate showErrorWithTitle:NSLocalizedString(@"Error", @"error") message:errorMessage];
170 | } else {
171 | NSRunAlertPanel(NSLocalizedString(@"Error", @"error"), errorMessage, @"OK", nil, nil);
172 | }
173 |
174 | return NO;
175 | }
176 |
177 | /**
178 | * Restore a maximum query size after temporarily increasing it for a query. This action
179 | * may be called directly after a query, or may be before the next query if a streaming result
180 | * had to be used.
181 | */
182 | - (void)_restoreMaximumQuerySizeAfterQuery
183 | {
184 |
185 | // Return if no action needs to be performed
186 | if (queryActionShouldRestoreMaxQuerySize == NSNotFound) return;
187 |
188 | // Move the target size to a local variable to prevent looping
189 | NSUInteger targetMaxQuerySize = queryActionShouldRestoreMaxQuerySize;
190 | queryActionShouldRestoreMaxQuerySize = NSNotFound;
191 |
192 | // Enact the change
193 | [self setGlobalMaxQuerySize:targetMaxQuerySize];
194 | }
195 |
196 | @end
197 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLStreamingResult.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLStreamingResult.m 3578 2012-04-09 16:37:31Z rowanb@gmail.com $
3 | //
4 | // SPMySQLStreamingResult.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 18, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #import "SPMySQLStreamingResult.h"
34 | #import "SPMySQL Private APIs.h"
35 |
36 |
37 | /**
38 | * This type of streaming result allows each row to be accessed on-demand; this can
39 | * be dangerous as it means a SELECT will tie up the server for longer, as for MyISAM
40 | * tables updates (and subsequent reads) must block while a SELECT is still running.
41 | * However this can be useful for certain processes such as working with very large
42 | * tables to keep memory usage low.
43 | */
44 |
45 | @implementation SPMySQLStreamingResult
46 |
47 | #pragma mark -
48 |
49 | /**
50 | * Prevent SPMySQLStreamingResults from being init'd as SPMySQLResults.
51 | */
52 | - (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding
53 | {
54 | [NSException raise:NSInternalInconsistencyException format:@"SPMySQLFullStreamingResults should not be init'd as SPMySQLResults; use initWithMySQLResult:stringEncoding:connection:withFullStreaming: instead."];
55 | return nil;
56 | }
57 |
58 | /**
59 | * Standard init method, constructing the SPMySQLStreamingResult around a MySQL
60 | * result pointer and the encoding to use when working with the data.
61 | * As opposed to SPMySQLResult, defaults to returning rows as arrays, as the result
62 | * sets are likely to be larger and processed in loops.
63 | */
64 | - (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection
65 | {
66 |
67 | // If no result set was passed in, return nil.
68 | if (!theResult) return nil;
69 |
70 | if ((self = [super initWithMySQLResult:theResult stringEncoding:theStringEncoding])) {
71 | parentConnection = theConnection;
72 | numberOfRows = NSNotFound;
73 |
74 | // Start with no rows downloaded
75 | downloadedRowCount = 0;
76 | dataDownloaded = NO;
77 | connectionUnlocked = NO;
78 |
79 | // Cache the isConnected selector and pointer for fast connection checks
80 | isConnectedSelector = @selector(isConnected);
81 | isConnectedPtr = [parentConnection methodForSelector:isConnectedSelector];
82 |
83 | // Default to returning rows as arrays
84 | defaultRowReturnType = SPMySQLResultRowAsArray;
85 | }
86 |
87 | return self;
88 | }
89 |
90 | /**
91 | * Deallocate the result and ensure the parent connection is unlocked for further use.
92 | */
93 | - (void)dealloc
94 | {
95 |
96 | // Ensure all data is processed and the parent connection is unlocked
97 | [self cancelResultLoad];
98 |
99 | // Throw an exception if in invalid state
100 | if (!connectionUnlocked) {
101 | [parentConnection _unlockConnection];
102 | [NSException raise:NSInternalInconsistencyException format:@"Parent connection remains locked after SPMySQLStreamingResult use"];
103 | }
104 |
105 | [super dealloc];
106 | }
107 |
108 | #pragma mark -
109 | #pragma mark Result set information
110 |
111 | /**
112 | * Override the return of the number of rows in the data set. If this is used before the
113 | * data is fully downloaded, the number of results is still unknown (the server may still
114 | * be seeking/matching), so return NSNotFound; otherwise the number of rows is returned.
115 | */
116 | - (unsigned long long)numberOfRows
117 | {
118 | if (!dataDownloaded) return NSNotFound;
119 |
120 | return downloadedRowCount;
121 | }
122 |
123 | #pragma mark -
124 | #pragma mark Data retrieval
125 |
126 | /**
127 | * Override seeking behaviour: seeking cannot be used in streaming result sets.
128 | */
129 | - (void)seekToRow:(unsigned long long)targetRow
130 | {
131 | [NSException raise:NSInternalInconsistencyException format:@"Seeking is not supported in streaming SPMySQL result sets."];
132 | }
133 |
134 | /**
135 | * Override the convenience selectors so that forwarding works correctly.
136 | */
137 | - (id)getRow
138 | {
139 | return SPMySQLResultGetRow(self, SPMySQLResultRowAsDefault);
140 | }
141 | - (NSArray *)getRowAsArray
142 | {
143 | return SPMySQLResultGetRow(self, SPMySQLResultRowAsArray);
144 | }
145 | - (NSDictionary *)getRowAsDictionary
146 | {
147 | return SPMySQLResultGetRow(self, SPMySQLResultRowAsDictionary);
148 | }
149 |
150 | /**
151 | * Retrieve the next row in the result set, using the internal pointer, in the specified
152 | * return format.
153 | * If there are no rows remaining in the current iteration, returns nil.
154 | */
155 | - (id)getRowAsType:(SPMySQLResultRowType)theType
156 | {
157 | id theRow = nil;
158 |
159 | // Ensure that the connection is still up before performing a row fetch
160 | if ((*isConnectedPtr)(parentConnection, isConnectedSelector)) {
161 |
162 | // The core of result fetching in streaming mode is still based around mysql_fetch_row,
163 | // so use the super to perform normal processing.
164 | theRow = [super getRowAsType:theType];
165 | }
166 |
167 | // If no row was returned, the end of the result set has been reached. Clear markers,
168 | // unlock the parent connection, and return nil.
169 | if (!theRow) {
170 | dataDownloaded = YES;
171 | [parentConnection _unlockConnection];
172 | connectionUnlocked = YES;
173 |
174 | // If the connection query may have been cancelled with a query kill, double-check connection
175 | if ([parentConnection lastQueryWasCancelled] && [parentConnection serverMajorVersion] < 5) {
176 | [parentConnection checkConnection];
177 | }
178 |
179 | return nil;
180 | }
181 |
182 | // Otherwise increment the data downloaded counter and return the row
183 | downloadedRowCount++;
184 |
185 | return theRow;
186 | }
187 |
188 | /*
189 | * Ensure the result set is fully processed and freed without any processing
190 | * This method ensures that the connection is unlocked.
191 | */
192 | - (void)cancelResultLoad
193 | {
194 |
195 | // If data has already been downloaded successfully, no further action is required
196 | if (dataDownloaded) return;
197 |
198 | MYSQL_ROW theRow;
199 |
200 | // Loop through all the rows and ensure the rows are fetched.
201 | while (1) {
202 | theRow = mysql_fetch_row(resultSet);
203 |
204 | // If no data was returned, we're at the end of the result set - return.
205 | if (theRow == NULL) {
206 | dataDownloaded = YES;
207 | if (!connectionUnlocked) {
208 | [parentConnection _unlockConnection];
209 | connectionUnlocked = YES;
210 | }
211 | return;
212 | }
213 |
214 | downloadedRowCount++;
215 | }
216 | }
217 |
218 | #pragma mark -
219 | #pragma mark Data retrieval for fast enumeration
220 |
221 | /**
222 | * Implement the fast enumeration endpoint. Rows for fast enumeration are retrieved in
223 | * the instance default, as specified in setDefaultRowReturnType: or defaulting to
224 | * NSDictionary. Full streaming mode - return one row at a time.
225 | */
226 | - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
227 | {
228 |
229 | // If all rows have been retrieved, return 0 to stop iteration.
230 | if (dataDownloaded) return 0;
231 |
232 | // If the MySQL row pointer does not match the requested state, throw an exception
233 | if (state->state != currentRowIndex) {
234 | [NSException raise:NSRangeException format:@"SPMySQLStreamingResult results can only be accessed linearly"];
235 | }
236 |
237 | // In full streaming mode return one row at a time. Retrieve the row.
238 | id theRow = SPMySQLResultGetRow(self, SPMySQLResultRowAsDefault);
239 |
240 | // If nil was returned the end of the result resource has been reached
241 | if (!theRow) return 0;
242 |
243 | // Add the row to the result stack and update state
244 | stackbuf[0] = theRow;
245 | state->state += 1;
246 | state->itemsPtr = stackbuf;
247 | state->mutationsPtr = (unsigned long *)self;
248 |
249 | return 1;
250 | }
251 |
252 | @end
253 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Ping & KeepAlive.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Ping & KeepAlive.m 3658 2012-05-15 23:40:08Z rowanb@gmail.com $
3 | //
4 | // Ping & KeepAlive.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on January 14, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 |
34 | #import "Ping & KeepAlive.h"
35 | #import "SPMySQL Private APIs.h"
36 | #import "Locking.h"
37 | #import
38 |
39 | @implementation SPMySQLConnection (Ping_and_KeepAlive)
40 |
41 | #pragma mark -
42 | #pragma mark Keepalive ping initialisation
43 |
44 | /**
45 | * Keeps the connection alive by running a ping.
46 | * This method is called every ten seconds and spawns a thread which determines
47 | * whether or not it should perform a ping.
48 | */
49 | - (void)_keepAlive
50 | {
51 |
52 | // Do nothing if not connected, if keepalive is disabled, or a keepalive is in
53 | // progress.
54 | if (state != SPMySQLConnected || !useKeepAlive) return;
55 |
56 | // Check to see whether a ping is required. First, compare the last query
57 | // and keepalive times against the keepalive interval.
58 | // Compare against interval-1 to allow default keepalive intervals to repeat
59 | // at the correct intervals (eg no timer interval delay).
60 | uint64_t currentTime = mach_absolute_time();
61 | if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < keepAliveInterval - 1
62 | || _elapsedSecondsSinceAbsoluteTime(lastKeepAliveTime) < keepAliveInterval - 1)
63 | {
64 | return;
65 | }
66 |
67 | // Attempt to lock the connection. If the connection is currently busy,
68 | // we don't need a ping.
69 | if (![self _tryLockConnection]) return;
70 | [self _unlockConnection];
71 |
72 | // Store the ping time
73 | lastKeepAliveTime = currentTime;
74 |
75 | [NSThread detachNewThreadSelector:@selector(_threadedKeepAlive) toTarget:self withObject:nil];
76 | }
77 |
78 | /**
79 | * A threaded keepalive to avoid blocking the interface. Performs safety
80 | * checks, and then creates a child pthread to actually ping the connection,
81 | * forcing the thread to close after the timeout if it hasn't closed already.
82 | */
83 | - (void)_threadedKeepAlive
84 | {
85 | keepAliveThread = [NSThread currentThread];
86 |
87 | // If the maximum number of ping failures has been reached, determine whether to reconnect.
88 | if (keepAliveLastPingBlocked || keepAlivePingFailures >= 3) {
89 |
90 | // If the connection has been used within the last fifteen minutes,
91 | // attempt a single reconnection in the background
92 | if (_elapsedSecondsSinceAbsoluteTime(lastConnectionUsedTime) < 60 * 15) {
93 | [self _reconnectAfterBackgroundConnectionLoss];
94 |
95 | // Otherwise set the state to connection lost for automatic reconnect on
96 | // next use.
97 | } else {
98 | state = SPMySQLConnectionLostInBackground;
99 | }
100 |
101 | // Return as no further ping action required this cycle.
102 | keepAliveThread = nil;
103 | return;
104 | }
105 |
106 | // Otherwise, perform a background ping.
107 | BOOL pingResult = [self _pingConnectionUsingLoopDelay:10000];
108 | if (pingResult) {
109 | keepAlivePingFailures = 0;
110 | } else {
111 | keepAlivePingFailures++;
112 | }
113 | keepAliveThread = nil;
114 | }
115 |
116 | #pragma mark -
117 | #pragma mark Master ping method
118 |
119 | /**
120 | * This function provides a method of pinging the remote server while also enforcing
121 | * the specified connection time. This is required because low-level net reads can
122 | * block indefinitely if the remote server disappears or on network issues - setting
123 | * the MYSQL_OPT_READ_TIMEOUT (and the WRITE equivalent) would "fix" ping, but cause
124 | * long queries to be terminated.
125 | * The supplied loop delay number controls how tight the thread checking loop is, in
126 | * microseconds, to allow differentiating foreground and background pings.
127 | * Unlike mysql_ping, this function returns FALSE on failure and TRUE on success.
128 | */
129 | - (BOOL)_pingConnectionUsingLoopDelay:(NSUInteger)loopDelay
130 | {
131 | if (state != SPMySQLConnected) return NO;
132 |
133 | uint64_t pingStartTime_t;
134 | double pingElapsedTime;
135 | BOOL threadCancelled = NO;
136 |
137 | // Set up a query lock
138 | [self _lockConnection];
139 |
140 | keepAliveLastPingSuccess = NO;
141 | keepAliveLastPingBlocked = NO;
142 | keepAlivePingThreadActive = YES;
143 |
144 | // Use a ping timeout defaulting to thirty seconds, but using the connection timeout if set
145 | NSUInteger pingTimeout = 30;
146 | if (timeout > 0) pingTimeout = timeout;
147 |
148 | // Set up a struct containing details the ping task will need
149 | SPMySQLConnectionPingDetails *pingDetails = malloc(sizeof(SPMySQLConnectionPingDetails));
150 | pingDetails->mySQLConnection = mySQLConnection;
151 | pingDetails->keepAliveLastPingSuccessPointer = &keepAliveLastPingSuccess;
152 | pingDetails->keepAlivePingActivePointer = &keepAlivePingThreadActive;
153 |
154 | // Create a pthread for the ping
155 | pthread_attr_t attr;
156 | pthread_attr_init(&attr);
157 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
158 | pthread_create(&keepAlivePingThread_t, &attr, (void *)&_backgroundPingTask, pingDetails);
159 |
160 | // Record the ping start time
161 | pingStartTime_t = mach_absolute_time();
162 |
163 | // Loop until the ping completes
164 | do {
165 | usleep((useconds_t)loopDelay);
166 | pingElapsedTime = _elapsedSecondsSinceAbsoluteTime(pingStartTime_t);
167 |
168 | // If the ping timeout has been exceeded, or the ping thread has been
169 | // cancelled, force a timeout; double-check that the thread is still active.
170 | if (([keepAliveThread isCancelled] || pingElapsedTime > pingTimeout)
171 | && keepAlivePingThreadActive
172 | && !threadCancelled)
173 | {
174 | pthread_cancel(keepAlivePingThread_t);
175 | threadCancelled = YES;
176 |
177 | // If the timeout has been exceeded by an additional two seconds, and the thread is
178 | // still active, kill the thread. This can occur in certain network conditions causing
179 | // a blocking read.
180 | } else if (pingElapsedTime > (pingTimeout + 2) && keepAlivePingThreadActive) {
181 | pthread_kill(keepAlivePingThread_t, SIGUSR1);
182 | keepAlivePingThreadActive = NO;
183 | keepAliveLastPingBlocked = YES;
184 | }
185 | } while (keepAlivePingThreadActive);
186 |
187 | // Clean up
188 | keepAlivePingThread_t = NULL;
189 | pthread_attr_destroy(&attr);
190 | free(pingDetails);
191 |
192 | // Unlock the connection
193 | [self _unlockConnection];
194 |
195 | return keepAliveLastPingSuccess;
196 | }
197 |
198 | #pragma mark -
199 | #pragma mark Ping thread internals
200 |
201 | /**
202 | * Actually perform a keepalive ping - intended for use within a pthread.
203 | */
204 | void _backgroundPingTask(void *ptr)
205 | {
206 | SPMySQLConnectionPingDetails *pingDetails = (SPMySQLConnectionPingDetails *)ptr;
207 |
208 | // Set up a cleanup routine
209 | pthread_cleanup_push(_pingThreadCleanup, pingDetails);
210 |
211 | // Initialise MySQL variables and handling on this thread
212 | mysql_thread_init();
213 |
214 | // Set up a signal handler for SIGUSR1, to handle forced timeouts.
215 | signal(SIGUSR1, _forceThreadExit);
216 |
217 | // Perform a ping
218 | *(pingDetails->keepAliveLastPingSuccessPointer) = (BOOL)(!mysql_ping(pingDetails->mySQLConnection));
219 |
220 | // Call the cleanup routine
221 | pthread_cleanup_pop(1);
222 | }
223 |
224 | /**
225 | * Support forcing a thread to exit as a result of a signal.
226 | */
227 | void _forceThreadExit(int signalNumber)
228 | {
229 | pthread_exit(NULL);
230 | }
231 |
232 | /**
233 | * A thread cleanup routine. This is added to the thread using a
234 | * pthread_cleanup_push call; a pthread_exit or a pthread_cleanup_pop
235 | * both execute this function.
236 | */
237 | void _pingThreadCleanup(void *pingDetails)
238 | {
239 | SPMySQLConnectionPingDetails *pingDetailsStruct = pingDetails;
240 | *(pingDetailsStruct->keepAlivePingActivePointer) = NO;
241 |
242 | // Clean up MySQL variables and handlers
243 | mysql_thread_end();
244 | }
245 |
246 | #pragma mark -
247 | #pragma mark Cancellation
248 |
249 | /**
250 | * If a keepalive thread is active, cancel it, and wait a short time for it
251 | * to exit.
252 | */
253 | - (void)_cancelKeepAlives
254 | {
255 |
256 | // If no keepalive thread is active, return
257 | if (!keepAliveThread) {
258 | return;
259 | }
260 |
261 | // Mark the thread as cancelled
262 | [keepAliveThread cancel];
263 |
264 | // Wait inside a time limit of ten seconds for it to exit
265 | uint64_t threadCancelStartTime_t = mach_absolute_time();
266 | do {
267 | usleep(100000);
268 | if (_elapsedSecondsSinceAbsoluteTime(threadCancelStartTime_t) > 10) break;
269 | } while (keepAliveThread);
270 | }
271 |
272 | @end
273 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Databases & Tables.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: Databases & Tables.m 3558 2012-03-28 20:41:42Z sqlprodev@gmail.com $
3 | //
4 | // Databases & Tables.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 11, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #import "Databases & Tables.h"
34 | #import "SPMySQL Private APIs.h"
35 | #import "SPMySQLStringAdditions.h"
36 |
37 | @implementation SPMySQLConnection (Databases_and_Tables)
38 |
39 | #pragma mark -
40 | #pragma mark Database selection
41 |
42 | /**
43 | * Selects the database the connection should work with. Typically, a database should be
44 | * set on a connection before any database-specific queries are run.
45 | * Returns whether the database was correctly set or not.
46 | * As MySQL does not support deselecting databases, a nil databaseName will return NO.
47 | */
48 | - (BOOL)selectDatabase:(NSString *)aDatabase
49 | {
50 |
51 | // If no database was supplied, can't deselected - return NO.
52 | if (!aDatabase) return NO;
53 |
54 | // Database selection should be made in UTF8 to avoid name encoding issues
55 | BOOL encodingChangeRequired = [self _storeAndAlterEncodingToUTF8IfRequired];
56 |
57 | // Attempt to select the supplied database
58 | [self queryString:[NSString stringWithFormat:@"USE %@", [aDatabase mySQLBacktickQuotedString]]];
59 |
60 | // If selecting the database failed, return failure.
61 | if ([self queryErrored]) {
62 |
63 | // If the encoding needs to be restored, the error message and ID have to be stored so the
64 | // actual error is still available to inspect on the class...
65 | if (encodingChangeRequired) {
66 | NSString *theErrorString = [self lastErrorMessage];
67 | NSUInteger theErrorID = [self lastErrorID];
68 |
69 | [self restoreStoredEncoding];
70 |
71 | [self _updateLastErrorMessage:theErrorString];
72 | [self _updateLastErrorID:theErrorID];
73 | }
74 |
75 | return NO;
76 | }
77 |
78 | // Restore the connection encoding if necessary
79 | if (encodingChangeRequired) [self restoreStoredEncoding];
80 |
81 | // Store new database name and return success
82 | if (database) [database release];
83 | database = [[NSString alloc] initWithString:aDatabase];
84 |
85 | return YES;
86 | }
87 |
88 | #pragma mark -
89 | #pragma mark Database lists
90 |
91 | /**
92 | * Retrieve an array of databases available to the current user, ordered as MySQL
93 | * returns them.
94 | * If an error occurred while retrieving the list of databases, nil will be returned;
95 | * if no databases are available, an empty array will be returned.
96 | */
97 | - (NSArray *)databases
98 | {
99 |
100 | // Wrap the related databasesLike: function to avoid code duplication
101 | return [self databasesLike:nil];
102 | }
103 |
104 | /**
105 | * Retrieve an array of databases whose names are matched against the supplied name
106 | * using MySQL LIKE syntax (with wildcard support for % and _). If no name is supplied,
107 | * all databases will be returned, in the order that MySQL returns them.
108 | * If an error occurred while retrieving the list of databases, nil will be returned;
109 | * if no matching databases are available, an empty array will be returned.
110 | */
111 | - (NSArray *)databasesLike:(NSString *)nameLikeString
112 | {
113 | NSMutableArray *databaseList = nil;
114 |
115 | // Database display should be made in UTF8 to avoid name encoding issues
116 | BOOL encodingChangeRequired = [self _storeAndAlterEncodingToUTF8IfRequired];
117 |
118 | // Build the query as appropriate
119 | NSMutableString *databaseQuery = [NSMutableString stringWithString:@"SHOW DATABASES"];
120 | if ([nameLikeString length]) {
121 | [databaseQuery appendFormat:@" LIKE %@", [nameLikeString mySQLTickQuotedString]];
122 | }
123 |
124 | // Perform the query and record state
125 | SPMySQLResult *databaseResult = [self queryString:databaseQuery];
126 | [databaseResult setDefaultRowReturnType:SPMySQLResultRowAsArray];
127 |
128 | // Retrieve the result into an array if the query was successful
129 | if (![self queryErrored]) {
130 | databaseList = [NSMutableArray arrayWithCapacity:(NSUInteger)[databaseResult numberOfRows]];
131 | for (NSArray *dbRow in databaseResult) {
132 | [databaseList addObject:[dbRow objectAtIndex:0]];
133 | }
134 | }
135 |
136 | // Restore the connection encoding if necessary
137 | if (encodingChangeRequired) [self restoreStoredEncoding];
138 |
139 | return databaseList;
140 | }
141 |
142 | #pragma mark -
143 | #pragma mark Table lists
144 |
145 | /**
146 | * Retrieve an array of tables in the currently selected database, ordered as MySQL
147 | * returns them.
148 | * If an error occurred while retrieving the list of tables, nil will be returned;
149 | * if no tables are present, an empty array will be returned.
150 | */
151 | - (NSArray *)tables
152 | {
153 |
154 | // Wrap the related tablesLike:fromDatabase: function to avoid code duplication
155 | return [self tablesLike:nil fromDatabase:nil];
156 | }
157 |
158 | /**
159 | * Retrieve an array of tables in the currently selected database whose names are
160 | * matched against the supplied name using MySQL LIKE syntax (with wildcard
161 | * support for % and _). If no name is supplied, all tables in the selected
162 | * database will be returned, in the order that MySQL returns them.
163 | * If an error occurred while retrieving the list of tables, nil will be returned;
164 | * if no matching tables are present, an empty array will be returned.
165 | */
166 | - (NSArray *)tablesLike:(NSString *)nameLikeString
167 | {
168 |
169 | // Wrap the related tablesLike:fromDatabase: function to avoid code duplication
170 | return [self tablesLike:nameLikeString fromDatabase:nil];
171 |
172 | }
173 |
174 | /**
175 | * Retrieve an array of tables in the specified database, ordered as MySQL returns them.
176 | * If no database is specified, the current database will be used.
177 | * If an error occurred while retrieving the list of tables, nil will be returned;
178 | * if no tables are present in the specified database, an empty array will be returned.
179 | */
180 | - (NSArray *)tablesFromDatabase:(NSString *)aDatabase
181 | {
182 |
183 | // Wrap the related tablesLike:fromDatabase: function to avoid code duplication
184 | return [self tablesLike:nil fromDatabase:aDatabase];
185 |
186 | }
187 |
188 | /**
189 | * Retrieve an array of tables in the specified database whose names are matched
190 | * against the supplied name using MySQL LIKE syntax (with wildcard support
191 | * for % and _). If no name is supplied, all tables in the specified database
192 | * will be returned, in the order that MySQL returns them.
193 | * If no database is specified, the current database will be used.
194 | * If an error occurred while retrieving the list of tables, nil will be returned;
195 | * if no matching tables are present in the specified database, an empty array
196 | * will be returned.
197 | */
198 | - (NSArray *)tablesLike:(NSString *)nameLikeString fromDatabase:(NSString *)aDatabase
199 | {
200 | NSMutableArray *tableList = nil;
201 |
202 | // Table display should be made in UTF8 to avoid name encoding issues
203 | BOOL encodingChangeRequired = [self _storeAndAlterEncodingToUTF8IfRequired];
204 |
205 | // Build up the table lookup query
206 | NSMutableString *tableQuery = [NSMutableString stringWithString:@"SHOW TABLES"];
207 | if ([aDatabase length]) {
208 | [tableQuery appendFormat:@" FROM %@", [aDatabase mySQLBacktickQuotedString]];
209 | }
210 | if ([nameLikeString length]) {
211 | [tableQuery appendFormat:@" LIKE %@", [nameLikeString mySQLTickQuotedString]];
212 | }
213 |
214 | // Perform the query and record state
215 | SPMySQLResult *tableResult = [self queryString:tableQuery];
216 | [tableResult setDefaultRowReturnType:SPMySQLResultRowAsArray];
217 |
218 | // Retrieve the result into an array if the query was successful
219 | if (![self queryErrored]) {
220 | tableList = [NSMutableArray arrayWithCapacity:(NSUInteger)[tableResult numberOfRows]];
221 | for (NSArray *tableRow in tableResult) {
222 | [tableList addObject:[tableRow objectAtIndex:0]];
223 | }
224 | }
225 |
226 | // Restore the connection encoding if necessary
227 | if (encodingChangeRequired) [self restoreStoredEncoding];
228 |
229 | return tableList;
230 | }
231 |
232 | @end
233 |
234 | #pragma mark -
235 | #pragma mark Private API
236 |
237 | @implementation SPMySQLConnection (Databases_and_Tables_Private_API)
238 |
239 | /**
240 | * A number of queries regarding database or table information have to be made in UTF8, not
241 | * in the connection encoding, so that names can be fully displayed and used even if they
242 | * use a different encoding. This provides a convenience method to check whether a change
243 | * is required; if so, the current encoding is stored, the encoding is changed, and YES is
244 | * returned so the process can be reversed afterwards.
245 | */
246 | - (BOOL)_storeAndAlterEncodingToUTF8IfRequired
247 | {
248 |
249 | // If the encoding is already UTF8, no change is required.
250 | if ([encoding isEqualToString:@"utf8"] && !encodingUsesLatin1Transport) return NO;
251 |
252 | // Store the current encoding for restoration afterwards, and update encoding
253 | [self storeEncodingForRestoration];
254 | [self setEncoding:@"utf8"];
255 |
256 | return YES;
257 | }
258 |
259 | @end
--------------------------------------------------------------------------------
/Sequel Pro/en.lproj/NTDetailViewController.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1536
5 | 12A206j
6 | 2519
7 | 1172.1
8 | 613.00
9 |
10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
11 | 1856
12 |
13 |
14 | IBNSLayoutConstraint
15 | IBProxyObject
16 | IBUILabel
17 | IBUIView
18 |
19 |
20 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
21 |
22 |
23 | PluginDependencyRecalculationVersion
24 |
25 |
26 |
27 |
28 | IBFilesOwner
29 | IBIPadFramework
30 |
31 |
32 | IBFirstResponder
33 | IBIPadFramework
34 |
35 |
36 |
37 | 274
38 |
39 |
40 |
41 | 298
42 | {{20, 495}, {728, 18}}
43 |
44 |
45 |
46 | 3
47 | MQA
48 |
49 | YES
50 | NO
51 | IBIPadFramework
52 |
53 | 1
54 | 10
55 | Detail view content goes here
56 |
57 | 1
58 | MCAwIDAAA
59 |
60 | 1
61 |
62 | 1
63 | 4
64 |
65 |
66 | Helvetica
67 | 14
68 | 16
69 |
70 |
71 |
72 | {{0, 20}, {768, 1004}}
73 |
74 |
75 |
76 | NO
77 |
78 | 2
79 |
80 | IBIPadFramework
81 |
82 |
83 |
84 |
85 |
86 |
87 | view
88 |
89 |
90 |
91 | 12
92 |
93 |
94 |
95 |
96 |
97 | 0
98 |
99 |
100 |
101 |
102 |
103 | -1
104 |
105 |
106 | File's Owner
107 |
108 |
109 | -2
110 |
111 |
112 |
113 |
114 | 8
115 |
116 |
117 |
118 |
119 | 10
120 | 0
121 |
122 | 10
123 | 1
124 |
125 | 0.0
126 |
127 | 1000
128 |
129 | 5
130 | 22
131 | 2
132 |
133 |
134 |
135 | 6
136 | 0
137 |
138 | 6
139 | 1
140 |
141 | 20
142 |
143 | 1000
144 |
145 | 8
146 | 29
147 | 3
148 |
149 |
150 |
151 | 5
152 | 0
153 |
154 | 5
155 | 1
156 |
157 | 20
158 |
159 | 1000
160 |
161 | 8
162 | 29
163 | 3
164 |
165 |
166 |
167 |
168 |
169 |
170 | 81
171 |
172 |
173 |
174 |
175 |
176 | 94
177 |
178 |
179 |
180 |
181 | 97
182 |
183 |
184 |
185 |
186 | 98
187 |
188 |
189 |
190 |
191 |
192 |
193 | NTDetailViewController
194 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
195 | UIResponder
196 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
197 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
198 |
199 |
200 |
201 |
202 |
203 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
204 |
205 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
206 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
207 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
208 |
209 |
210 |
211 |
212 |
213 | 98
214 |
215 |
216 | 0
217 | IBIPadFramework
218 | YES
219 | 3
220 | YES
221 | 1856
222 |
223 |
224 |
--------------------------------------------------------------------------------
/Sequel Pro/Frameworks/SPMySQLFramework/Source/SPMySQLFastStreamingResult.m:
--------------------------------------------------------------------------------
1 | //
2 | // $Id: SPMySQLFastStreamingResult.m 3578 2012-04-09 16:37:31Z rowanb@gmail.com $
3 | //
4 | // SPMySQLFastStreamingResult.m
5 | // SPMySQLFramework
6 | //
7 | // Created by Rowan Beentje (rowan.beent.je) on February 2, 2012
8 | // Copyright (c) 2012 Rowan Beentje. All rights reserved.
9 | //
10 | // Permission is hereby granted, free of charge, to any person
11 | // obtaining a copy of this software and associated documentation
12 | // files (the "Software"), to deal in the Software without
13 | // restriction, including without limitation the rights to use,
14 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
15 | // copies of the Software, and to permit persons to whom the
16 | // Software is furnished to do so, subject to the following
17 | // conditions:
18 | //
19 | // The above copyright notice and this permission notice shall be
20 | // included in all copies or substantial portions of the Software.
21 | //
22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 | // OTHER DEALINGS IN THE SOFTWARE.
30 | //
31 | // More info at
32 |
33 | #import "SPMySQLFastStreamingResult.h"
34 | #import "SPMySQL Private APIs.h"
35 | #import "SPMySQLArrayAdditions.h"
36 | #include
37 |
38 | static id NSNullPointer;
39 |
40 | /**
41 | * This type of streaming result operates in a multithreaded fashion - a worker
42 | * thread is set up to download the results as fast as possible in the background,
43 | * while the results are made available via blocking (and so single-thread-compatible)
44 | * calls. This provides the benefit of allowing a progress bar to be shown during
45 | * downloads, and threaded processing, but still has reasonable memory usage for the
46 | * downloaded result - and won't block the server.
47 | */
48 |
49 | typedef struct st_spmysqlstreamingrowdata {
50 | char *data;
51 | unsigned long *dataLengths;
52 | struct st_spmysqlstreamingrowdata *nextRow;
53 | } SPMySQLStreamingRowData;
54 |
55 | @interface SPMySQLFastStreamingResult (Private_API)
56 |
57 | - (void) _downloadAllData;
58 |
59 | @end
60 |
61 | #pragma mark -
62 |
63 | @implementation SPMySQLFastStreamingResult
64 |
65 | #pragma mark -
66 |
67 | /**
68 | * In the one-off class initialisation, cache static variables
69 | */
70 | + (void)initialize
71 | {
72 |
73 | // Cached NSNull singleton reference
74 | if (!NSNullPointer) NSNullPointer = [NSNull null];
75 | }
76 |
77 | /**
78 | * Standard init method, constructing the SPMySQLStreamingResult around a MySQL
79 | * result pointer and the encoding to use when working with the data.
80 | * As opposed to SPMySQLResult, defaults to returning rows as arrays, as the result
81 | * sets are likely to be larger and processed in loops.
82 | */
83 | - (id)initWithMySQLResult:(void *)theResult stringEncoding:(NSStringEncoding)theStringEncoding connection:(SPMySQLConnection *)theConnection
84 | {
85 |
86 | // If no result set was passed in, return nil.
87 | if (!theResult) return nil;
88 |
89 | if ((self = [super initWithMySQLResult:theResult stringEncoding:theStringEncoding connection:theConnection])) {
90 |
91 | // Initialise the extra streaming result counts and tracking
92 | processedRowCount = 0;
93 |
94 | // Initialise the linked list pointers
95 | currentDataStoreEntry = NULL;
96 | lastDataStoreEntry = NULL;
97 |
98 | // Set up the linked list lock
99 | pthread_mutex_init(&dataLock, NULL);
100 |
101 | // Start the data download thread
102 | [NSThread detachNewThreadSelector:@selector(_downloadAllData) toTarget:self withObject:nil];
103 | }
104 |
105 | return self;
106 | }
107 |
108 | /**
109 | * Deallocate the result and ensure the parent connection is unlocked for further use.
110 | */
111 | - (void)dealloc
112 | {
113 |
114 | // Ensure all data is processed and the parent connection is unlocked
115 | [self cancelResultLoad];
116 |
117 | // Destroy the linked list lock
118 | pthread_mutex_destroy(&dataLock);
119 |
120 | // Call dealloc on super to clean up everything else, and to throw an exception if
121 | // the parent connection hasn't been cleaned up correctly.
122 | [super dealloc];
123 | }
124 |
125 | #pragma mark -
126 | #pragma mark Data retrieval
127 |
128 | /**
129 | * Override the convenience selectors so that forwarding works correctly.
130 | */
131 | - (id)getRow
132 | {
133 | return SPMySQLResultGetRow(self, SPMySQLResultRowAsDefault);
134 | }
135 | - (NSArray *)getRowAsArray
136 | {
137 | return SPMySQLResultGetRow(self, SPMySQLResultRowAsArray);
138 | }
139 | - (NSDictionary *)getRowAsDictionary
140 | {
141 | return SPMySQLResultGetRow(self, SPMySQLResultRowAsDictionary);
142 | }
143 |
144 | /**
145 | * Retrieve the next row in the result set, using the internal pointer, in the specified
146 | * return format.
147 | * If there are no rows remaining in the current iteration, returns nil.
148 | */
149 | - (id)getRowAsType:(SPMySQLResultRowType)theType
150 | {
151 | NSUInteger copiedDataLength = 0;
152 | char *theRowData;
153 | unsigned long *fieldLengths;
154 | id theReturnData;
155 |
156 | // If the target type was unspecified, use the instance default
157 | if (theType == SPMySQLResultRowAsDefault) theType = defaultRowReturnType;
158 |
159 | // Set up the return data as appropriate
160 | if (theType == SPMySQLResultRowAsArray) {
161 | theReturnData = [NSMutableArray arrayWithCapacity:numberOfFields];
162 | } else {
163 | theReturnData = [NSMutableDictionary dictionaryWithCapacity:numberOfFields];
164 | }
165 |
166 | // Lock the data mutex for safe access of variables and counters
167 | pthread_mutex_lock(&dataLock);
168 |
169 | // Determine whether any data is available; if not, wait 1ms before trying again
170 | while (!dataDownloaded && processedRowCount == downloadedRowCount) {
171 | pthread_mutex_unlock(&dataLock);
172 | usleep(1000);
173 | pthread_mutex_lock(&dataLock);
174 | }
175 |
176 | // If all rows have been processed, the end of the result set has been reached; return nil.
177 | if (processedRowCount == downloadedRowCount) {
178 | pthread_mutex_unlock(&dataLock);
179 | return nil;
180 | }
181 |
182 | // Unlock the data mutex now checks are complete
183 | pthread_mutex_unlock(&dataLock);
184 |
185 | // Get a reference to the data for the current row; this is safe to do outside the lock
186 | // as the pointer won't change until markers are changed at the end of this process
187 | theRowData = currentDataStoreEntry->data;
188 | fieldLengths = currentDataStoreEntry->dataLengths;
189 |
190 | // Convert each of the cells in the row in turn
191 | unsigned long fieldLength;
192 | id cellData;
193 | char *rawCellData;
194 | for (NSUInteger i = 0; i < numberOfFields; i++) {
195 | fieldLength = fieldLengths[i];
196 |
197 | // If the length of this cell is NSNotFound, it's a null reference
198 | if (fieldLength == NSNotFound) {
199 | cellData = nil;
200 |
201 | // Otherwise grab a reference to that data using pointer arithmetic
202 | } else {
203 | rawCellData = theRowData + copiedDataLength;
204 | copiedDataLength += fieldLength;
205 |
206 | // Convert to the correct object type
207 | cellData = SPMySQLResultGetObject(self, rawCellData, fieldLength, fieldTypes[i], i);
208 | }
209 |
210 | // If object creation failed, display a null
211 | if (!cellData) cellData = NSNullPointer;
212 |
213 | // Add to the result array/dictionary
214 | if (theType == SPMySQLResultRowAsArray) {
215 | SPMySQLMutableArrayInsertObject(theReturnData, cellData, i);
216 | } else {
217 | [(NSMutableDictionary *)theReturnData setObject:cellData forKey:fieldNames[i]];
218 | }
219 | }
220 |
221 | // Get a reference to the current item
222 | SPMySQLStreamingRowData *previousDataStoreEntry = currentDataStoreEntry;
223 |
224 | // Lock the mutex before updating counters and linked lists
225 | pthread_mutex_lock(&dataLock);
226 |
227 | // Update the active-data pointer to the next item in the list (which may be NULL)
228 | currentDataStoreEntry = currentDataStoreEntry->nextRow;
229 | if (!currentDataStoreEntry) lastDataStoreEntry = NULL;
230 |
231 | // Increment the processed counter and row index
232 | processedRowCount++;
233 | currentRowIndex++;
234 | if (dataDownloaded && processedRowCount == downloadedRowCount) currentRowIndex = NSNotFound;
235 |
236 | // Unlock the mutex
237 | pthread_mutex_unlock(&dataLock);
238 |
239 | // Free the memory for the processed row
240 | free(previousDataStoreEntry->dataLengths);
241 | if (previousDataStoreEntry->data != NULL) free(previousDataStoreEntry->data);
242 | free(previousDataStoreEntry);
243 |
244 | return theReturnData;
245 | }
246 |
247 | /*
248 | * Ensure the result set is fully processed and freed without any processing
249 | * This method ensures that the connection is unlocked.
250 | */
251 | - (void)cancelResultLoad
252 | {
253 |
254 | // If data has already been downloaded successfully, no further action is required
255 | if (dataDownloaded && processedRowCount == downloadedRowCount) return;
256 |
257 | // Loop until all data is fetched and freed
258 | while (1) {
259 |
260 | // Check to see whether we need to wait for the data to be available
261 | // - if so, wait 1ms before checking again
262 | while (!dataDownloaded && processedRowCount == downloadedRowCount) usleep(1000);
263 |
264 | // If all rows have been processed, we're at the end of the result set - return
265 | if (processedRowCount == downloadedRowCount) {
266 |
267 | // We don't need to unlock the connection because the data loading thread
268 | // has already taken care of that
269 | return;
270 | }
271 |
272 | // Mark the row entry as processed without performing any actions
273 | pthread_mutex_lock(&dataLock);
274 | SPMySQLStreamingRowData *previousDataStoreEntry = currentDataStoreEntry;
275 |
276 | // Update the active-data pointer to the next item in the list (which may be NULL)
277 | currentDataStoreEntry = currentDataStoreEntry->nextRow;
278 | if (!currentDataStoreEntry) lastDataStoreEntry = NULL;
279 |
280 | processedRowCount++;
281 | currentRowIndex++;
282 | if (dataDownloaded && processedRowCount == downloadedRowCount) currentRowIndex = NSNotFound;
283 |
284 | // Unlock the mutex
285 | pthread_mutex_unlock(&dataLock);
286 |
287 | // Free the memory for the processed row
288 | free(previousDataStoreEntry->dataLengths);
289 | if (previousDataStoreEntry->data != NULL) free(previousDataStoreEntry->data);
290 | free(previousDataStoreEntry);
291 | }
292 | }
293 |
294 | #pragma mark -
295 | #pragma mark Data retrieval for fast enumeration
296 |
297 | /**
298 | * Implement the fast enumeration endpoint. Rows for fast enumeration are retrieved in
299 | * the instance default, as specified in setDefaultRowReturnType: or defaulting to
300 | * NSDictionary.
301 | */
302 | - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
303 | {
304 |
305 | // To avoid lock issues, return one row at a time.
306 | id nextRow = SPMySQLResultGetRow(self, SPMySQLResultRowAsDefault);
307 |
308 | // If no row was available, return 0 to stop iteration.
309 | if (!nextRow) return 0;
310 |
311 | // Otherwise, add the item to the buffer and return the appropriate state.
312 | stackbuf[0] = nextRow;
313 |
314 | state->state += 1;
315 | state->itemsPtr = stackbuf;
316 | state->mutationsPtr = (unsigned long *)self;
317 |
318 | return 1;
319 | }
320 |
321 | @end
322 |
323 | #pragma mark -
324 | #pragma mark Result set internals
325 |
326 | @implementation SPMySQLFastStreamingResult (Private_API)
327 |
328 | /**
329 | * Used internally to download results in a background thread
330 | */
331 | - (void)_downloadAllData
332 | {
333 | NSAutoreleasePool *downloadPool = [[NSAutoreleasePool alloc] init];
334 | MYSQL_ROW theRow;
335 | unsigned long *fieldLengths;
336 | NSUInteger i, dataCopiedLength, rowDataLength;
337 | SPMySQLStreamingRowData *newRowStore;
338 |
339 | size_t sizeOfStreamingRowData = sizeof(SPMySQLStreamingRowData);
340 | size_t sizeOfDataLengths = (size_t)(sizeof(unsigned long) * numberOfFields);
341 | size_t sizeOfChar = sizeof(char);
342 |
343 | // Loop through the rows until the end of the data is reached - indicated via a NULL
344 | while (
345 | (*isConnectedPtr)(parentConnection, isConnectedSelector)
346 | && (theRow = mysql_fetch_row(resultSet))
347 | )
348 | {
349 |
350 | // Retrieve the lengths of the returned data
351 | fieldLengths = mysql_fetch_lengths(resultSet);
352 | rowDataLength = 0;
353 | dataCopiedLength = 0;
354 | for (i = 0; i < numberOfFields; i++) {
355 | rowDataLength += fieldLengths[i];
356 | }
357 |
358 | // Initialise memory for the row and set a NULL pointer for the next item
359 | newRowStore = malloc(sizeOfStreamingRowData);
360 | newRowStore->nextRow = NULL;
361 |
362 | // Set up the row data store - a char* - and copy in the data if there is any.
363 | newRowStore->data = malloc(sizeOfChar * rowDataLength);
364 | for (i = 0; i < numberOfFields; i++) {
365 | if (theRow[i] != NULL) {
366 | memcpy(newRowStore->data+dataCopiedLength, theRow[i], fieldLengths[i]);
367 | dataCopiedLength += fieldLengths[i];
368 | } else {
369 | fieldLengths[i] = NSNotFound;
370 | }
371 | }
372 |
373 | // Set up the memory for, and copy in, the field lengths
374 | newRowStore->dataLengths = memcpy(malloc(sizeOfDataLengths), fieldLengths, sizeOfDataLengths);
375 |
376 | // Lock the data mutex
377 | pthread_mutex_lock(&dataLock);
378 |
379 | // Add the newly allocated row to end of the storage linked list
380 | if (lastDataStoreEntry) {
381 | lastDataStoreEntry->nextRow = newRowStore;
382 | }
383 | lastDataStoreEntry = newRowStore;
384 | if (!currentDataStoreEntry) currentDataStoreEntry = newRowStore;
385 |
386 | // Update the downloaded row count
387 | downloadedRowCount++;
388 |
389 | // Unlock the mutex
390 | pthread_mutex_unlock(&dataLock);
391 | }
392 |
393 | // Update the connection's error statuses to reflect any errors during the content download
394 | [parentConnection _updateLastErrorID:NSNotFound];
395 | [parentConnection _updateLastErrorMessage:nil];
396 |
397 | // Unlock the parent connection now all data has been retrieved
398 | [parentConnection _unlockConnection];
399 | connectionUnlocked = YES;
400 |
401 | // If the connection query may have been cancelled with a query kill, double-check connection
402 | if ([parentConnection lastQueryWasCancelled] && [parentConnection serverMajorVersion] < 5) {
403 | [parentConnection checkConnection];
404 | }
405 |
406 | dataDownloaded = YES;
407 | [downloadPool drain];
408 | }
409 |
410 | @end
411 |
--------------------------------------------------------------------------------