------------------------------------------------------------
revno: 237
committer: John Deal <bassd...@yahoo.com>
branch nick: dbBackEnd
timestamp: Sun 2011-12-11 14:55:19 -0500
message:
Fixed various joining workplaces and subscription issues. Reduced number of
mysql_execute() stack trash workarounds to one. Deleted various commented
debug code.
added:
mira-server/conf/mira.conf.mysql
modified:
mira-server/src/directory/db/DbDirectory.cpp
mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp
--
lp:~mira-dev/mira/dbBackEnd
https://code.launchpad.net/~mira-dev/mira/dbBackEnd
You are subscribed to branch lp:~mira-dev/mira/dbBackEnd.
To unsubscribe from this branch go to
https://code.launchpad.net/~mira-dev/mira/dbBackEnd/+edit-subscription
=== added file 'mira-server/conf/mira.conf.mysql'
--- mira-server/conf/mira.conf.mysql 1970-01-01 00:00:00 +0000
+++ mira-server/conf/mira.conf.mysql 2011-12-11 19:55:19 +0000
@@ -0,0 +1,9 @@
+# Don't edit this file while mira-server is
+# running unless you know what you're doing
+
+PORT = "7351"
+NETWORK_THREAD_COUNT = "5"
+NEW_ACCOUNT_CREATOR = "1"
+DIRECTORY_TYPE = "MYSQL"
+DIRECTORY_USER = "mira"
+DIRECTORY_PASSWORD = "MiraGroupWare"
=== modified file 'mira-server/src/directory/db/DbDirectory.cpp'
--- mira-server/src/directory/db/DbDirectory.cpp 2011-11-15 02:19:46 +0000
+++ mira-server/src/directory/db/DbDirectory.cpp 2011-12-11 19:55:19 +0000
@@ -577,9 +577,8 @@
std::list<subscription_record> target = target_list;
std::list<subscription_record> current = current_list;
-
- std::list<subscription_record>::iterator target_itr = target.begin();
- std::list<subscription_record>::iterator current_itr = current.begin();
+ std::list<subscription_record>::iterator target_itr;
+ std::list<subscription_record>::iterator current_itr;
add_list.resize(0);
@@ -589,6 +588,10 @@
target.sort(diff_subscription_list_compare);
current.sort(diff_subscription_list_compare);
+ // Initialize iterators to sorted lists.
+ target_itr = target.begin();
+ current_itr = current.begin();
+
// Largest list will determine number of times to loop.
if (target_size > current_size)
{
@@ -609,7 +612,8 @@
continue;
}
- if ((current_size == 0) || (current_size <= count))
+ if ((current_size == 0) || ((current_size <= count)
+ && (target_itr->user_id != current_itr->user_id)))
{ // Anything still in target_list should be added.
add_list.push_back(*target_itr);
target_itr++;
=== modified file 'mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp'
--- mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp 2011-10-02 15:57:54 +0000
+++ mira-server/src/directory/db/mysql/DbMySqlDirectory.cpp 2011-12-11 19:55:19 +0000
@@ -150,38 +150,12 @@
{
DbDirectory::subscription_record work_subscription;
DbDirectory::SubscriptionList work_subscription_list;
- // int mysql_result;
- // unsigned long data_lengths[4] = {sizeof(workplace_id)};
- // my_bool is_nulls[4];
- // MYSQL_BIND bind[4];
- MYSQL_RES* mysql_result_set;
- MYSQL_ROW mysql_result_row;
- char mysql_statement[sizeof(m_get_subscription_user_list_sql) + 10];
-
- sprintf(mysql_statement,
- "select subscriptionID, userID, workplaceID, rolesID from subscriptions where workplaceID = %u",
- workplace_id);
-
- if (mysql_real_query(m_db, mysql_statement, strlen(mysql_statement)) !=
- m_mysql_ok)
- { // Query failed.
- cout << "Error (DbMySqlDirectory::get_workplace_subscription_list): Query: '"
- << mysql_statement << "' failed. Error Code: " << mysql_errno(m_db)
- << " Message: " << mysql_error(m_db) << endl;
- return work_subscription_list;
- }
-
- mysql_result_set = mysql_store_result(m_db);
-
- if (mysql_result_set == NULL)
- { // Retrieving result set failed.
- cout << "Error (DbMySqlDirectory::get_workplace_subscription_list): Result set retrieval failed. "
- << " Error Code: " << mysql_errno(m_db) << " Message: "
- << mysql_error(m_db) << endl;
- return work_subscription_list;
- }
-
- /***********************************************
+ int mysql_result;
+ unsigned long data_lengths[4] = {sizeof(workplace_id)};
+ my_bool is_nulls[4];
+ MYSQL_BIND bind[4];
+
+
memset(bind, 0, sizeof(bind)); // Initialize MYSQL_BIND structure.
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].buffer = (char*) &workplace_id;
@@ -248,34 +222,12 @@
<< mysql_stmt_error(m_prep_get_subscription_user_list) << endl;
return work_subscription_list;
}
- ***********************************************/
do
{ // Retrieve list of user IDs for specified workplace.
- // mysql_result = mysql_stmt_fetch(m_prep_get_subscription_user_list);
- mysql_result_row = mysql_fetch_row(mysql_result_set);
-
- // if (mysql_result == m_mysql_ok)
- if (mysql_result_row != NULL)
- { // Retrieved record. Load into subscription list.
- work_subscription.subscription_id = std::atol(mysql_result_row[0]);
- work_subscription.user_id = std::atol(mysql_result_row[1]);
- work_subscription.workplace_id = std::atol(mysql_result_row[2]);
- work_subscription.roles_id = 0; // Roles not currently used.
- work_subscription_list.push_back(work_subscription); // Add to list.
- }
- else
- { // No more rows or retrieving row failed.
- if (mysql_result_row != m_mysql_ok)
- {
- cout << "Error (DbMySqlDirectory::get_user_subscription_workplace_list): Result set row retrieval failed Error: "
- << mysql_errno(m_db) << " Message: " << mysql_error(m_db)
- << endl;
- return work_subscription_list;
- }
- }
-
- /**********************************
+ mysql_result = mysql_stmt_fetch(m_prep_get_subscription_user_list);
+
+ if (mysql_result == m_mysql_ok)
{ // Retrieved record. Load into subscription list.
work_subscription_list.push_back(work_subscription); // Add to list.
}
@@ -300,14 +252,11 @@
} // End of if (mysql_return == MYSQL_DATA_TRUNCATED).
} // End of if (mysql_return != MYSQL_NO_DATA).
} // End of if (mysql_return == m_mysql_ok)
- **********************************/
}
- // while (mysql_result != MYSQL_NO_DATA);
- while (mysql_result_row != NULL);
+ while (mysql_result != MYSQL_NO_DATA);
- // free_results(m_prep_get_subscription_user_list,
- // "DbMySqlDirectory::add_get_workplace_subscription_list");
- mysql_free_result(mysql_result_set);
+ free_results(m_prep_get_subscription_user_list,
+ "DbMySqlDirectory::add_get_workplace_subscription_list");
return work_subscription_list;
}
@@ -316,46 +265,23 @@
{
subscription_record work_subscription;
SubscriptionList work_subscription_list;
- // int mysql_result;
- char sql_statement[sizeof(m_get_subscription_workplace_list_sql) + 10];
- // unsigned long lengths[4];
- // my_bool is_nulls[4];
- // my_bool truncation_flags[4];
- // MYSQL_BIND bind[4];
- MYSQL_RES* mysql_result_set;
- MYSQL_ROW mysql_result_row;
-
-
- std::sprintf(sql_statement,
- "select subscriptionID, userID, workplaceID, rolesID from subscriptions where userID = %u",
- user_id);
-
- if (mysql_real_query(m_db, sql_statement, std::strlen(sql_statement)) !=
- m_mysql_ok)
- { // Query failed.
- cout << "Error (DbMySqlDirectory::get_user_subscription_workplace_list): Query failed Error: "
- << mysql_errno(m_db) << " Message: " << mysql_error(m_db) << endl;
- return work_subscription_list;
- }
-
- mysql_result_set = mysql_store_result(m_db);
-
- if (mysql_result_set == NULL)
- { // Retrieving results failed.
- cout << "Error (DbMySqlDirectory::get_user_subscription_workplace_list): Result set retrieval failed Error: "
- << mysql_errno(m_db) << " Message: " << mysql_error(m_db) << endl;
- return work_subscription_list;
- }
-
- /***************************************************************
+ int mysql_result;
+ unsigned long lengths[4];
+ my_bool is_nulls[4];
+ my_bool truncation_flags[4];
+ MYSQL_BIND bind[4];
+
+
// HACK! reprepare statement each time. Removing this causes
// the mysql_stmt_execute() to trash stack. (JRD)
+ /***************************************************************
if (prepareStatement("DbMySqlDirectory::DbMySqlDirectory",
&m_prep_get_subscription_workplace_list,
m_get_subscription_workplace_list_sql) == false)
{
exit(-1);
}
+ ***************************************************************/
memset(bind, 0, sizeof(bind)); // Initialize MYSQL_BIND structure.
bind[0].buffer_type = MYSQL_TYPE_LONG;
@@ -430,33 +356,16 @@
<< mysql_stmt_error(m_prep_get_subscription_workplace_list) << endl;
return work_subscription_list;
}
- ***************************************************************/
do
{ // Retrieve list of user IDs for specified workplace.
- // mysql_result = mysql_stmt_fetch(m_prep_get_subscription_workplace_list);
- mysql_result_row = mysql_fetch_row(mysql_result_set);
+ mysql_result = mysql_stmt_fetch(m_prep_get_subscription_workplace_list);
- // if (mysql_result == m_mysql_ok)
- if (mysql_result_row != NULL)
- { // Retrieved record. Load into subscription list.
- work_subscription.subscription_id = std::atol(mysql_result_row[0]);
- work_subscription.user_id = std::atol(mysql_result_row[1]);
- work_subscription.workplace_id = std::atol(mysql_result_row[2]);
- work_subscription.roles_id = 0; // Roles not currently used.
+ if (mysql_result == m_mysql_ok)
+ {
work_subscription_list.push_back(work_subscription); // Add to list.
}
else
- { // No more rows or retrieving row failed.
- if (mysql_result_row != m_mysql_ok)
- {
- cout << "Error (DbMySqlDirectory::get_user_subscription_workplace_list): Result set row retrieval failed Error: "
- << mysql_errno(m_db) << " Message: " << mysql_error(m_db)
- << endl;
- return work_subscription_list;
- }
- }
- /***********************************************
{ // Either finished or error.
if (mysql_result != MYSQL_NO_DATA)
{
@@ -476,15 +385,11 @@
} // End of if (mysql_result == MYSQL_DATA_TRUNCATED).
} // End of if (mysql_result != MYSQL_NO_DATA).
} // End of if (mysql_result == m_mysql_ok)
- ***********************************************/
}
- // while (mysql_result != MYSQL_NO_DATA);
- while (mysql_result_row != NULL);
-
- // free_results(m_prep_get_subscription_workplace_list,
- // "DbMySqlDirectory::add_get_user_subscription_workplace_list");
- mysql_free_result(mysql_result_set);
-
+ while (mysql_result != MYSQL_NO_DATA);
+
+ free_results(m_prep_get_subscription_workplace_list,
+ "DbMySqlDirectory::add_get_user_subscription_workplace_list");
return work_subscription_list;
}
@@ -2222,14 +2127,28 @@
User work_user;
+ /****
+ For some reason, reusing prepared statement in this method trashes
+ the stack even though resources are released. Repreparing the
+ statement each time fixes issue (but significanlly slows this
+ method). Could be replaced with query() or real_query() but
+ kept code here to work on it later. JRD 12.11.2011
+ ****/
+ if (prepareStatement("DbMySqlDirectory::DbMySqlDirectory",
+ &m_prep_get_workplace_workplacename, m_get_workplace_workplacename_sql)
+ == false)
+ {
+ exit(-1);
+ }
+
// Bind key to prep statement.
strcpy(workplace_name, p_workplace_name.c_str());
- memset(bind, 0, sizeof(bind));
+ memset(&bind[0], 0, sizeof(bind[0]));
bind[0].buffer_type = MYSQL_TYPE_STRING;
bind[0].buffer = (char*) workplace_name;
lengths[0] = strlen(workplace_name);
bind[0].length = &lengths[0];
- bind[0].buffer_length = sizeof(workplace_name);
+ bind[0].buffer_length = strlen(workplace_name);
bind[0].is_null = (my_bool*) 0;
bind[0].is_unsigned = true;
@@ -2256,11 +2175,12 @@
}
// Bind output.
+ memset(bind, 0, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].buffer = (char*) &workplace_id;
bind[0].buffer_length = sizeof(workplace_id);
bind[0].length = &lengths[0];
- bind[0].is_null = &is_nulls[0];
+ bind[0].is_null = (my_bool*) 0;
bind[0].is_unsigned = true;
bind[0].error = &truncation_flags[0];
@@ -2378,13 +2298,14 @@
} // End switch(mysql_result).
workplace.set_id(workplace_id);
- workplace.set_name(p_workplace_name.c_str());
+ workplace.set_name(p_workplace_name);
// Set description field.
work_field.type = Field::type_string;
work_field.attribute = ATTRIBUTE_DESCRIPTION;
work_string = workplace_desc;
work_field.value = work_string;
+ work_field.value = workplace_desc;
workplace.set_field(work_field);
// Set user_list field.
@@ -2398,6 +2319,7 @@
// Get list of userIDs associated with workplace.
work_subscription_list = get_workplace_subscription_list(workplace_id);
+ work_field.value_list.clear(); // Remove any leftower list items.
for (SubscriptionList::iterator itr = work_subscription_list.begin();
itr != work_subscription_list.end(); itr++)
------------------------------------------------------------------------------
Learn Windows Azure Live! Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for
developers. It will provide a great way to learn Windows Azure and what it
provides. You can attend the event by watching it streamed LIVE online.
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Mira-development mailing list
Mira-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mira-development