WillAyd commented on code in PR #577:
URL: https://github.com/apache/arrow-adbc/pull/577#discussion_r1183883042
##########
c/driver/postgresql/connection.cc:
##########
@@ -47,7 +49,80 @@ AdbcStatusCode PostgresConnection::GetTableSchema(const
char* catalog,
const char* table_name,
struct ArrowSchema* schema,
struct AdbcError* error) {
- return ADBC_STATUS_NOT_IMPLEMENTED;
+ AdbcStatusCode final_status = ADBC_STATUS_OK;
+ struct StringBuilder query = {0};
+ if (StringBuilderInit(&query, /*initial_size=*/256) != 0) return
ADBC_STATUS_INTERNAL;
+
+ if (StringBuilderAppend(
+ &query, "%s",
+ "SELECT attname, atttypid "
+ "FROM pg_catalog.pg_class AS cls "
+ "INNER JOIN pg_catalog.pg_attribute AS attr ON cls.oid =
attr.attrelid "
+ "INNER JOIN pg_catalog.pg_type AS typ ON attr.atttypid = typ.oid "
+ "WHERE attr.attnum >= 0 AND cls.oid = '") != 0)
+ return ADBC_STATUS_INTERNAL;
+
+ if (db_schema != nullptr) {
+ char* schema = PQescapeIdentifier(conn_, db_schema, strlen(db_schema));
+ if (schema == NULL) {
+ SetError(error, "%s%s", "Faled to escape schema: ",
PQerrorMessage(conn_));
+ return ADBC_STATUS_INVALID_ARGUMENT;
+ }
+
+ int ret = StringBuilderAppend(&query, "%s%s", schema, ".");
+ PQfreemem(schema);
+
+ if (ret != 0) return ADBC_STATUS_INTERNAL;
+ }
+
+ char* table = PQescapeIdentifier(conn_, table_name, strlen(table_name));
+ if (table == NULL) {
+ SetError(error, "%s%s", "Failed to escape table: ", PQerrorMessage(conn_));
+ return ADBC_STATUS_INVALID_ARGUMENT;
+ }
+
+ int ret = StringBuilderAppend(&query, "%s%s", table_name,
"'::regclass::oid");
+ PQfreemem(table);
+
+ if (ret != 0) return ADBC_STATUS_INTERNAL;
Review Comment:
Think its worth creating a private method to resolve the schema / table
name? I can see that being used a few places. May also be worth creating in
postgres_utils
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]