libgda r3278 - in trunk: . libgda/sqlite/virtual tools



Author: vivien
Date: Tue Jan  6 19:29:20 2009
New Revision: 3278
URL: http://svn.gnome.org/viewvc/libgda?rev=3278&view=rev

Log:
2009-01-06  Vivien Malerba <malerba gnome-db org>

        * tools/: embedded web server improvements:
         - fix a bug where big data models were truncated
         - UI corrections
         - multiple simultaneous consoles now works
        * libgda/sqlite/virtual/gda-vconnection-hub.c: only bind the tables
        which require a complete name (<schema>.<name>)


Modified:
   trunk/ChangeLog
   trunk/libgda/sqlite/virtual/gda-vconnection-hub.c
   trunk/tools/gda-sql.c
   trunk/tools/irb.css
   trunk/tools/irb.js
   trunk/tools/mouseapp_2.js
   trunk/tools/mouseirb_2.js
   trunk/tools/web-server.c

Modified: trunk/libgda/sqlite/virtual/gda-vconnection-hub.c
==============================================================================
--- trunk/libgda/sqlite/virtual/gda-vconnection-hub.c	(original)
+++ trunk/libgda/sqlite/virtual/gda-vconnection-hub.c	Tue Jan  6 19:29:20 2009
@@ -451,10 +451,21 @@
 	model = gda_connection_get_meta_store_data (hc->cnc, GDA_CONNECTION_META_TABLES, error, 0);
 	if (!model)
 		return FALSE;
+
 	nrows = gda_data_model_get_n_rows (model);
 	for (i = 0; i < nrows; i++) {
 		const GValue *cv = gda_data_model_get_value_at (model, 0, i, error);
-		if (!cv || !table_add (hc, cv, error)) {
+		const GValue *cv1 = gda_data_model_get_value_at (model, 2, i, error);
+		if (!cv || !cv1) {
+			g_object_unref (model);
+			return FALSE;
+		}
+
+		/* ignore tables which require a complete name <schema>.<name> */
+		if (!gda_value_differ (cv, cv1))
+			continue;
+
+		if (!table_add (hc, cv, error)) {
 			g_object_unref (model);
 			return FALSE;
 		}

Modified: trunk/tools/gda-sql.c
==============================================================================
--- trunk/tools/gda-sql.c	(original)
+++ trunk/tools/gda-sql.c	Tue Jan  6 19:29:20 2009
@@ -1537,10 +1537,8 @@
 		table = xmlNewChild (html, NULL, BAD_CAST "table", NULL);
 		xmlSetProp (table, BAD_CAST "border", BAD_CAST "1");
 		
-		if (g_object_get_data (G_OBJECT (model), "name")) {
-			node = xmlNewChild (table, NULL, BAD_CAST "caption", NULL);
-			xmlNewTextChild (node, NULL, BAD_CAST "big", g_object_get_data (G_OBJECT (model), "name"));
-		}
+		if (g_object_get_data (G_OBJECT (model), "name"))
+			xmlNewTextChild (table, NULL, BAD_CAST "caption", g_object_get_data (G_OBJECT (model), "name"));
 
 		ncols = gda_data_model_get_n_columns (model);
 		nrows = gda_data_model_get_n_rows (model);
@@ -1577,8 +1575,6 @@
 		xmlNodeSetContent (node, BAD_CAST str);
 		g_free (str);
 
-	        xmlNewChild (html, NULL, BAD_CAST "br", NULL);
-
 		buffer = xmlBufferCreate ();
 		xmlNodeDump (buffer, NULL, html, 0, 1);
 		str = g_strdup ((gchar *) xmlBufferContent (buffer));
@@ -2704,7 +2700,7 @@
 }
 
 static void
-vconnection_hub_foreach_cb (SqlConsole *console, GdaConnection *cnc, const gchar *ns, GString *string)
+vconnection_hub_foreach_cb (GdaConnection *cnc, const gchar *ns, GString *string)
 {
 	if (string->len > 0)
 		g_string_append_c (string, '\n');

Modified: trunk/tools/irb.css
==============================================================================
--- trunk/tools/irb.css	(original)
+++ trunk/tools/irb.css	Tue Jan  6 19:29:20 2009
@@ -8,7 +8,7 @@
 
 /* irb terminal */
 #terminal {
-    background-color: #f2f2f0;
+    /*background-color: #f2f2f0;*/
     width: 100%;
     height: 78%;
     overflow: auto; 

Modified: trunk/tools/irb.js
==============================================================================
--- trunk/tools/irb.js	(original)
+++ trunk/tools/irb.js	Tue Jan  6 19:29:20 2009
@@ -27,18 +27,30 @@
 
 //the main function, call to the effect object
 window.onload = function() {
+	$.ajax({url: "/~irb?cmd=!INIT!IRB!", type: "GET", 
+		complete: (function(r) {
+				var xmlDoc=r.responseXML.documentElement;
+				
+				var cid = xmlDoc.getElementsByTagName("cid")[0].childNodes[0].nodeValue;
+				window.irb.options.gdaid = cid;
+				
+				var pt = xmlDoc.getElementsByTagName("prompt")[0].childNodes[0].nodeValue;
+				var trimmed = pt.replace(/^\s+|\s+$/g, '') ;
+				window.irb.options.ps = "\033[1;31m" + trimmed + "\033[m";
+				window.irb.prompt();
+			}), type:"xml"});
+
     window.irb = new MouseApp.Irb('#irb', {
         rows: 25,
 	columns: 115,
         name: 'IRB',
-        greeting: "%+r Interactive SQL console %-r\n use .? to get help",
-        ps: '\033[1;31mgda>\033[m',
+        greeting: "Use .? to get help\n",
+        ps: "",
         user: 'guest',
         host: 'tryruby',
         irbUrl: '/~irb',
 	gdaid: 'none',
         init: function () {
-			    
         },
     });
 }

Modified: trunk/tools/mouseapp_2.js
==============================================================================
--- trunk/tools/mouseapp_2.js	(original)
+++ trunk/tools/mouseapp_2.js	Tue Jan  6 19:29:20 2009
@@ -572,7 +572,9 @@
             ps = this.options.ps; pt = true;
         }
         this.write(ps, pt);
-        this.putc(1, 0);
+        if (ps!="") {
+            this.putc(1, 0);
+	}
         this.typingOn();
     },
 

Modified: trunk/tools/mouseirb_2.js
==============================================================================
--- trunk/tools/mouseirb_2.js	(original)
+++ trunk/tools/mouseirb_2.js	Tue Jan  6 19:29:20 2009
@@ -33,14 +33,6 @@
   this.initWindow();
   this.setup();
   this.irbInit = false;
-  this.fireOffCmd(".c", (function(r) {
-                                        /*alert (r.responseText);*/
-                                        var xmlDoc=r.responseXML.documentElement;
-                                        var txt;
-                                        if (xmlDoc.getElementsByTagName("cmde")[0].childNodes[0])
-                                            txt = xmlDoc.getElementsByTagName("cmde")[0].childNodes[0].nodeValue;
-                                        var pt = xmlDoc.getElementsByTagName("prompt")[0].childNodes[0].nodeValue;
-                                }));
 };
 
 $.extend(MouseApp.Irb.prototype, MouseApp.Terminal.prototype, {
@@ -52,23 +44,8 @@
 
     fireOffCmd: function(cmd, func) {
       var irb = this;
-        if (!this.irbInit)
-        {
-          $.ajax({url: this.options.irbUrl + "?" + this.cmdToQuery("!INIT!IRB!"), type: "GET",
-				  complete: (function(r) { 
-						  irb.irbInit = true; 
-						  var xmlDoc=r.responseXML.documentElement;
-						  var cid = xmlDoc.getElementsByTagName("cid")[0].childNodes[0].nodeValue;
-						  irb.options.gdaid = cid;
-						  irb.fireOffCmd(cmd, func); 
-					  }), 
-				  type:"xml"});
-        }
-        else
-        {
           $.ajax({url: this.options.irbUrl + "?" + this.cmdToQuery(cmd), type: "GET", 
             complete: func});
-        }
     },
 
     reply: function(str,prompt) {
@@ -85,20 +62,36 @@
                 } catch (e) {}
                 str = str.replace(js_payload, '');
             }
+
             var pr_re = new RegExp("(^|\\n)=>");
             if ( str.match( pr_re ) ) {
               str = str.replace(new RegExp("(^|\\n)=>"), "$1\033[1;34m=>\033[m");
             } else {
               str = str.replace(new RegExp("(^|\\n)= (.+?) ="), "$1\033[1;33m$2\033[m");
             }
+
 	    if (str.search(/^</) != -1) {
 		    var irbdiv = $("#irb");
-		    this.cursorOff();
+
+		    $("#irb div:last-child").hide();
+
 		    var table = $("<div class=\"tcontents\">"+str+"</div>");
+		    table.children(":first").children(":first").attr("class","ctable");
+		    var folded = $("<div></div>");
+		    var nbrows = table.children(":first").children(":last");
+		    nbrows.appendTo(folded);
+		    nbrows.css("margin","0");
+
 		    irbdiv.append(table);
-		    table.resizable({"autoHide":true, "knobHandles":true});
-		    table.dblclick(function() {table.hide("slide");});
-			       
+		    table.resizable({"autoHide":true});
+		    table.dblclick(function() {table.hide(); folded.show();});
+		    
+		    irbdiv.append(folded);
+		    folded.hide();
+		    folded.dblclick(function() {table.show(); folded.hide();});
+
+
+		    this.cursorOff();
 		    this.advanceLine();
 		    this.cursorOn();
 	    }
@@ -138,11 +131,15 @@
             } else {
                 var term = this;
                 this.fireOffCmd(cmd, (function(r) {
-					/*alert (r.responseText);*/
 					var xmlDoc=r.responseXML.documentElement;
 					var txt;
-					if (xmlDoc.getElementsByTagName("cmde")[0].childNodes[0])
-					    txt = xmlDoc.getElementsByTagName("cmde")[0].childNodes[0].nodeValue;
+					if (xmlDoc.getElementsByTagName("cmde")[0].childNodes[0]) {
+						// it appears Firefox and some others split long text nodes into several
+						// smaller chunks of 4kb, so we need to get all of them.
+						txt="";
+						for (i = 0; i < xmlDoc.getElementsByTagName("cmde")[0].childNodes.length; i++)
+							txt += xmlDoc.getElementsByTagName("cmde")[0].childNodes[i].nodeValue
+					}
 					var pt = xmlDoc.getElementsByTagName("prompt")[0].childNodes[0].nodeValue;
 					term.reply(txt ? txt: '', pt ? pt : null);
 				}));

Modified: trunk/tools/web-server.c
==============================================================================
--- trunk/tools/web-server.c	(original)
+++ trunk/tools/web-server.c	Tue Jan  6 19:29:20 2009
@@ -177,7 +177,7 @@
 static gboolean get_auth (WebServer *server, SoupMessage *msg, GHashTable *query);
 static gboolean get_post_for_irb (WebServer *webserver, SoupMessage *msg, 
 				  const ConnectionSetting *cs, GHashTable *query, GError **error);
-static void     get_for_cnclist (WebServer *webserver, SoupMessage *msg);
+static void     get_for_cnclist (WebServer *webserver, SoupMessage *msg, gboolean is_authenticated);
 
 
 /*#define DEBUG_SERVER*/
@@ -248,7 +248,7 @@
 			g_free (cookie);
 		}
 
-		if (auth_needed) {
+		if (auth_needed && !g_str_has_suffix (path, "~cnclist")) {
 			if (!get_auth (webserver, msg, query))
 				return;
 		}
@@ -290,7 +290,7 @@
 			done = TRUE;
 		}
 		else if (!strcmp (path, "~cnclist")) {
-			get_for_cnclist (webserver, msg);
+			get_for_cnclist (webserver, msg, !auth_needed);
 			done = TRUE;
 		}
 		else {
@@ -685,33 +685,29 @@
 }
 
 static xmlNodePtr
-cnc_ul ()
+cnc_ul (gboolean is_authenticated)
 {
 	xmlNodePtr ul, li, a;
 	const GSList *clist, *list;
 	gchar *str;
 
 	/* other connections in the sidebar */
-	list = gda_sql_get_all_connections ();
+	if (is_authenticated)
+		list = gda_sql_get_all_connections ();
+	else
+		list = NULL;
 	ul = xmlNewNode (NULL, BAD_CAST "ul");
 	xmlNodeSetContent(ul, BAD_CAST _("Connections"));
 	xmlSetProp (ul, BAD_CAST "id", BAD_CAST "cnclist");
 
 	if (!list) {
-		/* no connection at all */
+		/* no connection at all or not authenticated */
 		str = g_strdup_printf ("(%s)",  _("None"));
 		li = xmlNewChild (ul, NULL, BAD_CAST "li", NULL);
 		xmlNewChild (li, NULL, BAD_CAST "a", BAD_CAST str);
 		g_free (str);
 	}
 	else {
-		/*
-		li = xmlNewChild (ul, NULL, BAD_CAST "li", NULL);
-		str = g_strdup_printf ("(%s)",  _("From console"));
-		a = xmlNewChild (li, NULL, BAD_CAST "a", BAD_CAST str);
-		g_free (str);
-		xmlSetProp (a, BAD_CAST "href", BAD_CAST "/");
-		*/
 		for (clist = list; clist; clist = clist->next) {
 			gchar *tmp;
 			ConnectionSetting *cs2 = (ConnectionSetting*) clist->data;
@@ -729,12 +725,12 @@
 }
 
 static void
-get_for_cnclist (WebServer *webserver, SoupMessage *msg)
+get_for_cnclist (WebServer *webserver, SoupMessage *msg, gboolean is_authenticated)
 {
 	xmlNodePtr ul;
 	SoupBuffer *buffer;
 
-	ul = cnc_ul ();
+	ul = cnc_ul (is_authenticated);
 	soup_message_headers_replace (msg->response_headers,
 				      "Content-Type", "text/html");
 
@@ -1864,7 +1860,7 @@
 		hdoc = html_doc_new (_("Database information"));
 
 	/* other connections in the sidebar */
-	ul = cnc_ul ();
+	ul = cnc_ul (TRUE);
 	xmlAddChild (hdoc->sidebar, ul);
 
 	/* list all database object's types for which information can be obtained */
@@ -1907,7 +1903,7 @@
 	g_get_current_time (&tv);
 	for (list = server->priv->terminals_list; list; ) {
 		SqlConsole *con = (SqlConsole *) list->data;
-		if (con->last_time_used.tv_sec + 600 > tv.tv_sec) {
+		if (con->last_time_used.tv_sec + 600 < tv.tv_sec) {
 			GSList *n = list->next;
 			server->priv->terminals_list = g_slist_delete_link (server->priv->terminals_list, list);
 			list = n;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]