2013-10-11 23:07:35 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
2014-05-29 14:30:11 +00:00
|
|
|
SqlObject * sql_table_new (const gchar * name, const gchar * schema)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-05-29 14:30:11 +00:00
|
|
|
return g_object_new (SQL_TYPE_TABLE, "name", name, "schema", schema, NULL);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_table_render (SqlTable * self, SqlRender * render)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
if (self->schema)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
sql_render_add_identifier (render, self->schema);
|
2013-10-11 23:07:35 +00:00
|
|
|
sql_render_append (render, ".");
|
|
|
|
}
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
sql_render_add_identifier (render, self->name);
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
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
|
2014-06-20 13:46:39 +00:00
|
|
|
* @name: the target name
|
2014-06-05 15:59:35 +00:00
|
|
|
**/
|
|
|
|
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);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_NAME = 1
|
|
|
|
,PROP_SCHEMA
|
|
|
|
};
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_table_set_property (SqlTable * self, guint id,
|
2013-10-11 23:07:35 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
2014-06-05 15:59:35 +00:00
|
|
|
g_free (self->name);
|
|
|
|
self->name = g_value_dup_string (value);
|
2013-10-11 23:07:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_SCHEMA:
|
2014-06-05 15:59:35 +00:00
|
|
|
g_free (self->schema);
|
|
|
|
self->schema = g_value_dup_string (value);
|
2013-10-11 23:07:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-06-05 15:59:35 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_table_get_property (SqlTable * self, guint id,
|
2013-10-11 23:07:35 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
2014-06-05 15:59:35 +00:00
|
|
|
g_value_set_string (value, self->name);
|
2013-10-11 23:07:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_SCHEMA:
|
2014-06-05 15:59:35 +00:00
|
|
|
g_value_set_string (value, self->schema);
|
2013-10-11 23:07:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-06-05 15:59:35 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_table_init (SqlTable * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
self->name = NULL;
|
|
|
|
self->schema = NULL;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 15:59:35 +00:00
|
|
|
static void sql_table_finalize (SqlTable * self)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2014-06-05 15:59:35 +00:00
|
|
|
g_free (self->name);
|
|
|
|
g_free (self->schema);
|
|
|
|
G_OBJECT_CLASS (sql_table_parent_class)->finalize (G_OBJECT (self));
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
2014-05-09 11:40:32 +00:00
|
|
|
,("Name")
|
|
|
|
,("The table name")
|
|
|
|
,NULL, G_PARAM_READWRITE
|
2013-10-11 23:07:35 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
g_object_class_install_property (k, PROP_SCHEMA,
|
|
|
|
g_param_spec_string ("schema"
|
2014-05-09 11:40:32 +00:00
|
|
|
,("Schema")
|
|
|
|
,("The schema where the table is")
|
2013-10-11 23:07:35 +00:00
|
|
|
,NULL, G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
}
|