Broad Network


Column Properties with the EMySQL API

Using the EMySQL API – Part 6

Foreword: In this part of the series, I talk about table column (field) properties obtained with the EMySQL API.

By: Chrysanthus Date Published: 28 Jul 2016

Introduction

This is part 6 of my series, Using the EMySQL API. In this part of the series, I talk about table column (field) properties obtained with the EMySQL API. You should have read the previous parts of the series before reaching here, as this is a continuation.

The EMysql package has an array of arrays. Each internal array represents a column. So, if there were six columns in the result set, there would be six internal arrays. Each cell of each internal array has a column property.

The values of the cells of each internal array are in the following order:

- Virtual Column Name
- Schema Name (database)
- Virtual Table Name
- Charset Number
- Column Width
- Field Type Number
- Field Type (meaning)
- MaximumShown Decimal Digits
- Default Value

As you can see, there are 9 properties.

Displaying Rows of the Array
For the pet table of the PetStore, the following code displays all the properties for the six columns:

    var selStr = `SELECT * FROM pet`;
    con.query(selStr, function(err, result, field)
        {
            if (err)
                console.log(err);
            else
                console.log(field);
        });

Note the use of the field argument in the definition of the callback function. I tried the code and I had:

[ [ 'name',
    'petstore',
    'pet',
    33,
    60,
    253,
    'MYSQL_TYPE_VAR_STRING',
    0,
    '' ],
  [ 'owner',
    'petstore',
    'pet',
    33,
    60,
    253,
    'MYSQL_TYPE_VAR_STRING',
    0,
    '' ],
  [ 'species',
    'petstore',
    'pet',
    33,
    60,
    253,
    'MYSQL_TYPE_VAR_STRING',
    0,
    '' ],
  [ 'sex', 'petstore', 'pet', 33, 3, 254, 'MYSQL_TYPE_STRING', 0, '' ],
  [ 'birth', 'petstore', 'pet', 63, 10, 10, 'MYSQL_TYPE_DATE', 0, '' ],
  [ 'death', 'petstore', 'pet', 63, 10, 10, 'MYSQL_TYPE_DATE', 0, '' ] ]

That is it for this part of the series. We stop here and continue in the next part.

Chrys

Related Links

Free Pure ECMAScript MySQL API for Node.js
More Related Links
Node Mailsend
EMySQL API
Node.js Web Development Course
Major in Website Design
Low Level Programming - Writing ECMAScript Module
ECMAScript Course

BACK NEXT

Comments

Become the Writer's Follower
Send the Writer a Message