This repository has been archived on 2024-07-15. You can view files and clone it, but cannot push or open issues or pull requests.
hedera/sql/sql-table.c

179 lines
4.1 KiB
C

/*
* Copyright (C) 2012 - Juan Ferrer Toribio
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sql-table.h"
/**
* SECTION: sql-table
* @Short_description: a qualified table name.
* @Title: SqlTable
*
* A qualified table name.
**/
G_DEFINE_TYPE (SqlTable, sql_table, SQL_TYPE_TARGET);
SqlObject * sql_table_new (const gchar * name, const gchar * schema)
{
return g_object_new (SQL_TYPE_TABLE, "name", name, "schema", schema, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static void sql_table_render (SqlTable * self, SqlRender * render)
{
if (self->schema)
{
sql_render_add_identifier (render, self->schema);
sql_render_append (render, ".");
}
sql_render_add_identifier (render, self->name);
if (SQL_TARGET (self)->alias)
sql_render_add_identifier (render, SQL_TARGET (self)->alias);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
/**
* sql_table_get_name:
* @self: the #SqlTable
*
* Return value: the table name
**/
const gchar * sql_table_get_name (SqlTable * self)
{
return self->name;
}
/**
* sql_table_set_name:
* @self: the #SqlTable
* @name: the target name
**/
void sql_table_set_name (SqlTable * self, const gchar * name)
{
g_return_if_fail (SQL_IS_TABLE (self));
g_free (self->name);
self->name = g_strdup (name);
}
/**
* sql_table_get_schema:
* @self: the #SqlTable
*
* Return value: the schema name
**/
const gchar * sql_table_get_schema (SqlTable * self)
{
return self->schema;
}
/**
* sql_table_set_schema:
* @self: the #SqlTable
* @schema: the schema name
**/
void sql_table_set_schema (SqlTable * self, const gchar * schema)
{
g_return_if_fail (SQL_IS_TABLE (self));
g_free (self->schema);
self->schema = g_strdup (schema);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
{
PROP_NAME = 1
,PROP_SCHEMA
};
static void sql_table_set_property (SqlTable * self, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_NAME:
g_free (self->name);
self->name = g_value_dup_string (value);
break;
case PROP_SCHEMA:
g_free (self->schema);
self->schema = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
static void sql_table_get_property (SqlTable * self, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_NAME:
g_value_set_string (value, self->name);
break;
case PROP_SCHEMA:
g_value_set_string (value, self->schema);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_table_init (SqlTable * self)
{
self->name = NULL;
self->schema = NULL;
}
static void sql_table_finalize (SqlTable * self)
{
g_free (self->name);
g_free (self->schema);
G_OBJECT_CLASS (sql_table_parent_class)->finalize (G_OBJECT (self));
}
static void sql_table_class_init (SqlTableClass * klass)
{
GObjectClass * k = G_OBJECT_CLASS (klass);
k->finalize = (GObjectFinalizeFunc) sql_table_finalize;
k->set_property = (GObjectSetPropertyFunc) sql_table_set_property;
k->get_property = (GObjectGetPropertyFunc) sql_table_get_property;
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_table_render;
g_object_class_install_property (k, PROP_NAME,
g_param_spec_string ("name"
,("Name")
,("The table name")
,NULL, G_PARAM_READWRITE
));
g_object_class_install_property (k, PROP_SCHEMA,
g_param_spec_string ("schema"
,("Schema")
,("The schema where the table is")
,NULL, G_PARAM_READWRITE
));
}