MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / HandleFieldList

Method HandleFieldList

cmd/cql-mysql-adapter/cursor.go:342–406  ·  view source on GitHub ↗

HandleFieldList handle COM_FILED_LIST command.

(table string, fieldWildcard string)

Source from the content-addressed store, hash-verified

340
341// HandleFieldList handle COM_FILED_LIST command.
342func (c *Cursor) HandleFieldList(table string, fieldWildcard string) (fields []*my.Field, err error) {
343 var conn *sql.DB
344
345 if conn, err = c.ensureDatabase(); err != nil {
346 return
347 }
348
349 // send show tables command
350 var columns *sql.Rows
351 if columns, err = conn.Query(fmt.Sprintf("DESC `%s`", table)); err != nil {
352 // wrap error
353 err = my.NewError(my.ER_UNKNOWN_ERROR, err.Error())
354 return
355 }
356
357 defer columns.Close()
358
359 // transform the sql wildcard to glob pattern
360 var fieldGlob string
361
362 if fieldWildcard != "" {
363 fieldGlob = strings.NewReplacer("_", "?", "%", "*").Replace(fieldWildcard)
364 }
365
366 var cid, defaultValue interface{}
367 var columnName, typeString string
368 var isNotNull, isPK bool
369
370 for columns.Next() {
371 if err = columns.Scan(&cid, &columnName, &typeString, &isNotNull, &defaultValue, &isPK); err != nil {
372 return
373 }
374
375 if fieldGlob != "" {
376 if matched, _ := filepath.Match(fieldGlob, columnName); !matched {
377 continue
378 }
379 }
380
381 // process flag
382 colFlag := uint16(0)
383
384 if isNotNull {
385 colFlag |= my.NOT_NULL_FLAG
386 }
387 if isPK {
388 colFlag |= my.NOT_NULL_FLAG
389 colFlag |= my.PRI_KEY_FLAG
390 }
391
392 fields = append(fields, &my.Field{
393 Name: []byte(columnName),
394 OrgName: []byte(columnName),
395 Table: []byte(table),
396 OrgTable: []byte(table),
397 Schema: []byte(c.curDB),
398 Flag: colFlag,
399 Charset: uint16(my.DEFAULT_COLLATION_ID),

Callers

nothing calls this directly

Calls 7

ensureDatabaseMethod · 0.95
detectColumnTypeMethod · 0.95
ErrorMethod · 0.80
QueryMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected