Hib Eris : msi: Fix merging tables with string primary keys.

Alexandre Julliard julliard at winehq.org
Wed May 27 09:26:54 CDT 2009


Module: wine
Branch: master
Commit: 987d17dc6f4c04982de04ffa50b7dd2fa4fe7a86
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=987d17dc6f4c04982de04ffa50b7dd2fa4fe7a86

Author: Hib Eris <hib at hiberis.nl>
Date:   Tue May 26 22:32:12 2009 +0200

msi: Fix merging tables with string primary keys.

---

 dlls/msi/database.c |   42 +++++++++++++++++++++++++++++++++++++++---
 dlls/msi/tests/db.c |   10 +++++-----
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/dlls/msi/database.c b/dlls/msi/database.c
index c0df1e5..446a318 100644
--- a/dlls/msi/database.c
+++ b/dlls/msi/database.c
@@ -1174,8 +1174,8 @@ done:
 static LPWSTR get_key_value(MSIQUERY *view, LPCWSTR key, MSIRECORD *rec)
 {
     MSIRECORD *colnames;
-    LPWSTR str;
-    UINT r, i = 0;
+    LPWSTR str, val;
+    UINT r, i = 0, sz = 0;
     int cmp;
 
     r = MSI_ViewGetColumnInfo(view, MSICOLINFO_NAMES, &colnames);
@@ -1190,7 +1190,43 @@ static LPWSTR get_key_value(MSIQUERY *view, LPCWSTR key, MSIRECORD *rec)
     } while (cmp);
 
     msiobj_release(&colnames->hdr);
-    return msi_dup_record_field(rec, i);
+
+    r = MSI_RecordGetStringW(rec, i, NULL, &sz);
+    if (r != ERROR_SUCCESS)
+        return NULL;
+    sz++;
+
+    if (MSI_RecordGetString(rec, i))  /* check record field is a string */
+    {
+        /* quote string record fields */
+        const WCHAR szQuote[] = {'\'', 0};
+        sz += 2;
+        val = msi_alloc(sz*sizeof(WCHAR));
+        if (!val)
+            return NULL;
+
+        lstrcpyW(val, szQuote);
+        r = MSI_RecordGetStringW(rec, i, val+1, &sz);
+        lstrcpyW(val+1+sz, szQuote);
+    }
+    else
+    {
+        /* do not quote integer record fields */
+        val = msi_alloc(sz*sizeof(WCHAR));
+        if (!val)
+            return NULL;
+
+        r = MSI_RecordGetStringW(rec, i, val, &sz);
+    }
+
+    if (r != ERROR_SUCCESS)
+    {
+        ERR("failed to get string!\n");
+        msi_free(val);
+        return NULL;
+    }
+
+    return val;
 }
 
 static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view,
diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c
index 7b650e0..c3bdd11 100644
--- a/dlls/msi/tests/db.c
+++ b/dlls/msi/tests/db.c
@@ -6968,19 +6968,19 @@ static void test_dbmerge(void)
 
     /* primary key is string */
     r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
-    todo_wine ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
     query = "SELECT * FROM `One`";
     r = do_query(hdb, query, &hrec);
-    todo_wine ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
     size = MAX_PATH;
     r = MsiRecordGetStringA(hrec, 1, buf, &size);
-    todo_wine ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
-    todo_wine ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+    ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
 
     r = MsiRecordGetInteger(hrec, 2);
-    todo_wine ok(r == 1, "Expected 1, got %d\n", r);
+    ok(r == 1, "Expected 1, got %d\n", r);
 
     MsiCloseHandle(hrec);
 




More information about the wine-cvs mailing list