Author Topic: GNOME-DB  (Read 19316 times)

JRS

  • Guest
Re: GNOME-DB
« Reply #15 on: December 09, 2010, 08:59:42 PM »
I noticed that gtk_dialog_run is returning a pointer instead of the dialog button response values.

Quote
Blocks in a recursive main loop until the dialog either emits the "response" signal, or is destroyed. If the dialog is destroyed during the call to gtk_dialog_run(), gtk_dialog_run() returns GTK_RESPONSE_NONE. Otherwise, it returns the response ID from the ::response signal emission.

Oh, maybe I need to enable Peter's event (signal) function. (don't know if I have to define it first)

Code: [Select]
' GNOME-DB GRID

' INTERFACE
DECLARE SUB DLL ALIAS "_gtk" LIB "gtk-server"
DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server"

' GDA4
DLL("gtk_server_require libgda-4.0.so")
DLL("gtk_server_require libgda-ui-4.0.so")

' DECLARE
DLL("gtk_server_define gtk_init NONE NONE 2 NULL NULL")
DLL("gtk_server_define gtk_dialog_new_with_buttons NONE WIDGET 8 STRING NULL NULL STRING STRING STRING STRING NULL")
DLL("gtk_server_define gdaui_login_new NONE WIDGET 1 STRING")
DLL("gtk_server_define gtk_box_pack_start NONE NONE 5 WIDGET WIDGET BOOL BOOL INT")
DLL("gtk_server_define gtk_dialog_get_content_area NONE WIDGET 1 WIDGET")
DLL("gtk_server_define gtk_widget_show NONE NONE 1 WIDGET")
DLL("gtk_server_define gtk_dialog_run NONE INT 1 WIDGET")
DLL("gtk_server_define gdaui_login_get_connection_information NONE PTR_WIDGET 1 WIDGET")
DLL("gtk_server_define gda_connection_open_from_string NONE WIDGET 5 STRING STRING STRING INT PTR_LONG")
DLL("gtk_server_define gtk_widget_destroy NONE NONE 1 WIDGET")
DLL("gtk_server_define gda_execute_select_command NONE WIDGET 3 WIDGET STRING PTR_LONG")
DLL("gtk_server_define g_object_unref NONE NONE 1 WIDGET")
DLL("gtk_server_define gtk_window_new delete-event WIDGET 1 INT")
DLL("gtk_server_define gdaui_grid_new NONE WIDGET 1 WIDGET")
DLL("gtk_server_define gtk_container_add NONE NONE 2 WIDGET WIDGET")
DLL("gtk_server_define gtk_widget_show_all NONE NONE 1 WIDGET")

CONST GTK_STOCK_CANCEL = "gtk-cancel"
CONST GTK_STOCK_OK = "gtk-ok"
CONST GTK_RESPONSE_NONE = -1
CONST GTK_RESPONSE_OK = -5
CONST GDA_CONNECTION_OPTIONS_NONE = 0
CONST GTK_WINDOW_TOPLEVEL = 0

' MAIN

DLL("gtk_init 0 0")
DLL("gdaui_init")

window = DLL("gtk_dialog_new_with_buttons \"Select the Data Source to connect to\" NULL 0 GTK_STOCK_CANCEL GTK_RESPONSE_NONE GTK_STOCK_OK GTK_RESPONSE_OK NULL")

login = DLL("gdaui_login_new NULL")
DLL("gtk_box_pack_start " & DLL("gtk_dialog_get_content_area " & window) & " " &  login & " TRUE TRUE 0")
DLL("gtk_widget_show " & login)

DLL("gtk_dialog_run " & window)

' REPEAT
  event = DLL("gtk_server_callback WAIT")
' UNTIL event = GTK_RESPONSE_OK

  
PRINT "Dialog Response: ",event,"\n"

END

With this configuration, the dialog buttions click events aren't been seen and if I close the dialog with the "X" button, SB hangs in the console.

Update

I removed the WAIT (replacing it with 0) from the gtk_server_callback function and the buttons now work again. The event variable always returns 0 if I press OK or CANCEL.
« Last Edit: December 09, 2010, 09:23:26 PM by JRS »

JRS

  • Guest
Re: GNOME-DB
« Reply #16 on: December 09, 2010, 09:34:27 PM »
I added the delete-event to the gtk_dialog_run function as a callback 'label'. I think I need to 'auto-connect' somehow like you do when interfacing to Glade.

Maybe Peter can chime in to better explain how Gtk events (signals) work and are defined.



JRS

  • Guest
Re: GNOME-DB
« Reply #17 on: December 09, 2010, 10:44:16 PM »
I decided to put the OK or CANCEL checking event aside and see if I can get it to generate a grid with data. (reason we came to the party)

dsninfo = DLL("gdaui_login_get_connection_information " & login)

This is the next issue as I see it. How do I get the members of this structure when the function only returns a pointer. From what I have read, the PTR_ feature only works on arguments being passed and not on translation of return values.

I might have hit the wall.

P.S.

@AIR - Your input is needed. Don't just sit there and watch me suffer.


JRS

  • Guest
Re: GNOME-DB
« Reply #18 on: December 09, 2010, 11:19:35 PM »
I now understand what Peter meant when he said this is going to be difficult in SB. I just reread that message Peter sent me before I announced the code challenge thinking the VARPTR was all that was needed. SB (addition to GTK-Server extension module) really needs a MEMGET() function (the other knob) to walk through structures given a pointer.

Another idea is to extend GTK-Server to allow defining structures like you do functions.

Quote
John,

Well I can see the following code:

dsninfo = gdaui_login_get_connection_information (GDAUI_LOGIN (login));
         cnc = gda_connection_open_from_string (dsninfo->provider,
                                                dsninfo->cnc_string,
                                                dsninfo->auth_string,
                                                
GDA_CONNECTION_OPTIONS_NONE, &error);


This is tricky because within an interpreted language you cannot refer  
to members of pointers to structs... I wouldn't know how to use  
'dsninfo->provider' within ScriptBasic for example.

Regards
Peter
« Last Edit: December 09, 2010, 11:35:00 PM by JRS »

JRS

  • Guest
Re: GNOME-DB
« Reply #19 on: December 10, 2010, 02:09:22 AM »
My attempt at reading structures with strncpy().

Code: [Select]
DLL("gtk_server_define strncpy NONE STRING 3 POINTER POINTER INT")

...

dsninfo = DLL("gdaui_login_get_connection_information " & login)

infostr = 0
infoptr = VARPTR(infostr)
DLL("strncpy " & infoptr & " " & dsninfo & " 4")
infoname = 0
nameptr = VARPTR(infoname)
results = DLL("strncpy " & nameptr & " " & infostr & " 16")

PRINT results,"\n"

jrs@Laptop:~/SB/test$ scriba gda.sb
Trying to load plugins in /usr/local/lib/libgda-4.0/plugins...
Loading file /usr/local/lib/libgda-4.0/plugins/libgda-ui-plugins.so...
  - loaded filesel (File selection entry): Entry
  - loaded cird (Entry to hold an IPv4 network specification): Entry
  - loaded text (Multiline text entry): Entry
  - loaded picture (Picture entry): Entry Cell
  - loaded picture_as_string (Picture entry for data stored as a string): Entry Cell
SalesTest
jrs@Laptop:~/SB/test$

It looks like I found a way to read structures.

Code: [Select]
typedef struct {
        gchar    *name;        /* plain text, not RFC 1738 encoded */
        gchar    *provider;    /* plain text, not RFC 1738 encoded */
        gchar    *description; /* plain text, not RFC 1738 encoded */
        gchar    *cnc_string;  /* semi-colon separated <key>=<value> list where <key> and <value> are RFC 1738 encoded */
        gchar    *auth_string; /* semi-colon separated <key>=<value> list where <key> and <value> are RFC 1738 encoded */
        gboolean  is_system;
} GdaDsnInfo;
« Last Edit: December 10, 2010, 03:02:10 AM by JRS »

JRS

  • Guest
Re: GNOME-DB
« Reply #20 on: December 10, 2010, 04:54:58 AM »
I'm able to get the name, provider and description from the dsninfo structure. If I try to access the structure beyond that, I get a segment fault. I'm not sure what dsninfo is suppose to provide at this point.

Code: [Select]
dsninfo = DLL("gdaui_login_get_connection_information " & login)
info = 0
infoptr = VARPTR(info)
DLL("strncpy " & infoptr & " " & dsninfo & " 4")
dsn_name = DLL("strncpy " & VARPTR(infoptr) & " " & info & " 16")
info = 0
infoptr = VARPTR(info)
DLL("strncpy " & infoptr & " " & dsninfo + 4 & " 4")
dsn_provider = DLL("strncpy " & VARPTR(infoptr) & " " & info & " 16")
info = 0
infoptr = VARPTR(info)
DLL("strncpy " & infoptr & " " & dsninfo + 8 & " 4")
dsn_desc = DLL("strncpy " & VARPTR(infoptr) & " " & info & " 37")


PRINT dsn_name,"\n"
PRINT dsn_provider,"\n"
PRINT dsn_desc,"\n"

jrs@Laptop:~/SB/test$ scriba gda.sb
Trying to load plugins in /usr/local/lib/libgda-4.0/plugins...
Loading file /usr/local/lib/libgda-4.0/plugins/libgda-ui-plugins.so...
  - loaded filesel (File selection entry): Entry
  - loaded cird (Entry to hold an IPv4 network specification): Entry
  - loaded text (Multiline text entry): Entry
  - loaded picture (Picture entry): Entry Cell
  - loaded picture_as_string (Picture entry for data stored as a string): Entry Cell
SalesTest
SQLite
Test database for a sales department
jrs@Laptop:~/SB/test$


JRS

  • Guest
Re: GNOME-DB
« Reply #21 on: December 10, 2010, 05:53:07 AM »
My problem seemed to be the reuse of my VARPRT variables. I'm now getting all the dsninfo data from the structure but now have connection issues. I'm done for now and will work on it later.

Code: [Select]
' GNOME-DB GRID

' INTERFACE
DECLARE SUB DLL ALIAS "_gtk" LIB "gtk-server"
DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server"

' GDA4
DLL("gtk_server_require libgda-4.0.so")
DLL("gtk_server_require libgda-ui-4.0.so")

' SYSTEM
DLL("gtk_server_require libc.so.6")

' DECLARE
DLL("gtk_server_define gtk_init NONE NONE 2 NULL NULL")
DLL("gtk_server_define gtk_dialog_new_with_buttons NONE WIDGET 8 STRING NULL NULL STRING STRING STRING STRING NULL")
DLL("gtk_server_define gdaui_login_new NONE WIDGET 1 STRING")
DLL("gtk_server_define gtk_box_pack_start NONE NONE 5 WIDGET WIDGET BOOL BOOL INT")
DLL("gtk_server_define gtk_dialog_get_content_area NONE WIDGET 1 WIDGET")
DLL("gtk_server_define gtk_widget_show NONE NONE 1 WIDGET")
DLL("gtk_server_define gtk_dialog_run delete-event INT 1 WIDGET")
DLL("gtk_server_define gdaui_login_get_connection_information NONE WIDGET 1 WIDGET")
DLL("gtk_server_define gda_connection_open_from_string NONE WIDGET 5 STRING STRING STRING INT PTR_LONG")
DLL("gtk_server_define gtk_widget_destroy NONE NONE 1 WIDGET")
DLL("gtk_server_define gda_execute_select_command NONE WIDGET 3 WIDGET STRING PTR_LONG")
DLL("gtk_server_define g_object_unref NONE NONE 1 WIDGET")
DLL("gtk_server_define gtk_window_new delete-event WIDGET 1 INT")
DLL("gtk_server_define gdaui_grid_new NONE WIDGET 1 WIDGET")
DLL("gtk_server_define gtk_container_add NONE NONE 2 WIDGET WIDGET")
DLL("gtk_server_define gtk_widget_show_all NONE NONE 1 WIDGET")
DLL("gtk_server_define gtk_dialog_response NONE WIDGET 2 WIDGET INT")
DLL("gtk_server_define gtk_server_callback NONE STRING 1 STRING")
DLL("gtk_server_define gda_connection_open NONE BOOL 2 WIDGET PTR_LONG")
DLL("gtk_server_define strncpy NONE STRING 3 POINTER POINTER INT")


CONST GTK_STOCK_CANCEL = "gtk-cancel"
CONST GTK_STOCK_OK = "gtk-ok"
CONST GTK_RESPONSE_NONE = -1
CONST GTK_RESPONSE_OK = -5
CONST GDA_CONNECTION_OPTIONS_NONE = 0
CONST GTK_WINDOW_TOPLEVEL = 0

' MAIN

DLL("gtk_init 0 0")
DLL("gdaui_init")

window = DLL("gtk_dialog_new_with_buttons \"Select the Data Source to connect to\" NULL 0 GTK_STOCK_CANCEL GTK_RESPONSE_NONE GTK_STOCK_OK GTK_RESPONSE_OK NULL")
login = DLL("gdaui_login_new NULL")
DLL("gtk_box_pack_start " & DLL("gtk_dialog_get_content_area " & window) & " " &  login & " TRUE TRUE 0")
DLL("gtk_widget_show " & login)
response_id = DLL("gtk_dialog_run " & window)

' Event process needed to check for cancel or okay

dsninfo = DLL("gdaui_login_get_connection_information " & login)
info_name = 0
info_name_ptr = VARPTR(info_name)
DLL("strncpy " & info_name_ptr & " " & dsninfo & " 4")
dsn_name = DLL("strncpy " & VARPTR(info_name_ptr) & " " & info_name & " 16")
info_provider = 0
info_provider_ptr = VARPTR(info_provider)
DLL("strncpy " & info_provider_ptr & " " & dsninfo + 4 & " 4")
dsn_provider = DLL("strncpy " & VARPTR(info_provider_ptr) & " " & info_provider & " 16")
info_desc = 0
info_desc_ptr = VARPTR(info_desc)
DLL("strncpy " & info_desc_ptr & " " & dsninfo + 8 & " 4")
dsn_desc = DLL("strncpy " & VARPTR(info_desc_ptr) & " " & info_desc & " 37")
info_cnc = 0
info_cnc_ptr = VARPTR(info_cnc)
DLL("strncpy " & info_cnc_ptr & " " & dsninfo + 12 & " 4")
dsn_cnc = DLL("strncpy " & VARPTR(info_cnc_ptr) & " " & info_cnc & " 30")

PRINT dsn_name,"\n"
PRINT dsn_provider,"\n"
PRINT dsn_desc,"\n"
PRINT dsn_cnc,"\n"

gdaerr = 0
result = DLL("gda_connection_open_from_string " & dsn_provider & " " & dsn_cnc & " NULL " & GDA_CONNECTION_OPTIONS_NONE & " " & VARPTR(gdaerr))
SPLIT result BY " " TO cnc,gdamsg

DLL("gtk_widget_destroy" & window)

IF NOT(cnc) THEN
  PRINT "Could not open connection: \n",gdamsg,"\n"
  END
END IF

gdaerr = 0
result = DLL("gda_execute_select_command " & cnc & " SELECT * FROM customers " & VARPTR(gdaerr))
SPLIT result BY " " TO data_model,gdamsg

IF NOT(data_model) THEN
  PRINT "Could not execute the SQL command: \n",gdamsg,"\n"
  DLL("g_object_unref " & cnc)
  END
END IF

window = DLL("gtk_window_new GTK_WINDOW_TOPLEVEL")
grid = DLL("gdaui_grid_new " & data_model)

DLL("g_object_unref " & data_model)
DLL("gtk_container_add " & window & " " & grid)
DLL("gtk_widget_show_all " & window)

' EVENT

' gtk_main();


' END

DLL("g_object_unref " & cnc)

jrs@Laptop:~/SB/test$ scriba gda.sb
Trying to load plugins in /usr/local/lib/libgda-4.0/plugins...
Loading file /usr/local/lib/libgda-4.0/plugins/libgda-ui-plugins.so...
  - loaded filesel (File selection entry): Entry
  - loaded cird (Entry to hold an IPv4 network specification): Entry
  - loaded text (Multiline text entry): Entry
  - loaded picture (Picture entry): Entry Cell
  - loaded picture_as_string (Picture entry for data stored as a string): Entry Cell
SalesTest
SQLite
Test database for a sales department
DB_DIR=/home/jrs/.local/share/

(<unknown>:3233): GLib-CRITICAL **: g_strchug: assertion `string != NULL' failed

(<unknown>:3233): GLib-CRITICAL **: g_strchomp: assertion `string != NULL' failed
Could not open connection:
169489076
jrs@Laptop:~/SB/test$
« Last Edit: December 10, 2010, 06:23:45 AM by JRS »

AIR

  • Guest
Re: GNOME-DB
« Reply #22 on: December 10, 2010, 07:43:19 AM »
Here's the final MBC version (verbose version):
Code: [Select]
$EXECON "$(pkg-config --libs --cflags libgda-ui-4.0)"
$EXESTRIP

#INCLUDE <libgda.h>
#INCLUDE <libgda-ui/libgda-ui.h>



gtk_init (&argc, &argv)
gdaui_init ()

'~ /* create a login dialog window to let the user select a data source (or declare a new one)
'~ * and specify a username and password if necessary
'~ */
DIM window as GtkWidget PTR, login as GtkWidget PTR
window = gtk_dialog_new_with_buttons ("Select the Data Source to connect to", NULL, GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_NONE, GTK_STOCK_OK,  GTK_RESPONSE_OK,  NULL)

'~ /* Create the login widget */
login = gdaui_login_new (NULL)
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))),login, TRUE, TRUE, 0)
gtk_widget_show (login)

IF gtk_dialog_run (GTK_DIALOG (window)) != GTK_RESPONSE_OK THEN
PRINT "Cancelled!"
END = 0
END IF

'~ /* OPEN the connection */
DIM cnc as GdaConnection PTR, error as GError PTR
!const GdaDsnInfo *dsninfo;

dsninfo = gdaui_login_get_connection_information (GDAUI_LOGIN (login))
cnc = gda_connection_open_from_string (dsninfo->provider,  dsninfo->cnc_string,  dsninfo->auth_string, GDA_CONNECTION_OPTIONS_NONE, &error)

gtk_widget_destroy (window)

IF NOT cnc THEN
PRINT "Could not open connection: ";error;error->message
END = 1
END IF

'~ /* execute a SELECT statement; here the easiest API IS used */
RAW data_model as GdaDataModel PTR
data_model = gda_execute_select_command (cnc, "SELECT * FROM customers", &error)
IF NOT data_model THEN
PRINT "Could not execute the SQL command: ";error;error->message
'~ /* CLOSE the connection */
g_object_unref (cnc)
END = 1
END IF

'~ /* Create a main window and SHOW the DATA model IN a grid */
DIM grid as GtkWidget PTR
window = gtk_window_new (GTK_WINDOW_TOPLEVEL)

'~ /* Set Minimum size of window, and connect destroy event - AIR */
g_object_set(G_OBJECT(window),"width-request",400,"height-request",200,NULL);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

grid = gdaui_grid_new (data_model)
g_object_unref (data_model)
gtk_container_add (GTK_CONTAINER (window), grid)
gtk_widget_show_all (window)

gtk_main()

g_object_unref (cnc)

A.


JRS

  • Guest
Re: GNOME-DB
« Reply #23 on: December 10, 2010, 01:22:25 PM »
Thanks Armando for your BCX Basic version of the code challenge.

I was able to get just the text of the button label working but no images buttons yet. I have no idea why I can't get stock images to show on the buttons.
Code: [Select]
DLL("gtk_server_define gtk_dialog_new_with_buttons NONE WIDGET 8 STRING WIDGET INT STRING INT STRING INT NULL")

CONST GTK_STOCK_CANCEL = "gtk-cancel"
CONST GTK_STOCK_OK = "gtk-ok"
CONST GTK_RESPONSE_NONE = -1
CONST GTK_RESPONSE_OK = -5
CONST GDA_CONNECTION_OPTIONS_NONE = 0
CONST GTK_WINDOW_TOPLEVEL = 0
CONST GTK_DIALOG_MODAL = 1

window = DLL("gtk_dialog_new_with_buttons \"Select the Data Source to connect to\" 0 " & GTK_DIALOG_MODAL & " " & GTK_STOCK_CANCEL & " " & GTK_RESPONSE_NONE & " " & GTK_STOCK_OK & " " & GTK_RESPONSE_OK & " 0")

« Last Edit: December 10, 2010, 01:24:28 PM by JRS »

Pjot

  • Guest
Re: GNOME-DB
« Reply #24 on: December 10, 2010, 02:36:17 PM »
Quote
I have no idea why I can't get stock images to show on the buttons.

Well I do. You are using Ubuntu, right? For some reason they disable the display of stock buttons by default. You can enable it with the following command:

Quote
sudo gconftool-2 --type boolean --set /desktop/gnome/interface/buttons_have_icons 1

Hope this helps,
Peter

JRS

  • Guest
Re: GNOME-DB
« Reply #25 on: December 10, 2010, 03:07:39 PM »
Hi Peter,

I'm running under Ubuntu 10.10 32 bit. I tried the command you offered but with no change. (text on buttons only)

@AIR- Is your window set size needed to get it to show? (your addition to default code)

Update

Here is the command you need to get button images to work on Ubuntu.

press alt +F2
type 'gconf-editor'
navigate to '/desktop/gnome/interface'
check 'button_have_icons'
« Last Edit: December 10, 2010, 03:23:19 PM by JRS »

JRS

  • Guest
Re: GNOME-DB
« Reply #26 on: December 10, 2010, 03:45:31 PM »
Here is where I'm at currently.

Issues:

  • strncpy is having issues with grabbing the length of the string I requested. This normally happens at the end of structures. For example, I know how long the cnc striing should be and what it should contain. If I request the correct length, I'll get a GTK-Server trace back dump or a seg fault. I ended up having to hard code the cnc string to get by it.
  • I'm not seeing a grid window and it looks like I have everything needed to show it. AIR added a sizing command for the window which I haven't tried yet.
  • Not sure how to get the button that was pressed in the DB control panel. Is this a signal response or is there a function I need to call to get the button that was pressed?
  • I haven't got there yet but I'm assuming I can use the GTK-Server event handler for the grid window.

Code: [Select]
' GNOME-DB GRID

' INTERFACE
DECLARE SUB DLL ALIAS "_gtk" LIB "gtk-server"
DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server"

' GDA4
DLL("gtk_server_require libgda-4.0.so")
DLL("gtk_server_require libgda-ui-4.0.so")

' SYSTEM
DLL("gtk_server_require libc.so.6")

' DECLARE
DLL("gtk_server_define gtk_init NONE NONE 2 NULL NULL")
DLL("gtk_server_define gtk_dialog_new_with_buttons NONE WIDGET 8 STRING WIDGET INT STRING INT STRING INT NULL")
DLL("gtk_server_define gdaui_login_new NONE WIDGET 1 STRING")
DLL("gtk_server_define gtk_box_pack_start NONE NONE 5 WIDGET WIDGET BOOL BOOL INT")
DLL("gtk_server_define gtk_dialog_get_content_area NONE WIDGET 1 WIDGET")
DLL("gtk_server_define gtk_widget_show NONE NONE 1 WIDGET")
DLL("gtk_server_define gtk_dialog_run delete-event INT 1 WIDGET")
DLL("gtk_server_define gdaui_login_get_connection_information NONE WIDGET 1 WIDGET")
DLL("gtk_server_define gda_connection_open_from_string NONE WIDGET 5 STRING STRING STRING INT LONG")
DLL("gtk_server_define gtk_widget_destroy NONE NONE 1 WIDGET")
DLL("gtk_server_define gda_execute_select_command NONE WIDGET 3 WIDGET STRING PTR_LONG")
DLL("gtk_server_define g_object_unref NONE NONE 1 WIDGET")
DLL("gtk_server_define gtk_window_new delete-event WIDGET 1 INT")
DLL("gtk_server_define gdaui_grid_new NONE WIDGET 1 WIDGET")
DLL("gtk_server_define gtk_container_add NONE NONE 2 WIDGET WIDGET")
DLL("gtk_server_define gtk_widget_show_all NONE NONE 1 WIDGET")
DLL("gtk_server_define gtk_dialog_response NONE WIDGET 2 WIDGET INT")
DLL("gtk_server_define gtk_server_callback NONE STRING 1 STRING")
DLL("gtk_server_define gda_connection_open NONE BOOL 2 WIDGET PTR_LONG")
DLL("gtk_server_define strncpy NONE STRING 3 POINTER POINTER INT")


CONST GTK_STOCK_CANCEL = "gtk-cancel"
CONST GTK_STOCK_OK = "gtk-ok"
CONST GTK_RESPONSE_NONE = -1
CONST GTK_RESPONSE_OK = -5
CONST GDA_CONNECTION_OPTIONS_NONE = 0
CONST GTK_WINDOW_TOPLEVEL = 0
CONST GTK_DIALOG_MODAL = 1

' MAIN

DLL("gtk_init 0 0")
DLL("gdaui_init")

window = DLL("gtk_dialog_new_with_buttons \"Select the Data Source to connect to\" 0 " & GTK_DIALOG_MODAL & " " & GTK_STOCK_CANCEL & " " & GTK_RESPONSE_NONE & " " & GTK_STOCK_OK & " " & GTK_RESPONSE_OK & " 0")
login = DLL("gdaui_login_new NULL")
DLL("gtk_box_pack_start " & DLL("gtk_dialog_get_content_area " & window) & " " &  login & " TRUE TRUE 0")
DLL("gtk_widget_show " & login)
response_id = DLL("gtk_dialog_run " & window)

' Event process needed to check for cancel or okay

dsninfo = DLL("gdaui_login_get_connection_information " & login)
info_name = 0
info_name_ptr = VARPTR(info_name)
DLL("strncpy " & info_name_ptr & " " & dsninfo & " 4")
dsn_name = DLL("strncpy " & VARPTR(info_name_ptr) & " " & info_name & " 16")
info_provider = 0
info_provider_ptr = VARPTR(info_provider)
DLL("strncpy " & info_provider_ptr & " " & dsninfo + 4 & " 4")
dsn_provider = DLL("strncpy " & VARPTR(info_provider_ptr) & " " & info_provider & " 16")
info_desc = 0
info_desc_ptr = VARPTR(info_desc)
DLL("strncpy " & info_desc_ptr & " " & dsninfo + 8 & " 4")
dsn_desc = DLL("strncpy " & VARPTR(info_desc_ptr) & " " & info_desc & " 36")
' info_cnc = 0
' info_cnc_ptr = VARPTR(info_cnc)
' DLL("strncpy " & info_cnc_ptr & " " & dsninfo + 12 & " 4")
' dsn_cnc = DLL("strncpy " & VARPTR(info_cnc_ptr) & " " & info_cnc & " 60")
dsn_cnc = "DB_DIR=/home/jrs/.local/share/libgda;DB_NAME=sales_test.db"

PRINT TRIM(dsn_name),"\n"
PRINT TRIM(dsn_provider),"\n"
PRINT LEFT(dsn_desc,36),"\n"
PRINT dsn_cnc,"\n"

gdaerr = 0

cnc = DLL("gda_connection_open_from_string " & dsn_provider & " " & dsn_cnc & " \"\" 0 " & VARPTR(gdaerr))

DLL("gtk_widget_destroy" & window)

' IF NOT(cnc) THEN
'   PRINT "Could not open connection: \n",gdamsg,"\n"
'   END
' END IF

gdaerr = 0
result = DLL("gda_execute_select_command " & cnc & " \"SELECT * FROM customers;\" NULL")

SPLIT result BY " " TO data_model,gdamsg


' IF NOT(data_model) THEN
'   PRINT "Could not execute the SQL command: \n",gdamsg,"\n"
DLL("g_object_unref " & cnc)
'   END
' END IF
 
window = DLL("gtk_window_new 0")
PRINT "window: ",window,"\n"

grid = DLL("gdaui_grid_new " & data_model)
PRINT "grid: ",grid,"\n"


DLL("g_object_unref " & data_model)
DLL("gtk_container_add " & window & " " & grid)
DLL("gtk_widget_show_all " & window)

' EVENT

' gtk_main();


' END

DLL("g_object_unref " & cnc)

jrs@Laptop:~/SB/test$ scriba gda.sb
Trying to load plugins in /usr/local/lib/libgda-4.0/plugins...
Loading file /usr/local/lib/libgda-4.0/plugins/libgda-ui-plugins.so...
  - loaded filesel (File selection entry): Entry
  - loaded cird (Entry to hold an IPv4 network specification): Entry
  - loaded text (Multiline text entry): Entry
  - loaded picture (Picture entry): Entry Cell
  - loaded picture_as_string (Picture entry for data stored as a string): Entry Cell
SalesTest
SQLite
Test database for a sales department
DB_DIR=/home/jrs/.local/share/libgda;DB_NAME=sales_test.db
window: 159890144
grid: 160434880
jrs@Laptop:~/SB/test$
« Last Edit: December 10, 2010, 03:54:07 PM by JRS »

AIR

  • Guest
Re: GNOME-DB
« Reply #27 on: December 10, 2010, 04:37:36 PM »
The first place you might look with your strncpy call is the  copying into a buffer that has no defined size.  You're possibly overwriting memory, which may be the cause of the segfault/backtrace.


JRS

  • Guest
Re: GNOME-DB
« Reply #28 on: December 10, 2010, 06:27:08 PM »
VARPTR() doesn't seem to work if I pass it a string based variable type. I can only pass SB variables that are initialized with a 0. (zero) Trying to get the structure info with strncpy() is too unstable using GTK-Server. I personally think there is a bug when trying to return a STRING response type. You can see what I mean in the following backtrace dump. Notice it gets the string but fails in GTK-Server.

jrs@Laptop:~/SB/test$ scriba gda.sb
Trying to load plugins in /usr/local/lib/libgda-4.0/plugins...
Loading file /usr/local/lib/libgda-4.0/plugins/libgda-ui-plugins.so...
  - loaded filesel (File selection entry): Entry
  - loaded cird (Entry to hold an IPv4 network specification): Entry
  - loaded text (Multiline text entry): Entry
  - loaded picture (Picture entry): Entry Cell
  - loaded picture_as_string (Picture entry for data stored as a string): Entry Cell
SalesTest
SQLite
Test database for a sales department
DB_DIR=/home/jrs/.local/share/libgda;DB_NAME=sales_test.db
*** glibc detected *** scriba: munmap_chunk(): invalid pointer: 0x08dac2a0 ***
======= Backtrace: =========
/lib/libc.so.6(+0x6c501)[0x194501]
/lib/libc.so.6(+0x6d77e)[0x19577e]
scriba[0x8053f6b]
scriba[0x8053fc8]
scriba[0x8054c87]
scriba[0x8054788]
scriba[0x804af9f]
/lib/libc.so.6(__libc_start_main+0xe7)[0x13ece7]
scriba[0x80497e1]

Code: [Select]
DLL("gtk_server_define strncpy NONE STRING 3 POINTER POINTER INT")

...

dsninfo = DLL("gdaui_login_get_connection_information " & login)
info_name = 0
info_name_ptr = VARPTR(info_name)
tmp_str = DLL("strncpy " & info_name_ptr & " " & dsninfo & " 4")
dsn_name = DLL("strncpy " & VARPTR(info_name_ptr) & " " & info_name & " 16")
info_provider = 0
info_provider_ptr = VARPTR(info_provider)
tmp_str = DLL("strncpy " & info_provider_ptr & " " & dsninfo + 4 & " 4")
dsn_provider = DLL("strncpy " & VARPTR(info_provider_ptr) & " " & info_provider & " 16")
info_desc = 0
info_desc_ptr = VARPTR(info_desc)
tmp_str = DLL("strncpy " & info_desc_ptr & " " & dsninfo + 8 & " 4")
dsn_desc = DLL("strncpy " & VARPTR(info_desc_ptr) & " " & info_desc & " 37")
info_cnc = 0
info_cnc_ptr = VARPTR(info_cnc)
tmp_str = DLL("strncpy " & info_cnc_ptr & " " & (dsninfo + 12) & " 4")
dsn_cnc = DLL("strncpy " & VARPTR(info_cnc_ptr) & " " & info_cnc & " 59")

' dsn_cnc = "DB_DIR=/home/jrs/.local/share/libgda;DB_NAME=sales_test.db"

PRINT dsn_name,"\n"
PRINT dsn_provider,"\n"
PRINT dsn_desc,"\n"
PRINT dsn_cnc,"\n"

END

I think my only option at this point is to plead with AIR for help for a string=MEMGET(pointer,size) function added to the SB gtk-server.so extension module.

Maybe all that is needed is a small tweak and a copy of the VARPTR() function to create a STRPTR() function so I can DIM some space and not over write memory as what seems to be happening when SB thinks I'm dealing with a long pointer.

Update

I have tried every possible combination to make this work with the tools at my disposal. I could maybe get this to work with some hard coded strings but that's BS and not something I would post. I hate to give up but I need to stop wasting my time on this looking for workarounds.
« Last Edit: December 10, 2010, 09:55:48 PM by JRS »

JRS

  • Guest
Re: GNOME-DB
« Reply #29 on: December 11, 2010, 12:14:49 AM »
I can't tell you the number of times I have given up on stuff and gone back to it just ONE LAST TIME and got it working.

Code: [Select]
dsninfo = DLL("gdaui_login_get_connection_information " & login)
info_name = 0
DLL("strncpy " & VARPTR(info_name) & " " & dsninfo & " 4")
info_name = DLL("strdup " & info_name)
info_provider = 0
DLL("strncpy " & VARPTR(info_provider) & " " & dsninfo + 4 & " 4")
info_provider = DLL("strdup " & info_provider)
info_desc = 0
DLL("strncpy " & VARPTR(info_desc) & " " & dsninfo + 8 & " 4")
info_desc = DLL("strdup " & info_desc)
info_cnc = 0
DLL("strncpy " & VARPTR(info_cnc) & " " & dsninfo + 12 & " 4")
info_cnc = DLL("strdup " & info_cnc)

PRINT info_name,"\n"
PRINT info_provider,"\n"
PRINT info_desc,"\n"
PRINT info_cnc,"\n"

jrs@Laptop:~/SB/test$ scriba gda.sb
Trying to load plugins in /usr/local/lib/libgda-4.0/plugins...
Loading file /usr/local/lib/libgda-4.0/plugins/libgda-ui-plugins.so...
  - loaded filesel (File selection entry): Entry
  - loaded cird (Entry to hold an IPv4 network specification): Entry
  - loaded text (Multiline text entry): Entry
  - loaded picture (Picture entry): Entry Cell
  - loaded picture_as_string (Picture entry for data stored as a string): Entry Cell
SalesTest
SQLite
Test database for a sales department
DB_DIR=/home/jrs/.local/share/libgda;DB_NAME=sales_test.db
jrs@Laptop:~/SB/test$


@Armando - Can you confirm for me that there isn't a auth_string as part of the dsninfo structure?



« Last Edit: December 11, 2010, 12:58:37 AM by JRS »