Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Functions | Variables

descriptor.c File Reference

#include "postgres_fe.h"
#include "extern.h"
Include dependency graph for descriptor.c:

Go to the source code of this file.

Defines

#define MAX_DESCRIPTOR_NAMELEN   128

Functions

void push_assignment (char *var, enum ECPGdtype value)
static void drop_assignments (void)
static void ECPGnumeric_lvalue (char *name)
void add_descriptor (char *name, char *connection)
void drop_descriptor (char *name, char *connection)
struct descriptorlookup_descriptor (char *name, char *connection)
void output_get_descr_header (char *desc_name)
void output_get_descr (char *desc_name, char *index)
void output_set_descr_header (char *desc_name)
static const char * descriptor_item_name (enum ECPGdtype itemcode)
void output_set_descr (char *desc_name, char *index)
struct variabledescriptor_variable (const char *name, int input)
struct variablesqlda_variable (const char *name)

Variables

static struct assignmentassignments
static struct descriptordescriptors

Define Documentation

#define MAX_DESCRIPTOR_NAMELEN   128

Definition at line 315 of file descriptor.c.


Function Documentation

void add_descriptor ( char *  name,
char *  connection 
)

Definition at line 76 of file descriptor.c.

References mm_alloc(), and descriptor::name.

{
    struct descriptor *new;

    if (name[0] != '"')
        return;

    new = (struct descriptor *) mm_alloc(sizeof(struct descriptor));

    new->next = descriptors;
    new->name = mm_alloc(strlen(name) + 1);
    strcpy(new->name, name);
    if (connection)
    {
        new->connection = mm_alloc(strlen(connection) + 1);
        strcpy(new->connection, connection);
    }
    else
        new->connection = connection;
    descriptors = new;
}

static const char* descriptor_item_name ( enum ECPGdtype  itemcode  )  [static]

Definition at line 219 of file descriptor.c.

References ECPGd_cardinality, ECPGd_count, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, and ECPGd_type.

Referenced by output_set_descr().

{
    switch (itemcode)
    {
        case ECPGd_cardinality:
            return "CARDINALITY";
        case ECPGd_count:
            return "COUNT";
        case ECPGd_data:
            return "DATA";
        case ECPGd_di_code:
            return "DATETIME_INTERVAL_CODE";
        case ECPGd_di_precision:
            return "DATETIME_INTERVAL_PRECISION";
        case ECPGd_indicator:
            return "INDICATOR";
        case ECPGd_key_member:
            return "KEY_MEMBER";
        case ECPGd_length:
            return "LENGTH";
        case ECPGd_name:
            return "NAME";
        case ECPGd_nullable:
            return "NULLABLE";
        case ECPGd_octet:
            return "OCTET_LENGTH";
        case ECPGd_precision:
            return "PRECISION";
        case ECPGd_ret_length:
            return "RETURNED_LENGTH";
        case ECPGd_ret_octet:
            return "RETURNED_OCTET_LENGTH";
        case ECPGd_scale:
            return "SCALE";
        case ECPGd_type:
            return "TYPE";
        default:
            return NULL;
    }
}

struct variable* descriptor_variable ( const char *  name,
int  input 
) [read]

Definition at line 317 of file descriptor.c.

References NULL, and strlcpy().

{
    static char descriptor_names[2][MAX_DESCRIPTOR_NAMELEN];
    static struct ECPGtype descriptor_type = {ECPGt_descriptor, NULL, NULL, NULL, {NULL}, 0};
    static struct variable varspace[2] = {
        {descriptor_names[0], &descriptor_type, 0, NULL},
        {descriptor_names[1], &descriptor_type, 0, NULL}
    };

    strlcpy(descriptor_names[input], name, sizeof(descriptor_names[input]));
    return &varspace[input];
}

static void drop_assignments ( void   )  [static]

Definition at line 33 of file descriptor.c.

References free, assignment::next, and assignment::variable.

Referenced by output_get_descr(), output_get_descr_header(), output_set_descr(), and output_set_descr_header().

{
    while (assignments)
    {
        struct assignment *old_head = assignments;

        assignments = old_head->next;
        free(old_head->variable);
        free(old_head);
    }
}

void drop_descriptor ( char *  name,
char *  connection 
)

Definition at line 99 of file descriptor.c.

References descriptor::connection, ET_WARNING, free, i, mmerror(), descriptor::name, descriptor::next, and PARSE_ERROR.

{
    struct descriptor *i;
    struct descriptor **lastptr = &descriptors;

    if (name[0] != '"')
        return;

    for (i = descriptors; i; lastptr = &i->next, i = i->next)
    {
        if (strcmp(name, i->name) == 0)
        {
            if ((!connection && !i->connection)
                || (connection && i->connection
                    && strcmp(connection, i->connection) == 0))
            {
                *lastptr = i->next;
                if (i->connection)
                    free(i->connection);
                free(i->name);
                free(i);
                return;
            }
        }
    }
    mmerror(PARSE_ERROR, ET_WARNING, "descriptor \"%s\" does not exist", name);
}

static void ECPGnumeric_lvalue ( char *  name  )  [static]
struct descriptor* lookup_descriptor ( char *  name,
char *  connection 
) [read]

Definition at line 129 of file descriptor.c.

References descriptor::connection, ET_WARNING, i, mmerror(), descriptor::name, descriptor::next, and PARSE_ERROR.

{
    struct descriptor *i;

    if (name[0] != '"')
        return NULL;

    for (i = descriptors; i; i = i->next)
    {
        if (strcmp(name, i->name) == 0)
        {
            if ((!connection && !i->connection)
                || (connection && i->connection
                    && strcmp(connection, i->connection) == 0))
                return i;
        }
    }
    mmerror(PARSE_ERROR, ET_WARNING, "descriptor \"%s\" does not exist", name);
    return NULL;
}

void output_get_descr ( char *  desc_name,
char *  index 
)

Definition at line 170 of file descriptor.c.

References variable::brace_level, drop_assignments(), ECPGd_key_member, ECPGd_nullable, ECPGdump_a_type(), ET_WARNING, find_variable(), get_dtype(), mm_strdup(), mmerror(), variable::name, assignment::next, NULL, PARSE_ERROR, variable::type, assignment::value, assignment::variable, whenever_action(), and yyout.

{
    struct assignment *results;

    fprintf(yyout, "{ ECPGget_desc(__LINE__, %s, %s,", desc_name, index);
    for (results = assignments; results != NULL; results = results->next)
    {
        const struct variable *v = find_variable(results->variable);

        switch (results->value)
        {
            case ECPGd_nullable:
                mmerror(PARSE_ERROR, ET_WARNING, "nullable is always 1");
                break;
            case ECPGd_key_member:
                mmerror(PARSE_ERROR, ET_WARNING, "key_member is always 0");
                break;
            default:
                break;
        }
        fprintf(yyout, "%s,", get_dtype(results->value));
        ECPGdump_a_type(yyout, v->name, v->type, v->brace_level, NULL, NULL, -1, NULL, NULL, mm_strdup("0"), NULL, NULL);
    }
    drop_assignments();
    fputs("ECPGd_EODT);\n", yyout);

    whenever_action(2 | 1);
}

void output_get_descr_header ( char *  desc_name  ) 

Definition at line 151 of file descriptor.c.

References drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, whenever_action(), and yyout.

{
    struct assignment *results;

    fprintf(yyout, "{ ECPGget_desc_header(__LINE__, %s, &(", desc_name);
    for (results = assignments; results != NULL; results = results->next)
    {
        if (results->value == ECPGd_count)
            ECPGnumeric_lvalue(results->variable);
        else
            mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
    }

    drop_assignments();
    fprintf(yyout, "));\n");
    whenever_action(3);
}

void output_set_descr ( char *  desc_name,
char *  index 
)

Definition at line 261 of file descriptor.c.

References variable::brace_level, descriptor_item_name(), drop_assignments(), ECPGd_cardinality, ECPGd_data, ECPGd_di_code, ECPGd_di_precision, ECPGd_indicator, ECPGd_key_member, ECPGd_length, ECPGd_name, ECPGd_nullable, ECPGd_octet, ECPGd_precision, ECPGd_ret_length, ECPGd_ret_octet, ECPGd_scale, ECPGd_type, ECPGdump_a_type(), ET_FATAL, find_variable(), get_dtype(), mm_strdup(), mmerror(), variable::name, assignment::next, NULL, PARSE_ERROR, variable::type, assignment::value, assignment::variable, whenever_action(), and yyout.

{
    struct assignment *results;

    fprintf(yyout, "{ ECPGset_desc(__LINE__, %s, %s,", desc_name, index);
    for (results = assignments; results != NULL; results = results->next)
    {
        const struct variable *v = find_variable(results->variable);

        switch (results->value)
        {
            case ECPGd_cardinality:
            case ECPGd_di_code:
            case ECPGd_di_precision:
            case ECPGd_precision:
            case ECPGd_scale:
                mmerror(PARSE_ERROR, ET_FATAL, "descriptor item \"%s\" is not implemented",
                        descriptor_item_name(results->value));
                break;

            case ECPGd_key_member:
            case ECPGd_name:
            case ECPGd_nullable:
            case ECPGd_octet:
            case ECPGd_ret_length:
            case ECPGd_ret_octet:
                mmerror(PARSE_ERROR, ET_FATAL, "descriptor item \"%s\" cannot be set",
                        descriptor_item_name(results->value));
                break;

            case ECPGd_data:
            case ECPGd_indicator:
            case ECPGd_length:
            case ECPGd_type:
                fprintf(yyout, "%s,", get_dtype(results->value));
                ECPGdump_a_type(yyout, v->name, v->type, v->brace_level, NULL, NULL, -1, NULL, NULL, mm_strdup("0"), NULL, NULL);
                break;

            default:
                ;
        }
    }
    drop_assignments();
    fputs("ECPGd_EODT);\n", yyout);

    whenever_action(2 | 1);
}

void output_set_descr_header ( char *  desc_name  ) 

Definition at line 200 of file descriptor.c.

References drop_assignments(), ECPGd_count, ECPGnumeric_lvalue(), ET_WARNING, mmerror(), assignment::next, PARSE_ERROR, assignment::value, assignment::variable, whenever_action(), and yyout.

{
    struct assignment *results;

    fprintf(yyout, "{ ECPGset_desc_header(__LINE__, %s, (int)(", desc_name);
    for (results = assignments; results != NULL; results = results->next)
    {
        if (results->value == ECPGd_count)
            ECPGnumeric_lvalue(results->variable);
        else
            mmerror(PARSE_ERROR, ET_WARNING, "descriptor header item \"%d\" does not exist", results->value);
    }

    drop_assignments();
    fprintf(yyout, "));\n");
    whenever_action(3);
}

void push_assignment ( char *  var,
enum ECPGdtype  value 
)

Definition at line 21 of file descriptor.c.

References mm_alloc(), and assignment::variable.

{
    struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment));

    new->next = assignments;
    new->variable = mm_alloc(strlen(var) + 1);
    strcpy(new->variable, var);
    new->value = value;
    assignments = new;
}

struct variable* sqlda_variable ( const char *  name  )  [read]

Definition at line 331 of file descriptor.c.

References variable::brace_level, mm_alloc(), mm_strdup(), variable::name, variable::next, and variable::type.

{
    struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable));

    p->name = mm_strdup(name);
    p->type = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
    p->type->type = ECPGt_sqlda;
    p->type->size = NULL;
    p->type->struct_sizeof = NULL;
    p->type->u.element = NULL;
    p->type->counter = 0;
    p->brace_level = 0;
    p->next = NULL;

    return p;
}


Variable Documentation

struct assignment* assignments [static]

Definition at line 18 of file descriptor.c.

struct descriptor* descriptors [static]

Definition at line 73 of file descriptor.c.