[GRASS-dev] implementing drop column into DBF driver

Hi,

I tried to implement drop column into DBF driver to get
rid of columns like 'cat_' when re-importing an exported map:
echo "ALTER TABLE mymap DROP COLUMN cat_" | db.execute

Attached the changes to lib/db/sqlp/ and /db/drivers/dbf/

The idea is to load the table internally in SQLP_DROP_COLUMN
(such as SQLP_ADD_COLUMN does) but to jump over the column
which we want to drop.
So I took load_table() and made it load_table_selective(),
most likely in an ugly way.

While ugly, it could work but apparently I never reach
SQLP_DROP_COLUMN. It bails out with

...
D3/3: sql: ALTER TABLE mymap DROP COLUMN cat_
D3/3: SQL statement parsed successfully: ALTER TABLE mymap DROP COLUMN cat_
...
D3/3: add_column(): tab = 11, type = 3, name = edg_id, width = 20, decimals = 6
D3/3: Doing SQL command <8> on DBF table... (see include/sqlp.h)
dbmi: Protocol error
D2/3: G__home home = /home/neteler
ERROR: Error while executing: "ALTER TABLE mymap DROP COLUMN cat_
       "

I have no clue why. Help is welcome.

Thanks,
Markus

(attachments)

sqlp.diff (1.99 KB)
dbf_driver.diff (4.79 KB)

Hi Markus,

Check st->nCol and whether st->Col[0] exist at the time you call
load_table_selective. It seems that the bang happens around the point
you call the function; the sqpAddColumn should have put your colname
there, but...

Daniel.

On 12/4/06, Markus Neteler <neteler@itc.it> wrote:

Hi,

I tried to implement drop column into DBF driver to get
rid of columns like 'cat_' when re-importing an exported map:
echo "ALTER TABLE mymap DROP COLUMN cat_" | db.execute

Attached the changes to lib/db/sqlp/ and /db/drivers/dbf/

The idea is to load the table internally in SQLP_DROP_COLUMN
(such as SQLP_ADD_COLUMN does) but to jump over the column
which we want to drop.
So I took load_table() and made it load_table_selective(),
most likely in an ugly way.

While ugly, it could work but apparently I never reach
SQLP_DROP_COLUMN. It bails out with

...
D3/3: sql: ALTER TABLE mymap DROP COLUMN cat_
D3/3: SQL statement parsed successfully: ALTER TABLE mymap DROP COLUMN cat_
...
D3/3: add_column(): tab = 11, type = 3, name = edg_id, width = 20, decimals = 6
D3/3: Doing SQL command <8> on DBF table... (see include/sqlp.h)
dbmi: Protocol error
D2/3: G__home home = /home/neteler
ERROR: Error while executing: "ALTER TABLE mymap DROP COLUMN cat_
       "

I have no clue why. Help is welcome.

Thanks,
Markus

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
-- Daniel Calvelo Aros

Hi,

I have tried to solve this problem. I think in a very ugly way, but it
seems to work (see the attached patch).

Regards, Martin

2006/12/4, Markus Neteler <neteler@itc.it>:

Hi,

I tried to implement drop column into DBF driver to get
rid of columns like 'cat_' when re-importing an exported map:
echo "ALTER TABLE mymap DROP COLUMN cat_" | db.execute

Attached the changes to lib/db/sqlp/ and /db/drivers/dbf/

The idea is to load the table internally in SQLP_DROP_COLUMN
(such as SQLP_ADD_COLUMN does) but to jump over the column
which we want to drop.
So I took load_table() and made it load_table_selective(),
most likely in an ugly way.

While ugly, it could work but apparently I never reach
SQLP_DROP_COLUMN. It bails out with

...
D3/3: sql: ALTER TABLE mymap DROP COLUMN cat_
D3/3: SQL statement parsed successfully: ALTER TABLE mymap DROP COLUMN cat_
...
D3/3: add_column(): tab = 11, type = 3, name = edg_id, width = 20, decimals = 6
D3/3: Doing SQL command <8> on DBF table... (see include/sqlp.h)
dbmi: Protocol error
D2/3: G__home home = /home/neteler
ERROR: Error while executing: "ALTER TABLE mymap DROP COLUMN cat_
       "

I have no clue why. Help is welcome.

Thanks,
Markus

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

(attachments)

dbf-drop-col-3.diff.gz (2.01 KB)

Martin,

nice, I have tested it successfully (DBF driver).
Also written v.db.dropcol and tested that with DBF and PG
driver.

Once you changes are in CVS, I'll submit v.db.dropcol.
Still it would be good to have more people testing the
proposed patch.

Thanks
Markus

On Fri, Feb 02, 2007 at 05:35:19PM +0100, Martin Landa wrote:

Hi,

I have tried to solve this problem. I think in a very ugly way, but it
seems to work (see the attached patch).

Regards, Martin

2006/12/4, Markus Neteler <neteler@itc.it>:
>Hi,
>
>I tried to implement drop column into DBF driver to get
>rid of columns like 'cat_' when re-importing an exported map:
>echo "ALTER TABLE mymap DROP COLUMN cat_" | db.execute
>
>Attached the changes to lib/db/sqlp/ and /db/drivers/dbf/
>
>The idea is to load the table internally in SQLP_DROP_COLUMN
>(such as SQLP_ADD_COLUMN does) but to jump over the column
>which we want to drop.
>So I took load_table() and made it load_table_selective(),
>most likely in an ugly way.
>
>While ugly, it could work but apparently I never reach
>SQLP_DROP_COLUMN. It bails out with
>
>...
>D3/3: sql: ALTER TABLE mymap DROP COLUMN cat_
>D3/3: SQL statement parsed successfully: ALTER TABLE mymap DROP COLUMN cat_
>...
>D3/3: add_column(): tab = 11, type = 3, name = edg_id, width = 20,
>decimals = 6
>D3/3: Doing SQL command <8> on DBF table... (see include/sqlp.h)
>dbmi: Protocol error
>D2/3: G__home home = /home/neteler
>ERROR: Error while executing: "ALTER TABLE mymap DROP COLUMN cat_
> "
>
>I have no clue why. Help is welcome.
>
>Thanks,
>Markus

Hi Markus,

the patch has been committed to CVS. It would be nice if more users test it...

Best regards, Martin

2007/2/2, Markus Neteler <neteler@itc.it>:

Martin,

nice, I have tested it successfully (DBF driver).
Also written v.db.dropcol and tested that with DBF and PG
driver.

Once you changes are in CVS, I'll submit v.db.dropcol.
Still it would be good to have more people testing the
proposed patch.

Thanks
Markus

On Fri, Feb 02, 2007 at 05:35:19PM +0100, Martin Landa wrote:
> Hi,
>
> I have tried to solve this problem. I think in a very ugly way, but it
> seems to work (see the attached patch).
>
> Regards, Martin
>
> 2006/12/4, Markus Neteler <neteler@itc.it>:
> >Hi,
> >
> >I tried to implement drop column into DBF driver to get
> >rid of columns like 'cat_' when re-importing an exported map:
> >echo "ALTER TABLE mymap DROP COLUMN cat_" | db.execute
> >
> >Attached the changes to lib/db/sqlp/ and /db/drivers/dbf/
> >
> >The idea is to load the table internally in SQLP_DROP_COLUMN
> >(such as SQLP_ADD_COLUMN does) but to jump over the column
> >which we want to drop.
> >So I took load_table() and made it load_table_selective(),
> >most likely in an ugly way.
> >
> >While ugly, it could work but apparently I never reach
> >SQLP_DROP_COLUMN. It bails out with
> >
> >...
> >D3/3: sql: ALTER TABLE mymap DROP COLUMN cat_
> >D3/3: SQL statement parsed successfully: ALTER TABLE mymap DROP COLUMN cat_
> >...
> >D3/3: add_column(): tab = 11, type = 3, name = edg_id, width = 20,
> >decimals = 6
> >D3/3: Doing SQL command <8> on DBF table... (see include/sqlp.h)
> >dbmi: Protocol error
> >D2/3: G__home home = /home/neteler
> >ERROR: Error while executing: "ALTER TABLE mymap DROP COLUMN cat_
> > "
> >
> >I have no clue why. Help is welcome.
> >
> >Thanks,
> >Markus

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

Martin Landa wrote on 02/05/2007 11:52 AM:

Hi Markus,

the patch has been committed to CVS. It would be nice if more users test it...

Thanks Martin and Daniel for making this possible!

Markus