Skip to content

Commit

Permalink
Merge pull request #7137 from dolthub/fulghum/connector-tests
Browse files Browse the repository at this point in the history
Adding tests for column name metadata through MySQL C++ and Rust Connector
  • Loading branch information
fulghum authored Dec 16, 2023
2 parents abc5600 + 2b5f217 commit 91d31ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <sstream>
#include <stdexcept>


#include "mysql_driver.h"
#include "mysql_connection.h"
#include "mysql_error.h"
Expand Down Expand Up @@ -64,10 +63,19 @@ int main(int argc, char **argv) {
sql::Statement *stmt = con->createStatement();

if ( is_update[i] ) {
int affected_rows = stmt->executeUpdate(queries[i]);
int affected_rows = stmt->executeUpdate(queries[i]);
} else {
sql::ResultSet *res = stmt->executeQuery(queries[i]);
delete res;
sql::ResultSet *res = stmt->executeQuery(queries[i]);

// Assert that all columns have colum name metadata populated
sql::ResultSetMetaData* metadata = res->getMetaData();
const uint columnCount = metadata->getColumnCount();
for (uint columnIndex = 1; columnIndex <= columnCount; ++columnIndex) {
sql::SQLString columnName = metadata->getColumnName(columnIndex);
assert(columnName.length() > 0);
}

delete res;
}

delete stmt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ fn main() {
let result = conn.query(query);
let response : Vec<Row> = result.expect("Error: bad response");
println!("{:?}", response);

// Assert that row metadata is populated
if response.len() > 0 {
let row = &response[0];
for column in row.columns_ref() {
if column.name_str().len() == 0 {
println!("FAIL: Column name is empty");
exit(1);
}
}
}

// Assert that the expected number of rows are returned
if response.len() != expected {
println!("LENGTH: {}", response.len());
println!("QUERY: {}", query);
Expand Down

0 comments on commit 91d31ad

Please sign in to comment.