mirror of
git://git.geda-project.org/gparts
synced 2025-05-09 04:23:18 +08:00
Fix units of measure for SQLite databases. (WIP)
This commit is contained in:
parent
0255723b7c
commit
c7b0731433
62
sql/sqlite/parts.sql
Normal file
62
sql/sqlite/parts.sql
Normal file
@ -0,0 +1,62 @@
|
||||
-- ---------------------------------------------------------------------------
|
||||
--
|
||||
-- gEDA - GPL Electronic Design Automation
|
||||
-- gparts - gEDA Parts Manager
|
||||
-- Copyright (C) 2010 Edward C. Hennessy
|
||||
-- Copyright (C) 2010 gEDA Contributors (see ChangeLog for details)
|
||||
--
|
||||
-- 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 2 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, write to the Free Software
|
||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
|
||||
--
|
||||
-- ---------------------------------------------------------------------------
|
||||
--
|
||||
-- ---------------------------------------------------------------------------
|
||||
|
||||
-- diodes
|
||||
|
||||
INSERT INTO Company (CompanyName)
|
||||
SELECT ( "Fairchild Semiconductor" ) WHERE NOT EXISTS (
|
||||
SELECT * FROM Company WHERE CompanyName = "Fairchild Semiconductor"
|
||||
);
|
||||
|
||||
INSERT INTO Device (DeviceName)
|
||||
SELECT ( "npn" ) WHERE NOT EXISTS (
|
||||
SELECT * FROM Device WHERE DeviceName = "npn"
|
||||
);
|
||||
|
||||
INSERT INTO Package (PackageName)
|
||||
SELECT ( "TO-92" ) WHERE NOT EXISTS (
|
||||
SELECT * FROM Package WHERE PackageName = "TO-92"
|
||||
);
|
||||
|
||||
INSERT INTO Part (CompanyID, PartNumber, DeviceID)
|
||||
SELECT
|
||||
(SELECT CompanyID FROM Company WHERE CompanyName = "Fairchild Semiconductor"),
|
||||
"FJN3303",
|
||||
(SELECT DeviceID FROM Device WHERE DeviceName = "npn")
|
||||
WHERE NOT EXISTS
|
||||
(SELECT * FROM Part WHERE PartNumber = "FJN3303");
|
||||
|
||||
INSERT INTO BJT (PartID, PackageID, Polarity, IC, FT, PD)
|
||||
VALUES (
|
||||
(SELECT PartID FROM Part WHERE PartNumber = "FJN3303"),
|
||||
(SELECT PackageID FROM Package WHERE PackageName = "TO-92"),
|
||||
"NPN",
|
||||
1.5,
|
||||
4000000,
|
||||
1.1 );
|
||||
|
||||
-- WHERE NOT EXISTS
|
||||
-- (SELECT * FROM Part WHERE PartNumber = "FJN3303");
|
||||
|
Binary file not shown.
@ -24,6 +24,7 @@
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "gparts-units.h"
|
||||
#include "gparts-column-data.h"
|
||||
|
||||
GPartsColumnData*
|
||||
|
@ -30,6 +30,7 @@ struct _GPartsColumnData
|
||||
{
|
||||
gchar *name;
|
||||
GType type;
|
||||
GPartsUnits* (*new_units)(gdouble value);
|
||||
};
|
||||
|
||||
/*! \private */
|
||||
|
@ -424,15 +424,25 @@ gparts_sqlite_result_process_columns(GPartsSQLiteResult *result, sqlite3_stmt *s
|
||||
switch (sqlite3_column_type(stmt, index))
|
||||
{
|
||||
case SQLITE_FLOAT:
|
||||
data->type = G_TYPE_DOUBLE;
|
||||
data->new_units = gparts_units_get_new_func(data->name);
|
||||
if (data->new_units != NULL)
|
||||
{
|
||||
data->type = GPARTS_TYPE_UNITS;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->type = G_TYPE_DOUBLE;
|
||||
}
|
||||
break;
|
||||
|
||||
case SQLITE_INTEGER:
|
||||
data->type = G_TYPE_INT64;
|
||||
data->new_units = NULL;
|
||||
break;
|
||||
|
||||
case SQLITE_TEXT:
|
||||
data->type = G_TYPE_STRING;
|
||||
data->new_units = NULL;
|
||||
break;
|
||||
|
||||
/* NULLs throw a wrench into the gears. Not all rows in */
|
||||
@ -442,6 +452,7 @@ gparts_sqlite_result_process_columns(GPartsSQLiteResult *result, sqlite3_stmt *s
|
||||
case SQLITE_NULL:
|
||||
default:
|
||||
data->type = G_TYPE_INVALID;
|
||||
data->new_units = NULL;
|
||||
}
|
||||
|
||||
g_ptr_array_add(privat->columns, data);
|
||||
@ -467,8 +478,20 @@ gparts_sqlite_result_process_row(GPartsSQLiteResult *result, sqlite3_stmt *stmt)
|
||||
switch (sqlite3_column_type(stmt, index))
|
||||
{
|
||||
case SQLITE_FLOAT:
|
||||
g_value_init(&value, G_TYPE_DOUBLE);
|
||||
g_value_set_double(&value, sqlite3_column_double(stmt, index));
|
||||
{
|
||||
GPartsColumnData *data = (GPartsColumnData*) g_ptr_array_index(privat->columns, index);
|
||||
|
||||
if (data->new_units != NULL)
|
||||
{
|
||||
g_value_init(&value, GPARTS_TYPE_UNITS);
|
||||
g_value_take_boxed(&value, data->new_units(sqlite3_column_double(stmt, index)));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_value_init(&value, G_TYPE_DOUBLE);
|
||||
g_value_set_double(&value, sqlite3_column_double(stmt, index));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SQLITE_INTEGER:
|
||||
|
@ -192,6 +192,56 @@ gparts_units_free(GPartsUnits *units)
|
||||
g_free(units);
|
||||
}
|
||||
|
||||
GPartsUnitsNewFunc
|
||||
gparts_units_get_new_func(const gchar *name)
|
||||
{
|
||||
struct entry
|
||||
{
|
||||
const gchar *name;
|
||||
GPartsUnitsNewFunc func;
|
||||
};
|
||||
|
||||
static const struct entry table[] =
|
||||
{
|
||||
{ "Capacitance", gparts_units_new_farads },
|
||||
{ "PD", gparts_units_new_watts },
|
||||
{ "IC", gparts_units_new_amps },
|
||||
{ "FT", gparts_units_new_hertz },
|
||||
{ "Frequency", gparts_units_new_hertz },
|
||||
{ "Inductance", gparts_units_new_henrys },
|
||||
{ "IF", gparts_units_new_amps },
|
||||
{ "Resistance", gparts_units_new_ohms },
|
||||
{ "Tolerance", gparts_units_new_pp },
|
||||
{ "Stability", gparts_units_new_pp },
|
||||
{ "VBR", gparts_units_new_volts },
|
||||
{ "VZ", gparts_units_new_volts },
|
||||
{ "VF", gparts_units_new_volts },
|
||||
{ "VR", gparts_units_new_volts },
|
||||
{ "VRWM", gparts_units_new_volts },
|
||||
{ "VZ", gparts_units_new_volts },
|
||||
{ "MinTemp", gparts_units_new_celcius },
|
||||
{ "MaxTemp", gparts_units_new_celcius },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
GPartsUnitsNewFunc func = NULL;
|
||||
const struct entry *t = &table[0];
|
||||
|
||||
while (func == NULL)
|
||||
{
|
||||
if ((t->name == NULL) || (g_strcmp0(t->name, name) == 0))
|
||||
{
|
||||
func = t->func;
|
||||
}
|
||||
else
|
||||
{
|
||||
t++;
|
||||
}
|
||||
}
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
GPartsUnits*
|
||||
gparts_units_new_amphours(gdouble amphours)
|
||||
{
|
||||
|
@ -36,8 +36,11 @@
|
||||
#define GPARTS_TYPE_UNITS (gparts_units_get_type())
|
||||
#define GPARTS_UNITS(obj) ((GPartsUnits*)obj)
|
||||
|
||||
|
||||
typedef struct _GPartsUnits GPartsUnits;
|
||||
|
||||
typedef GPartsUnits* (*GPartsUnitsNewFunc)(gdouble value);
|
||||
|
||||
/*! \private */
|
||||
GType
|
||||
gparts_units_get_type(void);
|
||||
@ -62,6 +65,17 @@ gparts_units_copy(const GPartsUnits *units);
|
||||
void
|
||||
gparts_units_free(GPartsUnits *units);
|
||||
|
||||
/*! \brief Create a new value with a measurement in amphours.
|
||||
*
|
||||
* When no longer needed, the caller must call gparts_units_free()
|
||||
* on the returned pointer.
|
||||
*
|
||||
* \param [in] amphours The value in amphours.
|
||||
* \return A pointer to a new GPartsUnits boxed type
|
||||
*/
|
||||
GPartsUnitsNewFunc
|
||||
gparts_units_get_new_func(const gchar *name);
|
||||
|
||||
/*! \brief Create a new value with a measurement in amphours.
|
||||
*
|
||||
* When no longer needed, the caller must call gparts_units_free()
|
||||
|
@ -28,9 +28,9 @@
|
||||
|
||||
/* Boxed types */
|
||||
|
||||
#include "gparts-units.h"
|
||||
#include "gparts-connect-data.h"
|
||||
#include "gparts-column-data.h"
|
||||
#include "gparts-units.h"
|
||||
|
||||
/* Forward declarations for gparts package */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user