Here is a more challenging use of API scripting. This example shows the new
VARPTR (language level addition) and
STRPTR. (implemented at the script level with IDLL calls to low level API functions) For those that like the more traditional function argument format, I added a
_DLL function wrapper in the included .sbh file to allow this. (see second gda.sb example)
Here is the
C code example that this code challenge was based on. (GNOME-DB project site)
' 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 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")
' Use the following format definition if you are passing actual strings not pointers to them.
' DLL("gtk_server_define gda_connection_open_from_string NONE WIDGET 5 STRING STRING POINTER INT NULL")
DLL("gtk_server_define gda_connection_open_from_string NONE WIDGET 5 POINTER POINTER POINTER INT NULL")
DLL("gtk_server_define gtk_widget_destroy NONE NONE 1 WIDGET")
DLL("gtk_server_define gda_execute_select_command NONE WIDGET 3 WIDGET STRING NULL")
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_server_callback NONE STRING 1 STRING")
DLL("gtk_server_define gtk_window_set_default_size NONE NONE 3 WIDGET INT INT")
DLL("gtk_server_define gtk_window_set_title NONE NONE 2 WIDGET STRING")
DLL("gtk_server_define strncpy NONE STRING 3 POINTER POINTER INT")
DLL("gtk_server_define strdup NONE STRING 1 POINTER")
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
CONST provider = 4
CONST cnc_string = 12
FUNCTION _DLL(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9)
LOCAL arg_str
arg_str = STR(a0) & " " & STR(a1) & " " & STR(a2) & " " & STR(a3) & " " & STR(a4) & " " & STR(a5) & " " & STR(a6) & " " & STR(a7) & " " & STR(a8) & " " & STR(a9)
_DLL = DLL(arg_str)
END FUNCTION
FUNCTION STRPTR(pointer)
LOCAL info_str
info_str = 0
DLL("strncpy " & VARPTR(info_str) & " " & pointer & " 4")
' Enabling the next line of code will return the actual string in info_str and not just the pointer to it.
' info_str = DLL("strdup " & info_str)
STRPTR = info_str
END FUNCTION
SUB gtk_main
LOCAL event
REPEAT
event = DLL("gtk_server_callback wait")
UNTIL event = window
END SUB
' GNOME-DB GRID
INCLUDE "db-grid.sbh"
DLL("gtk_init 0 0")
DLL("gdaui_init")
' DB Control Window
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)
IF DLL("gtk_dialog_run " & window) <> GTK_RESPONSE_OK THEN
PRINT "Cancelled!\n"
END
END IF
dsninfo = DLL("gdaui_login_get_connection_information " & login)
cnc = DLL("gda_connection_open_from_string " & STRPTR(dsninfo + provider) & " " & STRPTR(dsninfo + cnc_string) & " " & " 0 0 0")
data_model = DLL("gda_execute_select_command " & cnc & " \"SELECT * FROM customers\" 0")
DLL("gtk_widget_destroy " & window)
' DB Data Grid
window = DLL("gtk_window_new 0")
DLL("gtk_window_set_title " & window & " \"GNOME-DB Grid Control Example\"")
DLL("gtk_window_set_default_size " & window & " 400 200")
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)
gtk_main()
DLL("g_object_unref " & cnc)
' GNOME-DB GRID
INCLUDE "db-grid.sbh"
_DLL("gtk_init", 0, 0)
_DLL("gdaui_init")
' DB Control Window
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)
IF _DLL("gtk_dialog_run", window) <> GTK_RESPONSE_OK THEN
PRINT "Cancelled!\n"
END
END IF
dsninfo = _DLL("gdaui_login_get_connection_information", login)
cnc = _DLL("gda_connection_open_from_string", STRPTR(dsninfo + provider), STRPTR(dsninfo + cnc_string), 0, 0, 0)
data_model = _DLL("gda_execute_select_command", cnc, "\"SELECT * FROM customers\"", 0)
_DLL("gtk_widget_destroy", window)
' DB Data Grid
window = _DLL("gtk_window_new", 0)
_DLL("gtk_window_set_title", window, "\"GNOME-DB Grid Control Example\"")
_DLL("gtk_window_set_default_size", window, 400, 200)
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)
gtk_main()
_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
jrs@Laptop:~/SB/test$
The
GDA-Browser is a common admin/SQL browser for multiple providers. (SQLite3, PostgreSQL and MySQL)
The GdaBrowser program is a graphical tool to get a quick access to a database's structure and contents. This is a work in progress and more features will be added with time.
This tool aims at being simple to use, visually appealing, and full of features usefull to the database administrator or to discover a new database.
The main features are:
- it is possible to open any number of connections withing a running instance
- can access any database Libgda supports
- is fully multi-threaded to the UI never locks on an operation
- is organized around the notion of perspective which correspond to activities, and is easy to extend adding new perspectives
- fullsreen support
- integrated help