lidavidm commented on code in PR #4773:
URL: https://github.com/apache/arrow-adbc/pull/4773#discussion_r4331364063


##########
c/driver/sqlite/statement_reader.c:
##########
@@ -340,13 +340,49 @@ AdbcStatusCode InternalAdbcSqliteBinderBindNext(struct 
AdbcSqliteBinder* binder,
   if (binder->param_indices != NULL && binder->param_indices[0] == 0) {
     // Lazy initialize since we have the statement now
     for (int i = 0; i < binder->schema.n_children; i++) {
+      if (binder->schema.children[i]->name == NULL) {
+        binder->param_indices[0] = 0;
+        InternalAdbcSetError(error, "parameter field %d has no name", i);
+        return ADBC_STATUS_INVALID_ARGUMENT;
+      }
       binder->param_indices[i] =
           sqlite3_bind_parameter_index(stmt, binder->schema.children[i]->name);
       if (binder->param_indices[i] == 0) {
+        // Accept names without a prefix when the match is unique. Exact names
+        // above retain precedence and their existing behavior.
+        for (int parameter = 1; parameter <= 
sqlite3_bind_parameter_count(stmt);
+             parameter++) {
+          const char* name = sqlite3_bind_parameter_name(stmt, parameter);
+          if (name != NULL && (name[0] == ':' || name[0] == '@' || name[0] == 
'$') &&
+              strcmp(name + 1, binder->schema.children[i]->name) == 0) {
+            if (binder->param_indices[i] != 0) {
+              binder->param_indices[0] = 0;
+              InternalAdbcSetError(error, "ambiguous parameter `%s`; include 
its prefix",
+                                   binder->schema.children[i]->name);
+              return ADBC_STATUS_INVALID_ARGUMENT;
+            }
+            binder->param_indices[i] = parameter;

Review Comment:
   This does turn into a quadratic lookup, presumably we expect not too many 
parameters, but generated SQL may get gnarly. 



##########
c/driver/sqlite/statement_reader.c:
##########
@@ -340,13 +340,49 @@ AdbcStatusCode InternalAdbcSqliteBinderBindNext(struct 
AdbcSqliteBinder* binder,
   if (binder->param_indices != NULL && binder->param_indices[0] == 0) {
     // Lazy initialize since we have the statement now
     for (int i = 0; i < binder->schema.n_children; i++) {
+      if (binder->schema.children[i]->name == NULL) {
+        binder->param_indices[0] = 0;
+        InternalAdbcSetError(error, "parameter field %d has no name", i);
+        return ADBC_STATUS_INVALID_ARGUMENT;
+      }
       binder->param_indices[i] =
           sqlite3_bind_parameter_index(stmt, binder->schema.children[i]->name);
       if (binder->param_indices[i] == 0) {
+        // Accept names without a prefix when the match is unique. Exact names
+        // above retain precedence and their existing behavior.

Review Comment:
   LLM slop: don't talk about "existing behavior". 



-- 
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]

Reply via email to