Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_mapistoreURI returning MAPI_E_NOT_FOUND if mapping is alreay in database. #373

Closed
qantourisc opened this issue Jul 30, 2015 · 7 comments

Comments

@qantourisc
Copy link

In the file:
mapiproxy/libmapiproxy/backends/openchangedb_mysql.c:323 MAPISTATUS set_mapistoreURI
The query can return Query OK, 0 rows affected; Rows matched: 1 Changed: 0
Meaning the row is already on the requested value.
I had to change the check if (mysql_affected_rows(conn) == 0) { to if (mysql_num_rows(conn) == 0){

Please confirm this bug and I can make a pull request.

@qantourisc
Copy link
Author

And another possible victim: set_system_idx(

@sixstone-qq
Copy link
Contributor

You're right @qantourisc . I've just added a unit test for this case with the following result:

testsuite/libmapiproxy/openchangedb.c:177:F:Openchangedb MySQL backend:test_set_mapistoreURI:0: Assertion 'retval==MAPI_E_SUCCESS' failed: retval==-2147221233, MAPI_E_SUCCESS==0

We have to see which is the right solution.

@qantourisc
Copy link
Author

New by request by someone else: #379

@sixstone-qq
Copy link
Contributor

Do you agree with that solution?

@qantourisc
Copy link
Author

Yes and Hell No: See my patch: #378

Why yes: It looks like it will work.

Why no:
Why on earth would you do twice the work ? You read the wrong docs on mysql_***_rows, if I'm not mistaking. And you do not need to change the DB connection settings to use mysql_num_rows.

You have to look @ https://dev.mysql.com/doc/refman/5.5/en/mysql-num-rows.html not @ https://dev.mysql.com/doc/refman/5.5/en/mysql-affected-rows.html.
"mysql_num_rows() is intended for use with statements that return a result set, such as SELECT. For statements such as INSERT, UPDATE, or DELETE, the number of affected rows can be obtained with mysql_affected_rows(). " Translation (or atleast how I read it): num_rows() will select the number of rows matches by the WHERE. If you want to know howmany rows you updated: use affected_rows()

Side thought: We also ought to check for >1 cause that is also wrong, if one wishes to protect against DB-schema bugs, and code bugs. But not really required.

@sixstone-qq
Copy link
Contributor

I obtained the value for mysql_num_rows after executing the UPDATE query and here you are the results:

    sql = talloc_asprintf(mem_ctx,
        "UPDATE folders f "
        "JOIN mailboxes m ON m.id = f.mailbox_id AND m.name = '%s' "
        "SET f.MAPIStoreURI = '%s' "
        "WHERE f.folder_id = %"PRIu64,
        _sql(mem_ctx, username), mapistoreURL, fid);
    OPENCHANGE_RETVAL_IF(!sql, MAPI_E_NOT_ENOUGH_MEMORY, mem_ctx);
    retval = status(execute_query(conn, sql));
        printf("Count %d affected %d\n", mysql_num_rows(conn), mysql_affected_rows(conn));

The results after running testsuite.

Count 39703056 affected 1
Count 39703056 affected 0

So for me the mysql_num_rows is not set on UPDATE statements.

@qantourisc
Copy link
Author

Ok this is where mysql and mariadb differ it seems.So your solution is correct.

@blaxter blaxter closed this as completed Aug 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants