Broad Network


Column Properties with the PurePerl MySQL API

Using the PurePerl MySQL API – Part 6

Writing a Perl Module

Foreword: In this part of the series, I talk about table column properties obtained with the PurePerl MySQL API.

By: Chrysanthus Date Published: 28 Jan 2015

Introduction

This is part 6 of my series, Using the PurePerl MySQL API. In this part of the series, I talk about table column properties obtained with the PurePerl MySQL API. PurePerl stands for Pure Perl. It is Perl Software without C software underneath. You should have read the previous parts of the series before reaching here, as this is a continuation.

The Mysql package has the array variable, @Fields. It should have all the column properties:

Structure of the @Fields Array
@Fields is a two dimensional array, where the number of rows is the number of columns (fields) in the result set. Each row has the following values in the order given:

- Name of column: this is the alias name. It would be the original name if there was no alias name;
- Name of database for the result set;
- Name of table having the column: this is the alias name. It would be the original name if there was no alias name;
- Character Set Code;
- Column (Field) length;
- Type Code;
- Field Type;
- Decimal point precision of field values;
- Default column value, if present

As you can see, there are 9 properties.

Displaying a row of the Array
The following code returns a result set and the properties of the second column are displayed:

        my $sel = "SELECT * FROM pet";
        if (Mysql::query($sel) != 1)
            {
                print $Mysql::Error_msg, "\n";
            }
        else
            {
                for (my $j=0; $j<9; ++$j)
                    {
                           print $Mysql::Fields[1][$j],  ', ';
                    }
            }

In the code, [1] is for the second column; for the third column you would type, [2]; for fourth, [3] and so on. 9 in the first line of the for-loop is for the 9 properties.

Field Type
The word, field in this article means column or column title. To obtain the field type for the first column, you can use the following code:

        my $sel = "SELECT * FROM pet";
        if (Mysql::query($sel) != 1)
           {
                print $Mysql::Error_msg, "\n";
            }
        else
            {
                  print $Mysql::Fields[0][6], "\n";                         
            }

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

Chrys

More Related Links
Perl Mailsend
PurePerl MySQL API
Perl Course - Professional and Advanced
Major in Website Design
Web Development Course
Producing a Pure Perl Library
MySQL Course

BACK NEXT

Comments

Become the Writer's Fan
Send the Writer a Message