use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class DatabaseMetaData method getProcedureOrFunctionColumns.
protected java.sql.ResultSet getProcedureOrFunctionColumns(Field[] fields, String catalog, String schemaPattern, String procedureOrFunctionNamePattern, String columnNamePattern, boolean returnProcedures, boolean returnFunctions) throws SQLException {
String db = getDatabase(catalog, schemaPattern);
final boolean dbMapsToSchema = DatabaseMetaData.this.databaseTerm.getValue() == DatabaseTerm.SCHEMA;
List<ComparableWrapper<String, ProcedureType>> procsOrFuncsToExtractList = new ArrayList<>();
// Main container to be passed to getProceduresAndOrFunctions
ResultSet procsAndOrFuncsRs = null;
try {
// getProceduresAndOrFunctions does NOT expect procedureOrFunctionNamePattern in form of DB_NAME.SP_NAME thus we need to remove it
String tmpProcedureOrFunctionNamePattern = null;
// Check if NOT a pattern first, then "sanitize"
if ((procedureOrFunctionNamePattern != null) && (!procedureOrFunctionNamePattern.equals("%"))) {
tmpProcedureOrFunctionNamePattern = StringUtils.sanitizeProcOrFuncName(procedureOrFunctionNamePattern);
}
// Sanity check, if NamePattern is still NULL, we have a wildcard and not the name
if (tmpProcedureOrFunctionNamePattern == null) {
tmpProcedureOrFunctionNamePattern = procedureOrFunctionNamePattern;
} else {
// So we have a name to check meaning more actual processing
// Keep the Catalog parsed, maybe we'll need it at some point in the future...
String tmpDb = db;
List<String> parseList = StringUtils.splitDBdotName(tmpProcedureOrFunctionNamePattern, tmpDb, this.quotedId, this.session.getServerSession().isNoBackslashEscapesSet());
// There *should* be 2 rows, if any.
if (parseList.size() == 2) {
tmpDb = parseList.get(0);
tmpProcedureOrFunctionNamePattern = parseList.get(1);
} else {
// keep values as they are
}
}
procsAndOrFuncsRs = getProceduresAndOrFunctions(createFieldMetadataForGetProcedures(), catalog, schemaPattern, tmpProcedureOrFunctionNamePattern, returnProcedures, returnFunctions);
boolean hasResults = false;
while (procsAndOrFuncsRs.next()) {
procsOrFuncsToExtractList.add(new ComparableWrapper<>(StringUtils.getFullyQualifiedName(dbMapsToSchema ? procsAndOrFuncsRs.getString(2) : procsAndOrFuncsRs.getString(1), procsAndOrFuncsRs.getString(3), this.quotedId, this.pedantic), procsAndOrFuncsRs.getShort(8) == procedureNoResult ? PROCEDURE : FUNCTION));
hasResults = true;
}
// FIX for Bug#56305, allowing the code to proceed with empty fields causing NPE later
if (!hasResults) {
// throw SQLError.createSQLException(
// "User does not have access to metadata required to determine " +
// "stored procedure parameter types. If rights can not be granted, configure connection with \"noAccessToProcedureBodies=true\" " +
// "to have driver generate parameters that represent INOUT strings irregardless of actual parameter types.",
// MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
} else {
Collections.sort(procsOrFuncsToExtractList);
}
// Required to be sorted in name-order by JDBC spec, in 'normal' case getProcedures takes care of this for us, but if system tables are
// inaccessible, we need to sort... so just do this to be safe...
// Collections.sort(proceduresToExtractList);
} finally {
SQLException rethrowSqlEx = null;
if (procsAndOrFuncsRs != null) {
try {
procsAndOrFuncsRs.close();
} catch (SQLException sqlEx) {
rethrowSqlEx = sqlEx;
}
}
if (rethrowSqlEx != null) {
throw rethrowSqlEx;
}
}
ArrayList<Row> resultRows = new ArrayList<>();
int idx = 0;
String procNameToCall = "";
for (ComparableWrapper<String, ProcedureType> procOrFunc : procsOrFuncsToExtractList) {
String procName = procOrFunc.getKey();
ProcedureType procType = procOrFunc.getValue();
// Continuing from above (database_name.sp_name)
if (!" ".equals(this.quotedId)) {
idx = StringUtils.indexOfIgnoreCase(0, procName, ".", this.quotedId, this.quotedId, this.session.getServerSession().isNoBackslashEscapesSet() ? SearchMode.__MRK_COM_MYM_HNT_WS : SearchMode.__BSE_MRK_COM_MYM_HNT_WS);
} else {
idx = procName.indexOf(".");
}
if (idx > 0) {
db = StringUtils.unQuoteIdentifier(procName.substring(0, idx), this.quotedId);
// Leave as CAT.PROC, needed later
procNameToCall = procName;
} else {
// No catalog. Not sure how to handle right now...
procNameToCall = procName;
}
getCallStmtParameterTypes(db, procNameToCall, procType, columnNamePattern, resultRows, fields.length == 17);
}
return this.resultSetFactory.createFromResultsetRows(ResultSet.CONCUR_READ_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, new ResultsetRowsStatic(resultRows, new DefaultColumnDefinition(fields)));
}
use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class DatabaseMetaData method getColumnPrivileges.
@Override
public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException {
String db = getDatabase(catalog, schema);
StringBuilder grantQueryBuf = new StringBuilder("SELECT c.host, c.db, t.grantor, c.user, c.table_name, c.column_name, c.column_priv");
grantQueryBuf.append(" FROM mysql.columns_priv c, mysql.tables_priv t");
grantQueryBuf.append(" WHERE c.host = t.host AND c.db = t.db AND c.table_name = t.table_name");
if (db != null) {
grantQueryBuf.append(" AND c.db = ?");
}
grantQueryBuf.append(" AND c.table_name = ?");
if (columnNamePattern != null) {
grantQueryBuf.append(" AND c.column_name LIKE ?");
}
PreparedStatement pStmt = null;
ResultSet results = null;
ArrayList<Row> grantRows = new ArrayList<>();
try {
pStmt = prepareMetaDataSafeStatement(grantQueryBuf.toString());
int nextId = 1;
if (db != null) {
pStmt.setString(nextId++, db);
}
pStmt.setString(nextId++, table);
if (columnNamePattern != null) {
pStmt.setString(nextId, columnNamePattern);
}
results = pStmt.executeQuery();
while (results.next()) {
String host = results.getString(1);
db = results.getString(2);
String grantor = results.getString(3);
String user = results.getString(4);
if ((user == null) || (user.length() == 0)) {
user = "%";
}
StringBuilder fullUser = new StringBuilder(user);
if ((host != null) && this.useHostsInPrivileges) {
fullUser.append("@");
fullUser.append(host);
}
String columnName = results.getString(6);
String allPrivileges = results.getString(7);
if (allPrivileges != null) {
allPrivileges = allPrivileges.toUpperCase(Locale.ENGLISH);
StringTokenizer st = new StringTokenizer(allPrivileges, ",");
while (st.hasMoreTokens()) {
String privilege = st.nextToken().trim();
byte[][] tuple = new byte[8][];
tuple[0] = this.databaseTerm.getValue() == DatabaseTerm.SCHEMA ? s2b("def") : s2b(db);
tuple[1] = this.databaseTerm.getValue() == DatabaseTerm.SCHEMA ? s2b(db) : null;
tuple[2] = s2b(table);
tuple[3] = s2b(columnName);
tuple[4] = grantor != null ? s2b(grantor) : null;
tuple[5] = s2b(fullUser.toString());
tuple[6] = s2b(privilege);
tuple[7] = null;
grantRows.add(new ByteArrayRow(tuple, getExceptionInterceptor()));
}
}
}
} finally {
if (results != null) {
try {
results.close();
} catch (Exception ex) {
}
results = null;
}
if (pStmt != null) {
try {
pStmt.close();
} catch (Exception ex) {
}
pStmt = null;
}
}
return this.resultSetFactory.createFromResultsetRows(ResultSet.CONCUR_READ_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, new ResultsetRowsStatic(grantRows, new DefaultColumnDefinition(getColumnPrivilegesFields())));
}
use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class DatabaseMetaData method getTypeInfo.
@Override
public java.sql.ResultSet getTypeInfo() throws SQLException {
Field[] fields = new Field[18];
fields[0] = new Field("", "TYPE_NAME", this.metadataCollationIndex, this.metadataEncoding, MysqlType.CHAR, 32);
fields[1] = new Field("", "DATA_TYPE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.INT, 5);
fields[2] = new Field("", "PRECISION", this.metadataCollationIndex, this.metadataEncoding, MysqlType.INT, 10);
fields[3] = new Field("", "LITERAL_PREFIX", this.metadataCollationIndex, this.metadataEncoding, MysqlType.CHAR, 4);
fields[4] = new Field("", "LITERAL_SUFFIX", this.metadataCollationIndex, this.metadataEncoding, MysqlType.CHAR, 4);
fields[5] = new Field("", "CREATE_PARAMS", this.metadataCollationIndex, this.metadataEncoding, MysqlType.CHAR, 32);
fields[6] = new Field("", "NULLABLE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.SMALLINT, 5);
fields[7] = new Field("", "CASE_SENSITIVE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.BOOLEAN, 3);
fields[8] = new Field("", "SEARCHABLE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.SMALLINT, 3);
fields[9] = new Field("", "UNSIGNED_ATTRIBUTE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.BOOLEAN, 3);
fields[10] = new Field("", "FIXED_PREC_SCALE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.BOOLEAN, 3);
fields[11] = new Field("", "AUTO_INCREMENT", this.metadataCollationIndex, this.metadataEncoding, MysqlType.BOOLEAN, 3);
fields[12] = new Field("", "LOCAL_TYPE_NAME", this.metadataCollationIndex, this.metadataEncoding, MysqlType.CHAR, 32);
fields[13] = new Field("", "MINIMUM_SCALE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.SMALLINT, 5);
fields[14] = new Field("", "MAXIMUM_SCALE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.SMALLINT, 5);
fields[15] = new Field("", "SQL_DATA_TYPE", this.metadataCollationIndex, this.metadataEncoding, MysqlType.INT, 10);
fields[16] = new Field("", "SQL_DATETIME_SUB", this.metadataCollationIndex, this.metadataEncoding, MysqlType.INT, 10);
fields[17] = new Field("", "NUM_PREC_RADIX", this.metadataCollationIndex, this.metadataEncoding, MysqlType.INT, 10);
ArrayList<Row> tuples = new ArrayList<>();
/*
* The following are ordered by java.sql.Types, and then by how closely the MySQL type matches the JDBC Type (per spec)
*/
tuples.add(new ByteArrayRow(getTypeInfo("BIT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BOOL"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BIGINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BIGINT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARBINARY"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMBLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONGBLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("VARBINARY"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYBLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BINARY"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARCHAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMTEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONGTEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("CHAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("ENUM"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("SET"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DECIMAL"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("NUMERIC"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMINT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("SMALLINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("SMALLINT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("FLOAT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE PRECISION"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("REAL"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("VARCHAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYTEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DATE"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("YEAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TIME"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DATETIME"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TIMESTAMP"), getExceptionInterceptor()));
return this.resultSetFactory.createFromResultsetRows(ResultSet.CONCUR_READ_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, new ResultsetRowsStatic(tuples, new DefaultColumnDefinition(fields)));
}
use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class DatabaseMetaData method getSchemas.
@Override
public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
List<String> dbList = this.databaseTerm.getValue() == DatabaseTerm.SCHEMA ? getDatabases(schemaPattern) : new ArrayList<>();
Field[] fields = new Field[2];
fields[0] = new Field("", "TABLE_SCHEM", this.metadataCollationIndex, this.metadataEncoding, MysqlType.CHAR, 0);
fields[1] = new Field("", "TABLE_CATALOG", this.metadataCollationIndex, this.metadataEncoding, MysqlType.CHAR, 0);
ArrayList<Row> tuples = new ArrayList<>(dbList.size());
for (String db : dbList) {
byte[][] rowVal = new byte[2][];
rowVal[0] = s2b(db);
rowVal[1] = s2b("def");
tuples.add(new ByteArrayRow(rowVal, getExceptionInterceptor()));
}
return this.resultSetFactory.createFromResultsetRows(ResultSet.CONCUR_READ_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, new ResultsetRowsStatic(tuples, new DefaultColumnDefinition(fields)));
}
use of com.mysql.cj.result.Row in project ABC by RuiPinto96274.
the class UpdatableResultSet method insertRow.
@Override
public void insertRow() throws SQLException {
synchronized (checkClosed().getConnectionMutex()) {
if (!this.onInsertRow) {
throw SQLError.createSQLException(Messages.getString("UpdatableResultSet.7"), getExceptionInterceptor());
}
this.inserter.executeUpdate();
long autoIncrementId = this.inserter.getLastInsertID();
Field[] fields = this.getMetadata().getFields();
byte[][] newRow = new byte[fields.length][];
for (int i = 0; i < fields.length; i++) {
newRow[i] = this.inserter.isNull(i + 1) ? null : this.inserter.getBytesRepresentation(i + 1);
// WARN: This non-variant only holds if MySQL never allows more than one auto-increment key (which is the way it is _today_)
if (fields[i].isAutoIncrement() && autoIncrementId > 0) {
newRow[i] = StringUtils.getBytes(String.valueOf(autoIncrementId));
this.inserter.setBytesNoEscapeNoQuotes(i + 1, newRow[i]);
}
}
Row resultSetRow = new ByteArrayRow(newRow, getExceptionInterceptor());
// inserter is always a client-side prepared statement, so it's safe to use it with ByteArrayRow for server-side prepared statement too
refreshRow(this.inserter, resultSetRow);
this.rowData.addRow(resultSetRow);
resetInserter();
}
}
Aggregations