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


##########
go/adbc/driver/snowflake/connection.go:
##########
@@ -73,9 +73,51 @@ type connectionImpl struct {
        useHighPrecision  bool
 }
 
+func escapeSingleQuoteForLike(arg string) string {
+       if len(arg) == 0 {
+               return arg
+       }
+
+       idx := strings.IndexByte(arg, '\'')
+       if idx == -1 {
+               return arg
+       }
+
+       var b strings.Builder
+       b.Grow(len(arg))
+
+       for {
+               before, after, found := strings.Cut(arg, `'`)
+               b.WriteString(before)
+               if !found {
+                       return b.String()
+               }
+
+               if before[len(before)-1] != '\\' {
+                       b.WriteByte('\\')
+               }

Review Comment:
   I suppose this is to handle pre-escaped characters? But what if the escape 
is itself escaped? (Or is that not allowed?)



##########
go/adbc/driver/snowflake/connection.go:
##########
@@ -85,82 +127,165 @@ func (c *connectionImpl) GetObjects(ctx context.Context, 
depth adbc.ObjectDepth,
        defer conn.Close()
 
        gQueryIDs, gQueryIDsCtx := errgroup.WithContext(ctx)
+
        queryFile := queryTemplateGetObjectsAll
        switch depth {
        case adbc.ObjectDepthCatalogs:
-               if catalog == nil {
-                       queryFile = queryTemplateGetObjectsTerseCatalogs
-                       // if the catalog is null, show the terse databases
-                       // which doesn't require a database context
-                       gQueryIDs.Go(func() error {
-                               return conn.Raw(func(driverConn any) error {
-                                       rows, err := 
driverConn.(driver.QueryerContext).QueryContext(gQueryIDsCtx, "SHOW TERSE 
DATABASES", nil)
-                                       if err != nil {
-                                               return err
-                                       }
+               queryFile = queryTemplateGetObjectsTerseCatalogs
+               gQueryIDs.Go(func() error {
+                       return conn.Raw(func(driverConn any) (err error) {
+                               query := "SHOW TERSE /* ADBC:getObjectsCatalogs 
*/ DATABASES"
+                               if catalog != nil && len(*catalog) > 0 && 
*catalog != "%" && *catalog != ".*" {
+                                       query += " LIKE '" + 
escapeSingleQuoteForLike(*catalog) + "'"

Review Comment:
   ah, does Snowflake not allow bind parameters here?



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