Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Fixed couple of issues with latest version of MySQL 8
Browse files Browse the repository at this point in the history
- Fixed issue that ztsd compression was not supported (the compression flag being disabled by the client was ignored due to a new server flag)
- Fixed issue when sending query triggered Malformed packet response due to server flag default value being changed so client wasn't disabling.
  • Loading branch information
Chris Board committed Oct 28, 2022
1 parent 4967024 commit 2726401
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

5 changes: 2 additions & 3 deletions AndroidMySQLConnector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else
}

archivesBaseName="AndroidMySQLConnector"
version '0.48'
version '0.49'
group 'com.BoardiesITSolutions'


Expand All @@ -30,8 +30,6 @@ android {
//applicationId "com.BoardiesITSolutions.AndroidMySQLConnector"
minSdkVersion 19
targetSdkVersion 30
versionCode 37
versionName "0.48"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down Expand Up @@ -81,6 +79,7 @@ android {
url "https://maven.google.com"
}
}
namespace 'com.BoardiesITSolutions.AndroidMySQLConnector'
}

def getArtifactFullPath() {
Expand Down
3 changes: 1 addition & 2 deletions AndroidMySQLConnector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.BoardiesITSolutions.AndroidMySQLConnector">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,37 @@ public class Connection
public static final int CLIENT_MULTI_SET = 0x00010000;
public static final int CLIENT_SSL = 0x00000800;
public static final int CLIENT_LONG_PASSWORD = 0x00000001;
public static final int CLIENT_MULTI_STATEMENTS = 0x00010000;
//public static final int CLIENT_MULTI_STATEMENTS = 0x00010000;
public static final int CLIENT_SECURE_CONNECTION = 0x00008000;
public static final int CLIENT_CONNECT_ATTRS = 0x00100000;
public static final int CLIENT_CONNECT_WITH_DB = 0x00000008;
public static final int CLIENT_PROTOCOL_41 = 0x00000200;
public static final int CLIENT_COMPRESS = 0x00000020;

public static final int CLIENT_MULTI_STATEMENTS = 1 << 16;
public static final int MULTI_RESULTS = 1 << 17;
public static final int CLIENT_MULTI_RESULTS = 1 << 17;
public static final int CLIENT_NO_SCHEMA = 0x00000010;
public static final int CLIENT_IGNORE_SIGPIPE = 0x00001000;
public static final int CLIENT_INTERACTIVE = 0x00000400;
public static final int CLIENT_ODBC = 0x00000040;
public static final int CLIENT_IGNORE_SPACE = 0x00000100;
public static final int CLIENT_PS_MULTI_RESULTS = 0x00040000;
public static final int CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = 0x00400000;
public static final int CLIENT_SESSION_TRACK = 0x00800000;


public static final int MULTI_RESULTS = 1 << 17;
public static final int CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = 1 << 22;
public static final int CLIENT_SESSION_TRACK = 1 << 23;
public static final int DEPRECATE_EOF = 1 << 24;
public static final int CLIENT_OPTIONAL_RESULTSET_METADATA = 1 << 25;
public static final int CLIENT_ZSTD_COMPRESSION_ALGORITHM = 1 << 26;
public static final int CLIENT_QUERY_ATTRIBUTES = 1 << 27;
public static final int MULTI_FACTOR_AUTHENTICATION = 1 << 28;






/** ADDED OPTION */


//Character Sets
private final int LATIN1_SWEDISH_CI = 0x08;
Expand Down Expand Up @@ -416,16 +428,66 @@ private void processWelcomePacket() throws MySQLConnException, IOException {
clientCapabilities &= ~CLIENT_COMPRESS;
}

if ((Connection.this.serverCapabilities & CLIENT_ZSTD_COMPRESSION_ALGORITHM) == CLIENT_ZSTD_COMPRESSION_ALGORITHM)
{
Log.d("Connection", "Disabling ztsd compression");
clientCapabilities &= ~CLIENT_ZSTD_COMPRESSION_ALGORITHM;
}

if ((Connection.this.serverCapabilities & CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS) == CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS)
{
Log.d("Connection", "Disabling CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS");
clientCapabilities &= ~CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS;
}

if ((Connection.this.serverCapabilities & CLIENT_LONG_PASSWORD) == CLIENT_LONG_PASSWORD)
{
Log.d("Connection", "Disabling CLIENT_LONG_PASSWORD");
clientCapabilities &= ~CLIENT_LONG_PASSWORD;
}

if ((Connection.this.serverCapabilities & CLIENT_MULTI_STATEMENTS) == CLIENT_MULTI_STATEMENTS)
{
Log.d("Connection", "Disabling CLIENT_MULTI_STATEMENTS");
clientCapabilities &= ~CLIENT_MULTI_STATEMENTS;
}
if ((Connection.this.serverCapabilities & MULTI_FACTOR_AUTHENTICATION) == MULTI_FACTOR_AUTHENTICATION)
{
Log.d("Connection", "Disabling MULTI_FACTOR_AUTHENTICATION");
clientCapabilities &= ~MULTI_FACTOR_AUTHENTICATION;
}

if ((Connection.this.serverCapabilities & CLIENT_MULTI_RESULTS) == CLIENT_MULTI_RESULTS)
{
Log.d("Connection", "Disabling CLIENT_MULTI_RESULTS");
clientCapabilities &= ~CLIENT_MULTI_RESULTS;
}

if ((Connection.this.serverCapabilities & CLIENT_SESSION_TRACK) == CLIENT_SESSION_TRACK)
{
Log.d("Connection", "Disabling CLIENT_SESSION_TRACK");
clientCapabilities &= ~CLIENT_SESSION_TRACK;
}

if ((Connection.this.serverCapabilities & CLIENT_QUERY_ATTRIBUTES) == CLIENT_QUERY_ATTRIBUTES)
{
Log.d("Connection", "Disabling CLIENT_QUERY_ATTRIBUTES");
clientCapabilities &= ~CLIENT_QUERY_ATTRIBUTES;
}

if ((Connection.this.serverCapabilities & DEPRECATE_EOF) == DEPRECATE_EOF)
{
Log.d("MainActivity", "Disabled DEPRECATE_EOF");
clientCapabilities &= ~DEPRECATE_EOF;
}

//If MySQL 8 turn off can accept expired password
if (this.getMajorVersion() >= 8)
{
clientCapabilities &= ~CLIENT_OPTIONAL_RESULTSET_METADATA;
clientCapabilities &= ~CLIENT_SSL;

}

clientCapabilities &= ~DEPRECATE_EOF;
clientCapabilities &= ~MULTI_RESULTS;

//Check if the server is set to don't allow database.table, if so unset it so we can
//Having this enabled means SHOW TABLES and SHOW DATABASES can't be executed as it will only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,29 @@ private void processPacketData()
for (int currentColumnCount = 0; currentColumnCount < numberOfFields; currentColumnCount++)
{
this.mysqlConn.getMysqlIO().shiftCurrentBytePosition(4);

int catalogLength = (byte)this.mysqlConn.getMysqlIO().getLenEncodedInt();
String catalog = this.mysqlConn.getMysqlIO().extractData(false, catalogLength);

int databaseLength = (byte)this.mysqlConn.getMysqlIO().getLenEncodedInt();
String database = this.mysqlConn.getMysqlIO().extractData(false, databaseLength);

int tableLength = (byte)this.mysqlConn.getMysqlIO().getLenEncodedInt();
String table = this.mysqlConn.getMysqlIO().extractData(false, tableLength);

int origTableLength = (byte)this.mysqlConn.getMysqlIO().getLenEncodedInt();
String origTable = this.mysqlConn.getMysqlIO().extractData(false, origTableLength);

int columnNameLength = (byte)this.mysqlConn.getMysqlIO().getLenEncodedInt();
String columnName = this.mysqlConn.getMysqlIO().extractData(false, columnNameLength);

int origColumnNameLength = (byte)this.mysqlConn.getMysqlIO().getLenEncodedInt();
String origColumnName = this.mysqlConn.getMysqlIO().extractData(false, origColumnNameLength);

int nextLength = (byte)this.mysqlConn.getMysqlIO().getLenEncodedInt();

int characterSet = this.mysqlConn.getMysqlIO().fromByteArray((byte[])this.mysqlConn.getMysqlIO().extractData(2));

int columnLength = this.mysqlConn.getMysqlIO().fromByteArray((byte[])this.mysqlConn.getMysqlIO().extractData(4));

int columnType = (byte)this.mysqlConn.getMysqlIO().extractData(1) & 0xff;

int flags = this.mysqlConn.getMysqlIO().fromByteArray((byte[])this.mysqlConn.getMysqlIO().extractData(2));

int decimals = (byte)this.mysqlConn.getMysqlIO().extractData(1);


//2 Byte NULL fillers so shift on another 2
this.mysqlConn.getMysqlIO().shiftCurrentBytePosition(2);
//break;

this.columnDefinitions.add(new ColumnDefinition(catalog, database, table, columnName, characterSet,
columnType, flags, decimals));
}
Expand All @@ -92,6 +79,7 @@ private void processPacketData()
//it in case we need it - don't think we do though!
if (this.mysqlConn.isConnectedVersionLessThan(5,5,60) && !this.mysqlConn.isMariaDB())
{
Log.d("COMQueryResponse", "Reading extra un-used data");
int packetLength = this.mysqlConn.getMysqlIO().fromByteArray((byte[]) this.mysqlConn.getMysqlIO().extractData(3));
int packetNumber = (byte) this.mysqlConn.getMysqlIO().extractData(1);
int eofMarker = (byte) this.mysqlConn.getMysqlIO().extractData(1);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:4.2.2'
if (!publishToMavenLocal) {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
Expand Down
3 changes: 2 additions & 1 deletion demoapplication/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ android {
repositories {
maven { url 'https://jitpack.io' }
}
namespace 'com.boardiesitsolutions.demoapplication'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.48_MySQL8'
implementation 'com.github.BoardiesITSolutions:Android-MySQL-Connector:0.49_MySQL8'

}
3 changes: 1 addition & 2 deletions demoapplication/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.boardiesitsolutions.demoapplication">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Empty file modified gradlew
100644 → 100755
Empty file.

0 comments on commit 2726401

Please sign in to comment.