Skip to content
Permalink
Browse files

Add method to query mysql->server_status (part of #3005)

  • Loading branch information...
dmoagx committed May 20, 2018
1 parent dcda896 commit 5fa68474e6f817c32bf87db41f9879df8b1674dd
@@ -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
@@ -167,4 +167,36 @@ - (BOOL)serverShutdown
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
@@ -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;

0 comments on commit 5fa6847

Please sign in to comment.
You can’t perform that action at this time.