How to get filtered values from an alphanumeric table

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get filtered values from an alphanumeric table

Andrés Maneiro
Hello,

from the dialog "Add layer > Database tab" an user can load values from
a spatial-enabled database (say postgis). She can even filter which
results she wants from a table if using "SQL restrictions".

I'm looking for a way to do the same with alphanumeric tables, I mean,
just getting an IEditableSource with the values matching a condition,
not all the records in the table.

I'm navigating through the code to understand how that behaviour is
achieved with spatial-enabled databases, but any pointers on that will
be very valuable.

best,
amaneiro
_______________________________________________
gvSIG-desktop-devel mailing list
[hidden email]
https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to get filtered values from an alphanumeric table

Andrés Maneiro
Here my solution:

---

if ((w instanceof Table)
    && (((Table) w).getModel().getName().equalsIgnoreCase(myTable))) {

        IEditableSource source = ((Table) w).getModel().getModelo();
        DataSourceFactory dsf =
              source.getRecordset().getDataSourceFactory();
        String t = "'weird_name_of_alphanumeric_table'";
        String sql = "your_custom_sql_query";
        DataSource ds = dsf.executeSQL(sql, EditionEvent.ALPHANUMERIC);
        ds.setDataSourceFactory(dsf);
        SelectableDataSource sds = new SelectableDataSource(ds);
        EditableAdapter ea = new EditableAdapter();
        ea.setOriginalDataSource(sds);
        return ea;
}

---

That code will return an IEditableSource object ("ea" in this case) with
only the values matching the SQL query.

Some comments:

- myTable is the name of the window: for example, "my_table"
- t is a weird identifier of the table, which contains server, database
and so. Should look like 'myserver:post/Database Table:my_schema.my_table'

It'll be very valuable if some gvsig developer could share her thoughts
on that or say an alternative (clearer/simpler) way of doing it.

best,
amaneiro

_______________________________________________
gvSIG-desktop-devel mailing list
[hidden email]
https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to get filtered values from an alphanumeric table

Andrés Maneiro
On 23/05/11 11:09, Andrés Maneiro wrote:
> - myTable is the name of the window: for example, "my_table"
> - t is a weird identifier of the table, which contains server, database
> and so. Should look like 'myserver:post/Database Table:my_schema.my_table'
>

Forgot the later. myTable is the same as t: both contains something like
'myserver:post/Database Table:my_schema.my_table'

Sorry, copy-pasting in a hurry is not mistake-safe.

best,
amaneiro
_______________________________________________
gvSIG-desktop-devel mailing list
[hidden email]
https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to get filtered values from an alphanumeric table

Andrés Maneiro
In reply to this post by Andrés Maneiro
On 23/05/11 11:09, Andrés Maneiro wrote:

>
> if ((w instanceof Table)
> && (((Table) w).getModel().getName().equalsIgnoreCase(myTable))) {
>
> IEditableSource source = ((Table) w).getModel().getModelo();
> DataSourceFactory dsf =
> source.getRecordset().getDataSourceFactory();
> String t = "'weird_name_of_alphanumeric_table'";
> String sql = "your_custom_sql_query";
> DataSource ds = dsf.executeSQL(sql, EditionEvent.ALPHANUMERIC);
> ds.setDataSourceFactory(dsf);
> SelectableDataSource sds = new SelectableDataSource(ds);
> EditableAdapter ea = new EditableAdapter();
> ea.setOriginalDataSource(sds);
> return ea;
> }
>

With this code, the EditableAdapter have not writing capabilities.

I'm looking for a solution which include writing, if someone could point
me out to the solution, it will be very welcome.

best,
amaneiro
_______________________________________________
gvSIG-desktop-devel mailing list
[hidden email]
https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel