From 5fa68474e6f817c32bf87db41f9879df8b1674dd Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 20 May 2018 19:37:29 +0200 Subject: Add method to query mysql->server_status (part of #3005) --- .../SPMySQLConnection Categories/Server Info.h | 11 ++++++++ .../SPMySQLConnection Categories/Server Info.m | 32 ++++++++++++++++++++++ .../SPMySQLFramework/Source/SPMySQLConstants.h | 19 +++++++++++++ 3 files changed, 62 insertions(+) (limited to 'Frameworks/SPMySQLFramework') diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h index 8ec6c9e0..2e4ac7ad 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h @@ -55,4 +55,15 @@ */ - (BOOL)serverShutdown; +/** + * This method will update the passed-in bitfield struct with + * the server_status flags that were received most recently (i.e. usually + * in return to the last executed query). + * + * THIS METHOD IS NOT THREAD-SAFE! + * + * @return YES, unless the MySQL connection is invalid (in which case the passed-in struct remains unchanged) + */ +- (BOOL)updateServerStatusBits:(SPMySQLServerStatusBits *)bits; + @end diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m index 56675d5d..eab3c2f0 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m @@ -167,4 +167,36 @@ return NO; } +- (BOOL)updateServerStatusBits:(SPMySQLServerStatusBits *)bits +{ + if(state != SPMySQLConnected || !mySQLConnection) return NO; + + unsigned int ss = mySQLConnection->server_status; + + unsigned int (^isSet)(unsigned int) = ^unsigned int(unsigned int cmp) { + return ((ss & cmp) != 0 ? 1 : 0); + }; + + bits->inTransaction = isSet(SERVER_STATUS_IN_TRANS); // 1 << 0 + bits->autocommit = isSet(SERVER_STATUS_AUTOCOMMIT); // 1 << 1 + bits->_reserved1 = isSet(4); // 1 << 2 + bits->moreResultsExists = isSet(SERVER_MORE_RESULTS_EXISTS); // 1 << 3 + bits->queryNoGoodIndexUsed = isSet(SERVER_QUERY_NO_GOOD_INDEX_USED); // 1 << 4 + bits->queryNoIndexUsed = isSet(SERVER_QUERY_NO_INDEX_USED); // 1 << 5 + bits->cursorExists = isSet(SERVER_STATUS_CURSOR_EXISTS); // 1 << 6 + bits->lastRowSent = isSet(SERVER_STATUS_LAST_ROW_SENT); // 1 << 7 + bits->dbDropped = isSet(SERVER_STATUS_DB_DROPPED); // 1 << 8 + bits->noBackslashEscapes = isSet(SERVER_STATUS_NO_BACKSLASH_ESCAPES); // 1 << 9 + bits->metadataChanged = isSet(SERVER_STATUS_METADATA_CHANGED); // 1 << 10 + bits->queryWasSlow = isSet(SERVER_QUERY_WAS_SLOW); // 1 << 11 + bits->psOutParams = isSet(SERVER_PS_OUT_PARAMS); // 1 << 12 + //TODO the following two flags were added after the 5.5 branch we are currently using + bits->inTransReadonly = isSet(1 << 13); // 1 << 13 + bits->sessionStateChanged = isSet(1 << 14); // 1 << 14 + // currently unused bits (protocol V10 uses 16 bit status on the wire) + bits->_reserved2 = isSet(1 << 15); // 1 << 15 + + return YES; +} + @end diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h index 0a1beb96..c556b90d 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h @@ -81,3 +81,22 @@ typedef NS_OPTIONS(unsigned long, SPMySQLClientFlags) { SPMySQLClientFlagInteractive = 1024, // CLIENT_INTERACTIVE SPMySQLClientFlagMultiResults = (1UL << 17) // CLIENT_MULTI_RESULTS = 131072 }; + +typedef struct { + unsigned int inTransaction:1; + unsigned int autocommit:1; + unsigned int _reserved1:1; + unsigned int moreResultsExists:1; + unsigned int queryNoGoodIndexUsed:1; + unsigned int queryNoIndexUsed:1; + unsigned int cursorExists:1; + unsigned int lastRowSent:1; + unsigned int dbDropped:1; + unsigned int noBackslashEscapes:1; + unsigned int metadataChanged:1; + unsigned int queryWasSlow:1; + unsigned int psOutParams:1; + unsigned int inTransReadonly:1; + unsigned int sessionStateChanged:1; + unsigned int _reserved2:1; +} SPMySQLServerStatusBits; -- cgit v1.2.3