[GRASS-user] v.in.db accept DECIMAL'S?

Moritz Lennert mlennert at club.worldonline.be
Tue Apr 7 15:25:44 EDT 2009


On 07/04/09 21:11, Jhon Ortiz wrote:
> 
>  > On Tue, Apr 7, 2009 at 9:25 AM, Markus Neteler <neteler at osgeo.org> wrote:
>  > > On Tue, Apr 7, 2009 at 12:47 AM, Jhon Ortiz 
> <eljhonjhon at hotmail.com> wrote:
>  > >> Hi all,
>  > >>
>  > >> I'm trying to create a new vector (points) map from a mysql 
> database table
>  > >>
>  > >> v.in.db --overwrite table=data_wells driver=mysql
>  > >> database="host=localhost,dbname=Eoceno" x=Este y=Norte 
> z=Salinity_Index
>  > >> key=Cat output=Pozos
>  > >>
>  > >> but I get this error:
>  > >>
>  > >> WARNING: MySQL driver: column 'Salinity_Index', type 246 is not 
> supported
>  > >
>  > >
>  > > I have searched that and found
>  > >
>  > > grep 246 /usr/include/mysql/mysql_com.h
>  > >                        MYSQL_TYPE_NEWDECIMAL=246,
>  > >
>  > > I suspect that this change is sufficient to solve the problem:
>  > > --- db/drivers/mysql/describe.c (revision 36267)
>  > > +++ db/drivers/mysql/describe.c (working copy)
>  > > @@ -177,6 +177,7 @@
>  > >        break;
>  > >
>  > >     case MYSQL_TYPE_DECIMAL:
>  > > +    case MYSQL_TYPE_NEWDECIMAL:
>  > >        *sqltype = DB_SQL_TYPE_DECIMAL;
>  > >        break;
>  >
>  > Ah, I already suggested it in 2007 to someone else but there was
>  > no feedback:
>  > 
> https://wald.intevation.org/tracker/index.php?func=detail&aid=524&group_id=21&atid=204
>  >
>  > > Do you have a possibility to compile and test?
>  >
>  > Please :) Or someone else with a running Mysql installation.
>  >
> 
> Thanks for your help Markus,
> 
> I change in
> 
> db/drivers/mysql/describe.c
> 
> case MYSQL_TYPE_DECIMAL:
> case MYSQL_TYPE_NEWDECIMAL:
>      *sqltype = DB_SQL_TYPE_DECIMAL;
>        break;
> 
> and then compiled..
> 
> Now, when I tried
> 
> v.in.db --overwrite table=data_wells driver=mysql 
> database="host=localhost,dbname=Eoceno"
> x=Este y=Norte z=Salinity_Index key=Cat output=Pozos3
> 
> The error is:
> 
> Writing features...
> ERROR: x/y/z column must be integer or double
> 
> I change the decimal type by double in mi MySQL database table and now 
> is working..

The following (in combination with Marjus' patch) might make it work 
with decimal:

Index: lib/db/dbmi_base/sqlCtype.c
===================================================================
--- lib/db/dbmi_base/sqlCtype.c	(révision 36609)
+++ lib/db/dbmi_base/sqlCtype.c	(copie de travail)
@@ -17,6 +17,8 @@
  	return DB_C_TYPE_DOUBLE;
      case DB_SQL_TYPE_DOUBLE_PRECISION:
  	return DB_C_TYPE_DOUBLE;
+    case DB_SQL_TYPE_DECIMAL:
+	return DB_C_TYPE_DOUBLE;
      case DB_SQL_TYPE_SERIAL:
  	return DB_C_TYPE_INT;
      }

But I'm not sure whether it might have any negative consequences to 
automatically associate decimal with double. I can't think of anything 
obvious, but needs testing.

Moritz


More information about the grass-user mailing list