El 26 de marzo de 2012 11:48, Andoni Morales <ylat...@gmail.com> escribió:

> El 26 de marzo de 2012 11:28, Hans Leidekker <h...@codeweavers.com>escribió:
>
> On Mon, 2012-03-26 at 11:14 +0200, Andoni Morales wrote:
>> > -    case MSIMODIFY_REPLACE:
>> >      case MSIMODIFY_MERGE:
>> > +      /* check for a duplicated key */
>> > +      r = msi_table_find_row( tv, rec, &row, column );
>> > +      if (r == ERROR_SUCCESS) {
>> > +        /* check that both are identical */
>> > +        r = compare_record (tv, row, rec);
>> > +        if (r != ERROR_SUCCESS)
>> > +          break;
>> > +      } else {
>> > +        r = table_validate_new( tv, rec, NULL );
>> > +        if (r != ERROR_SUCCESS)
>> > +          break;
>> > +        r = TABLE_insert_row( view, rec, -1, FALSE );
>> > +          break;
>> > +      }
>> > +
>> > +    case MSIMODIFY_REPLACE:
>>
>> Please use bracketing and indentation style of the surrounding code.
>> Some tests would be nice.
>>
>
Updated patch with tests, which revealed bugs in the previous pathc :)

Cheers,
Andoni

>
>>
> Sorry, I attached the wrong patch file. I have fixed the indentation and
> will add tests too.
>
>
>
> --
> Andoni Morales Alastruey
>
> LongoMatch:The Digital Coach
> http://www.longomatch.ylatuya.es
>



-- 
Andoni Morales Alastruey

LongoMatch:The Digital Coach
http://www.longomatch.ylatuya.es
From c181ff748f0587e51b012330b5f47d550b6ceb0b Mon Sep 17 00:00:00 2001
From: Andoni Morales Alastruey <ylat...@gmail.com>
Date: Mon, 19 Mar 2012 23:19:17 +0100
Subject: [PATCH] msi: implement MSIMODIFY_MERGE function in TABLE_modify

---
 dlls/msi/table.c    |   15 +++++++++++++--
 dlls/msi/tests/db.c |   24 ++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/dlls/msi/table.c b/dlls/msi/table.c
index d37947e..852124e 100644
--- a/dlls/msi/table.c
+++ b/dlls/msi/table.c
@@ -1766,7 +1766,7 @@ static UINT TABLE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
                           MSIRECORD *rec, UINT row)
 {
     MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
-    UINT r, column;
+    UINT r, frow, column;
 
     TRACE("%p %d %p\n", view, eModifyMode, rec );
 
@@ -1811,8 +1811,19 @@ static UINT TABLE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
         r = msi_table_assign( view, rec );
         break;
 
-    case MSIMODIFY_REPLACE:
     case MSIMODIFY_MERGE:
+        /* check row that matches this record */
+        r = msi_table_find_row( tv, rec, &frow, &column );
+        if (r != ERROR_SUCCESS)
+        {
+            /* if the record was not found, validate it and insert it */
+            r = table_validate_new( tv, rec, NULL );
+            if (r == ERROR_SUCCESS)
+                r = TABLE_insert_row( view, rec, -1, FALSE );
+        }
+        break;
+
+    case MSIMODIFY_REPLACE:
     case MSIMODIFY_VALIDATE:
     case MSIMODIFY_VALIDATE_FIELD:
     case MSIMODIFY_VALIDATE_DELETE:
diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c
index d33eb0c..f5a3c1e 100644
--- a/dlls/msi/tests/db.c
+++ b/dlls/msi/tests/db.c
@@ -923,6 +923,30 @@ static void test_viewmodify(void)
     r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
     ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
 
+    /* try to merge the same record */
+    r = MsiViewExecute(hview, 0);
+    ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
+    r = MsiViewModify(hview, MSIMODIFY_MERGE, hrec );
+    ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
+
+    r = MsiCloseHandle(hrec);
+    ok(r == ERROR_SUCCESS, "failed to close record\n");
+
+    /* try merging a new record */
+    hrec = MsiCreateRecord(3);
+
+    r = MsiRecordSetInteger(hrec, 1, 2);
+    ok(r == ERROR_SUCCESS, "failed to set integer\n");
+    r = MsiRecordSetString(hrec, 2, "pepe");
+    ok(r == ERROR_SUCCESS, "failed to set string\n");
+    r = MsiRecordSetString(hrec, 3, "7654321");
+    ok(r == ERROR_SUCCESS, "failed to set string\n");
+
+    r = MsiViewModify(hview, MSIMODIFY_MERGE, hrec );
+    ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
+    r = MsiViewExecute(hview, 0);
+    ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
+
     r = MsiCloseHandle(hrec);
     ok(r == ERROR_SUCCESS, "failed to close record\n");
 
-- 
1.7.5.4



Reply via email to