[Planner Dev] First patch for the database system



Hi guys!

After looking to the SQL code now everytime you save a project to the
database planner will create a new project for it, no matter if you have
loaded the project from a database.

Here goes a experimental patch ir order you can save a project in the
database without creating a new one: *WARNING* I am sure no tests has
been done in order to see if the save does a good job so the project
data could end with garbage. For example, I have seen that if you remove
tasks from a project, when you save it, tasks aren't remove from the
database.

Once we save a project to the database without creating a new one, the
game starts :) You can open the same project from different instances of
Planner and you can try to modify the project and save in one instance,
try then to do the same from another instance and a nice dialog will
warn you about database changed from other user. Nice!

I am playing in this things and have created a little doc with use cases
to work in the database. I have attached to this email also this use
cases.

Cheers

-- Alvaro
Index: src/planner-sql-plugin.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-sql-plugin.c,v
retrieving revision 1.12
diff -u -b -B -p -r1.12 planner-sql-plugin.c
--- src/planner-sql-plugin.c	25 Jun 2004 09:59:35 -0000	1.12
+++ src/planner-sql-plugin.c	27 Jun 2004 16:13:10 -0000
@@ -703,6 +703,7 @@ sql_plugin_save (BonoboUIComponent *comp
 	gchar         *login = NULL;
 	gchar         *password = NULL;
 	gchar         *uri = NULL;
+	const gchar   *uri_plan = NULL;
 	GError        *error = NULL;
 		
 	project = planner_window_get_project (plugin->main_window);
@@ -721,15 +722,37 @@ sql_plugin_save (BonoboUIComponent *comp
 	 * save over. Needs finishing though. Pass project id -1 for now (always
 	 * create a new project).
 	 */
-	uri = create_sql_uri (server, port, database, login, password, -1);
+	uri_plan = mrp_project_get_uri (project);
 
+	/* First time project */
+	if (uri_plan == NULL) {
+		uri = create_sql_uri (server, port, database, login, password, -1);	
 	if (!mrp_project_save_as (project, uri, FALSE, &error)) {
 		show_error_dialog (plugin, error->message);
 		g_clear_error (&error);
 		goto fail;
 	}
+		g_free (uri);
 	
+	} 
+	/* Project was in database */
+	else if (strncmp (uri_plan, "sql://", 6) == 0) {
+		if (!mrp_project_save (project, FALSE, &error)) { 
+			show_error_dialog (plugin, error->message);
+			g_clear_error (&error);
+			goto fail;
+		}
+	} 
+	/* Project wasn't in database */
+	else {
+		uri = create_sql_uri (server, port, database, login, password, -1);	
+		if (!mrp_project_save_as (project, uri, FALSE, &error)) { 
+			show_error_dialog (plugin, error->message);
+			g_clear_error (&error);
+			goto fail;
+		}
 	g_free (uri);
+	}
 		
 	object = G_OBJECT (plugin->main_window);
 	
USE CASES FOR PLANNER DATABASE SYSTEM
-------------------------------------

* Project loading/saving:

- Load a project from a file and save it to the database

When you save the project to the database, next savings will go to
the database.

- Load a project from database and save it to a file

When you save the project to the database, next savings will go to
the file.

- New project and save it to database

A new project will be created in the database

- Load a project from a database and save it to the database

The new project data will be saved to the database and all old data
will be destroyed.

* Concurrency

- Open a project A from 2 different instances of planner

When one of the instances tries to save the project, check if
no changes from the other instance has been done.


* Identification and control access

- Different users access a project

The identification for each user is being done using the 
postgres user used to access the database.

- Control access

A user can put a flag in order only with the user that created
the database a project could be open. Other things like access
groups could be implemented using also the postgrer user system.

Attachment: signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente



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