Unnamed Fossil Project

Check-in [eb40275c3f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:xddb inser/update fixes
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:eb40275c3f2dfbf8d3fe948f4e06caca677f396f
User & Date: monster 2012-08-11 02:42:55
Context
2012-08-12
10:26
some bugs fixed check-in: b360d43149 user: monster tags: trunk
2012-08-11
02:42
xddb inser/update fixes check-in: eb40275c3f user: monster tags: trunk
2012-08-10
08:43
fixes check-in: 282111e83e user: monster tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to random.hc.

100
101
102
103
104
105
106










107
108
109
110
111
112
113
                rnd_bcont = sizeof(rnd_bits);
              }
            *bits++ = rnd_bits[--rnd_bcont];
            --count;
          }
      }
  }










#endif
  ;
  
void System_Random(void *bits,int count /* of bytes*/ )
#ifdef _YO_RANDOM_BUILTIN
  {
  #ifdef _SOFTRND







>
>
>
>
>
>
>
>
>
>







100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
                rnd_bcont = sizeof(rnd_bits);
              }
            *bits++ = rnd_bits[--rnd_bcont];
            --count;
          }
      }
  }
#endif
  ;

byte_t *Soft_Random_Bytes(int count)
#ifdef _YO_RANDOM_BUILTIN
  {
    byte_t *b = __Malloc(count);
    Soft_Random(b,count);
    return b;
  }
#endif
  ;
  
void System_Random(void *bits,int count /* of bytes*/ )
#ifdef _YO_RANDOM_BUILTIN
  {
  #ifdef _SOFTRND

Changes to string.hc.

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
494
...
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645

char *Str_Hex_Byte(byte_t val,char pfx,void *out)
#ifdef _YO_STRING_BUILTIN
  {
    static char symbols[] = 
      { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
    char *q = out;
    switch ( pfx )
      {
        case 'x': *q++='0'; *q++='x'; break;
        case '\\': *q++='\\'; *q++='x'; break;
        case '%': *q++='%'; break; 
        default: break;
      }
    *q++ = symbols[(val>>4)];
    *q++ = symbols[val&0x0f];

    *q = 0;
    return out;
  }
#endif
  ;

#define Str_Hex_Encode(S,L) Str_Hex_Encode_(S,L,0)
char *Str_Hex_Encode_(void *data, int len, char *out)
................................................................................
  ;

void Quad_To_Hex16(uquad_t val,char *out)
#ifdef _YO_STRING_BUILTIN
  {
    int i;
    for ( i = 0; i < 8; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0,out+i*2);
  }
#endif
  ;

void Unsigned_To_Hex8(uint_t val,char *out)
#ifdef _YO_STRING_BUILTIN
  {
    int i;
    for ( i = 0; i < 4; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0,out+i*2);
  }
#endif
  ;

void Unsigned_To_Hex4(uint_t val,char *out)
#ifdef _YO_STRING_BUILTIN
  {
    int i;
    for ( i = 0; i < 2; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0,out+i*2);
  }
#endif
  ;

#define Unsigned_To_Hex2(Val,Out) Str_Hex_Byte((byte_t)(Val),0,Out)

uquad_t Hex16_To_Quad(char *S)
#ifdef _YO_STRING_BUILTIN
  {
    uint_t ret = 0;
    int i;
    for ( i = 0; i < 8; ++i )







|








>
|







 







|









|









|




|







471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
...
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646

char *Str_Hex_Byte(byte_t val,char pfx,void *out)
#ifdef _YO_STRING_BUILTIN
  {
    static char symbols[] = 
      { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
    char *q = out;
    switch ( pfx&0x7f )
      {
        case 'x': *q++='0'; *q++='x'; break;
        case '\\': *q++='\\'; *q++='x'; break;
        case '%': *q++='%'; break; 
        default: break;
      }
    *q++ = symbols[(val>>4)];
    *q++ = symbols[val&0x0f];
    if ( !pfx&0x80 )
      *q = 0;
    return out;
  }
#endif
  ;

#define Str_Hex_Encode(S,L) Str_Hex_Encode_(S,L,0)
char *Str_Hex_Encode_(void *data, int len, char *out)
................................................................................
  ;

void Quad_To_Hex16(uquad_t val,char *out)
#ifdef _YO_STRING_BUILTIN
  {
    int i;
    for ( i = 0; i < 8; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0x80,out+i*2);
  }
#endif
  ;

void Unsigned_To_Hex8(uint_t val,char *out)
#ifdef _YO_STRING_BUILTIN
  {
    int i;
    for ( i = 0; i < 4; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0x80,out+i*2);
  }
#endif
  ;

void Unsigned_To_Hex4(uint_t val,char *out)
#ifdef _YO_STRING_BUILTIN
  {
    int i;
    for ( i = 0; i < 2; ++i )
      Str_Hex_Byte((byte_t)(val>>(i*8)),0x80,out+i*2);
  }
#endif
  ;

#define Unsigned_To_Hex2(Val,Out) Str_Hex_Byte((byte_t)(Val),0x80,Out)

uquad_t Hex16_To_Quad(char *S)
#ifdef _YO_STRING_BUILTIN
  {
    uint_t ret = 0;
    int i;
    for ( i = 0; i < 8; ++i )

Changes to xddb.hc.

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
...
133
134
135
136
137
138
139


140
141
142
143
144
145








146
147
148
149
150
151
152
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
192
193
194
195
196
197
198



199
200
201
202
203
204
205
206
207
208
209
...
211
212
213
214
215
216
217
218
219


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249





250
251
252
253
254
255
256
...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346


347
348

349
350
351
352
353
354
355
    int esc_put: 1;
    int esc_get: 1;
    int encrypt: 1;
    void *encipher16;
    void *decipher16;
  } YO_XDDB;

#define YO_XDDB_KEY_PROPERTY "$$key"
#define YO_XDDB_REV_PROPERTY "$$rev"

enum
  {
    XDDB_FORMAT_TEXT          = 'A',
    XDDB_FORMAT_BINARY        = 'B',
    XDDB_FORMAT_ZIPPED_TEXT   = 'a',
    XDDB_FORMAT_ZIPPED_BINARY= 'b',
................................................................................
  }
#endif
  ;

YO_BUFFER *Xddb_Encode(YO_XDDB *xddb, YO_XDATA *doc, int revision)
#ifdef _YO_XDDB_BUILTIN 
  {


    char prefix[] = ".,.,.,.,_******\n";
    YO_BUFFER *bf = Buffer_Init(0);
    if ( !revision ) revision = Xddb_Get_Revision(doc);
    Unsigned_To_Hex8(revision,prefix);
    prefix[8] = (char)xddb->doc_format;
    Buffer_Append(bf,prefix,16);








    
    if ( xddb->doc_format == XDDB_FORMAT_TEXT )
      {
        Def_Format_Into(bf,&doc->root,0);
      }
    else if ( xddb->doc_format == XDDB_FORMAT_ZIPPED_TEXT )
      {
................................................................................
    else if ( xddb->doc_format == XDDB_FORMAT_BINARY )
      ;//Xdata_Binary_Encode_Into(bf,doc,0);
    else if ( xddb->doc_format == XDDB_FORMAT_ZIPPED_BINARY )
      ;//Xdata_Binary_Encode_Into(bf,doc,1);
    else
      __Raise(YO_ERROR_INCONSISTENT,__yoTa("unsupported document format",0));

    Unsigned_To_Hex2(Crc_8(0,bf->at+16,bf->count-16),bf->at+13);

    if ( xddb->esc_put || xddb->encrypt )
      {
        if ( xddb->encrypt )
          {
          }
        if ( xddb->esc_put ) __Auto_Release
................................................................................
  ;

YO_XDATA *Xddb_Decode(YO_XDDB *xddb, byte_t *at,int count)
#ifdef _YO_XDDB_BUILTIN 
  {
    YO_XDATA *doc = 0;
    YO_BUFFER *bf = 0;



    
    __Auto_Ptr(doc)
      {
        if ( count < 16 ) 
          __Raise(YO_ERROR_CORRUPTED,__yoTa("document is corrupted",0));
        
        if ( xddb->esc_get || xddb->encrypt )
          {
            if ( xddb->encrypt )
              {
              }
................................................................................
              {
                bf = Buffer_Reserve(0,count);
                //Buffer_Unesc_Append(bf,at,count);
                at = bf->bytes;
                count = bf->count;
              }
          }
        
        if ( Crc_8(0,at+16,count-16) != Hex2_To_Unsigned(at+13) )


          __Raise(YO_ERROR_CORRUPTED,__yoTa("document corrupted",0));

        switch ( at[8] )
          {
            case XDDB_FORMAT_TEXT:
              doc = Def_Parse_Str(at+16);
              Xddb_Set_Revision(doc,Hex8_To_Unsigned(at));
              break;
            case XDDB_FORMAT_ZIPPED_TEXT:
              {
                int zOk;
                long final_size = Hex4_To_Unsigned(at+9);
                bf = Buffer_Init(final_size);
                zOk = Zlib_Uncompress(bf->at,&final_size,at+16,count-16);
                if ( zOk != 0 )
                  __Raise_Format(YO_ERROR_DECOMPRESS_DATA,(__yoTa("failed to decompress document: %s",0),Zlib_Error(zOk)));
                /*doc = Def_Parse_Str(bf->at);
                bf = Buffer_Copy(at+16,count-16);
                Zlib_Buffer_Uncompress(bf,final_size);*/
                doc = Def_Parse_Str(bf->at);
                Xddb_Set_Revision(doc,Hex8_To_Unsigned(at));
                break;
              }
            case XDDB_FORMAT_BINARY:
            case XDDB_FORMAT_ZIPPED_BINARY:
              //doc = Xdata_Binary_Decode(at+16,count-16);
              break;
            default:
              __Raise(YO_ERROR_INCONSISTENT,__yoTa("unsupported document format",0));
          }





      }
      
    return doc;
  }
#endif
  ;

................................................................................

#define Xddb_Update(Xddb,Doc) Xddb_Store(Xddb,Doc,1)

int Xddb_Newdoc(YO_XDDB *xddb, YO_XDATA *doc, char *key)
#ifdef _YO_XDDB_BUILTIN 
  {
    Xnode_Value_Set_Str(&doc->root,YO_XDDB_KEY_PROPERTY,key);
    Xnode_Value_Set_Int(&doc->root,YO_XDDB_REV_PROPERTY,1);
    return Xddb_Store(xddb,doc,1);
  }
#endif
  ;

int Xddb_Overwrite(YO_XDDB *xddb, YO_XDATA *doc, char *key)
#ifdef _YO_XDDB_BUILTIN 
  {
    if ( key )
      Xnode_Value_Set_Str(&doc->root,YO_XDDB_KEY_PROPERTY,key);
    else if ( !Xnode_Value_Get_Str(&doc->root,YO_XDDB_KEY_PROPERTY,0) )
      {
        char *k = Xddb_Build_Unique_Key_Npl();
        Xnode_Value_Put_Str(&doc->root,YO_XDDB_KEY_PROPERTY,k);
      }
    return Xddb_Store(xddb,doc,0);
  }
#endif
  ;

char *Xddb_Unique(YO_XDDB *xddb, YO_XDATA *doc)
#ifdef _YO_XDDB_BUILTIN 
  {


    Xddb_Overwrite(xddb,doc,0);
    return Str_Copy(Xddb_Get_Key(doc));

  }
#endif
  ;
    
_YO_XDDB_EXTERN char Xddb_Source_String_OjMID[] _YO_XDDB_BUILTIN_CODE( = "xddb_source_string/@"); 
char *Xddb_Source_String(void *xddb) _YO_XDDB_BUILTIN_CODE(
  { return ((char*(*)(void*))Yo_Find_Method_Of(&xddb,Xddb_Source_String_OjMID,YO_RAISE_ERROR))







|
|







 







>
>
|




|
>
>
>
>
>
>
>
>







 







|







 







>
>
>



|







 







|
|
>
>





|
<






|






<









>
>
>
>
>







 







<
|









<
<
<
<
<








>
>
|
<
>







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
334
335
336
337
338
339
340

341
342
343
344
345
346
347
348
349
350





351
352
353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
    int esc_put: 1;
    int esc_get: 1;
    int encrypt: 1;
    void *encipher16;
    void *decipher16;
  } YO_XDDB;

#define YO_XDDB_KEY_PROPERTY "$$$key"
#define YO_XDDB_REV_PROPERTY "$$$rev"

enum
  {
    XDDB_FORMAT_TEXT          = 'A',
    XDDB_FORMAT_BINARY        = 'B',
    XDDB_FORMAT_ZIPPED_TEXT   = 'a',
    XDDB_FORMAT_ZIPPED_BINARY= 'b',
................................................................................
  }
#endif
  ;

YO_BUFFER *Xddb_Encode(YO_XDDB *xddb, YO_XDATA *doc, int revision)
#ifdef _YO_XDDB_BUILTIN 
  {
    int key_len, hdr_len;
    char *key;
    char prefix[] = ".,.,.,.,_.*+-.*+-.*+";
    YO_BUFFER *bf = Buffer_Init(0);
    if ( !revision ) revision = Xddb_Get_Revision(doc);
    Unsigned_To_Hex8(revision,prefix);
    prefix[8] = (char)xddb->doc_format;
    Buffer_Append(bf,prefix,20);
    
    key = Xddb_Get_Key(doc);
    key_len = strlen(key);
    Buffer_Printf(bf,"%02x",key_len);
    Buffer_Append(bf,key,key_len);
    
    hdr_len = bf->count;
    Unsigned_To_Hex2(hdr_len,bf->at+13);
    
    if ( xddb->doc_format == XDDB_FORMAT_TEXT )
      {
        Def_Format_Into(bf,&doc->root,0);
      }
    else if ( xddb->doc_format == XDDB_FORMAT_ZIPPED_TEXT )
      {
................................................................................
    else if ( xddb->doc_format == XDDB_FORMAT_BINARY )
      ;//Xdata_Binary_Encode_Into(bf,doc,0);
    else if ( xddb->doc_format == XDDB_FORMAT_ZIPPED_BINARY )
      ;//Xdata_Binary_Encode_Into(bf,doc,1);
    else
      __Raise(YO_ERROR_INCONSISTENT,__yoTa("unsupported document format",0));

    Unsigned_To_Hex4(Crc_16(0,bf->at+hdr_len,bf->count-hdr_len),bf->at+16);

    if ( xddb->esc_put || xddb->encrypt )
      {
        if ( xddb->encrypt )
          {
          }
        if ( xddb->esc_put ) __Auto_Release
................................................................................
  ;

YO_XDATA *Xddb_Decode(YO_XDDB *xddb, byte_t *at,int count)
#ifdef _YO_XDDB_BUILTIN 
  {
    YO_XDATA *doc = 0;
    YO_BUFFER *bf = 0;
    int hdr_len;
    int key_len;
    char *key;
    
    __Auto_Ptr(doc)
      {
        if ( count < 20 ) 
          __Raise(YO_ERROR_CORRUPTED,__yoTa("document is corrupted",0));
        
        if ( xddb->esc_get || xddb->encrypt )
          {
            if ( xddb->encrypt )
              {
              }
................................................................................
              {
                bf = Buffer_Reserve(0,count);
                //Buffer_Unesc_Append(bf,at,count);
                at = bf->bytes;
                count = bf->count;
              }
          }
          
        hdr_len = Hex2_To_Unsigned(at+13);
          
        if ( hdr_len < 21 || hdr_len > count || Crc_16(0,at+hdr_len,count-hdr_len) != Hex4_To_Unsigned(at+16) )
          __Raise(YO_ERROR_CORRUPTED,__yoTa("document corrupted",0));

        switch ( at[8] )
          {
            case XDDB_FORMAT_TEXT:
              doc = Def_Parse_Str(at+hdr_len);

              break;
            case XDDB_FORMAT_ZIPPED_TEXT:
              {
                int zOk;
                long final_size = Hex4_To_Unsigned(at+9);
                bf = Buffer_Init(final_size);
                zOk = Zlib_Uncompress(bf->at,&final_size,at+hdr_len,count-hdr_len);
                if ( zOk != 0 )
                  __Raise_Format(YO_ERROR_DECOMPRESS_DATA,(__yoTa("failed to decompress document: %s",0),Zlib_Error(zOk)));
                /*doc = Def_Parse_Str(bf->at);
                bf = Buffer_Copy(at+16,count-16);
                Zlib_Buffer_Uncompress(bf,final_size);*/
                doc = Def_Parse_Str(bf->at);

                break;
              }
            case XDDB_FORMAT_BINARY:
            case XDDB_FORMAT_ZIPPED_BINARY:
              //doc = Xdata_Binary_Decode(at+16,count-16);
              break;
            default:
              __Raise(YO_ERROR_INCONSISTENT,__yoTa("unsupported document format",0));
          }
        key_len = Hex2_To_Unsigned(at+20);
        if ( 22 + key_len != hdr_len ) 
          __Raise(YO_ERROR_CORRUPTED,__yoTa("document corrupted",0));
        Xvalue_Set_Str(Xnode_Value(&doc->root,YO_XDDB_KEY_PROPERTY,1),at+22,key_len);
        Xddb_Set_Revision(doc,Hex8_To_Unsigned(at));
      }
      
    return doc;
  }
#endif
  ;

................................................................................

#define Xddb_Update(Xddb,Doc) Xddb_Store(Xddb,Doc,1)

int Xddb_Newdoc(YO_XDDB *xddb, YO_XDATA *doc, char *key)
#ifdef _YO_XDDB_BUILTIN 
  {
    Xnode_Value_Set_Str(&doc->root,YO_XDDB_KEY_PROPERTY,key);

    return Xddb_Store(xddb,doc,-1);
  }
#endif
  ;

int Xddb_Overwrite(YO_XDDB *xddb, YO_XDATA *doc, char *key)
#ifdef _YO_XDDB_BUILTIN 
  {
    if ( key )
      Xnode_Value_Set_Str(&doc->root,YO_XDDB_KEY_PROPERTY,key);





    return Xddb_Store(xddb,doc,0);
  }
#endif
  ;

char *Xddb_Unique(YO_XDDB *xddb, YO_XDATA *doc)
#ifdef _YO_XDDB_BUILTIN 
  {
    char *k = Xddb_Build_Unique_Key();
    Xnode_Value_Set_Str(&doc->root,YO_XDDB_KEY_PROPERTY,k);
    Xddb_Store(xddb,doc,-1);

    return k;
  }
#endif
  ;
    
_YO_XDDB_EXTERN char Xddb_Source_String_OjMID[] _YO_XDDB_BUILTIN_CODE( = "xddb_source_string/@"); 
char *Xddb_Source_String(void *xddb) _YO_XDDB_BUILTIN_CODE(
  { return ((char*(*)(void*))Yo_Find_Method_Of(&xddb,Xddb_Source_String_OjMID,YO_RAISE_ERROR))

Changes to xddbmsql.hc.

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
        XddbMsql_Quote_Append(bf,data,len);
        Buffer_Append(bf,"')",2);
      repeat:
        if ( mysql_real_query(sqldb->con,bf->at,bf->count) )
          {
            int err = mysql_errno(sqldb->con);
            if ( err != ER_NO_SUCH_TABLE )
              __Raise_Format(YO_ERROR_IO,
                  (__yoTa("failed to insert new document: %s",0),mysql_error(sqldb->con)));      
            XddbMsql_Create_Doc_Table(sqldb,colid);
            goto repeat;
          }
        else
          success = mysql_affected_rows(sqldb->con);
      }
    return success;







|
|







227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
        XddbMsql_Quote_Append(bf,data,len);
        Buffer_Append(bf,"')",2);
      repeat:
        if ( mysql_real_query(sqldb->con,bf->at,bf->count) )
          {
            int err = mysql_errno(sqldb->con);
            if ( err != ER_NO_SUCH_TABLE )
              __Raise_Format( (err == ER_DUP_ENTRY ? YO_ERROR_ALREADY_EXISTS : YO_ERROR_IO),
                (__yoTa("failed to insert new document: %s",0),mysql_error(sqldb->con)));      
            XddbMsql_Create_Doc_Table(sqldb,colid);
            goto repeat;
          }
        else
          success = mysql_affected_rows(sqldb->con);
      }
    return success;

Changes to xddbsql_.hc.

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254





255
256

257
258
259
260
261
262
263




264
265
266
267
268
269
270
        if ( !key )
          __Raise_Format(YO_ERROR_ILLFORMED,
             (__yoTa("%s property doesn't exist or has invalid value",0),
                     YO_XDDB_KEY_PROPERTY));
        
        doc_id = Xddbsql_Doc_ID(xddb,key);
        col_id = Xddbsql_Col_ID(xddb,key);
        stats  = Xddbsql_Stats_Doc(xddb->sqldb,col_id,doc_id);
        
        if ( strict_revision )
          if ( stats.f.exists && stats.revision != Xddb_Get_Revision(doc) )
            inconsist:
              __Raise(YO_ERROR_INCONSISTENT,
                __Format(__yoTa("inconsistent revision of document '%s', store:%d != docu:%d",0),
                         key,
                         stats.revision,
                         Xddb_Get_Revision(doc)));              
        
        new_revision = stats.revision + 1;
        bf = Xddb_Encode(&xddb->xddb,doc,new_revision);
        
        if ( stats.f.exists )





          success = Xddbsql_Update_Doc(xddb->sqldb, col_id, doc_id, new_revision, bf->at, bf->count, stats.revision );         
        else

          success = Xddbsql_Insert_Doc(xddb->sqldb, col_id, doc_id, new_revision, bf->at, bf->count );         
      
        if ( !success ) // revision inconsistent
          {
            stats = Xddbsql_Stats_Doc(xddb->sqldb,col_id,doc_id);
            if ( stats.f.exists && stats.revision != Xddb_Get_Revision(doc) )
              goto inconsist;




            else
              __Raise(YO_ERROR_ALREADY_EXISTS,
                __Format(__yoTa("document '%s' already exists or couldn´t be updated, docu:%d",0),
                         key,
                         stats.revision));              
          }
          







<

<
<
<
<
<
<
<
|
<



|
>
>
>
>
>


>
|





|
>
>
>
>







233
234
235
236
237
238
239

240







241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
        if ( !key )
          __Raise_Format(YO_ERROR_ILLFORMED,
             (__yoTa("%s property doesn't exist or has invalid value",0),
                     YO_XDDB_KEY_PROPERTY));
        
        doc_id = Xddbsql_Doc_ID(xddb,key);
        col_id = Xddbsql_Col_ID(xddb,key);

        







        stats.revision = Xddb_Get_Revision(doc);

        new_revision = stats.revision + 1;
        bf = Xddb_Encode(&xddb->xddb,doc,new_revision);
        
        if ( !strict_revision )
          {
            if ( !Xddbsql_Update_Doc(xddb->sqldb, col_id, doc_id, new_revision, bf->at, bf->count, 0 ))             
              goto insert;
          }
        else if ( strict_revision > 0 )
          success = Xddbsql_Update_Doc(xddb->sqldb, col_id, doc_id, new_revision, bf->at, bf->count, stats.revision );         
        else
          insert:
            success = Xddbsql_Insert_Doc(xddb->sqldb, col_id, doc_id, new_revision, bf->at, bf->count );         
      
        if ( !success ) // revision inconsistent
          {
            stats = Xddbsql_Stats_Doc(xddb->sqldb,col_id,doc_id);
            if ( stats.f.exists && stats.revision != Xddb_Get_Revision(doc) )
              __Raise(YO_ERROR_INCONSISTENT,
                __Format(__yoTa("inconsistent revision of document '%s', store:%d != docu:%d",0),
                         key,
                         stats.revision,
                         Xddb_Get_Revision(doc)));              
            else
              __Raise(YO_ERROR_ALREADY_EXISTS,
                __Format(__yoTa("document '%s' already exists or couldn´t be updated, docu:%d",0),
                         key,
                         stats.revision));              
          }
          

Changes to xdef.hc.

565
566
567
568
569
570
571

572
573
574
575
576
577
578
  {
    __Gogo
      {
        YO_XVALUE *val = Xnode_First_Value(r);
        for ( ; val; val = Xnode_Next_Value(r,val) )
          {
            char *tag = Xnode_Value_Get_Tag(r,val);

            
            Buffer_Fill_Append(bf,' ',indent*YO_XDEF_INDENT_WIDTH);
            if ( (flags&XDEF_FORMAT_MASK) == XDEF_FORMAT_JSON )
              {
                Buffer_Fill_Append(bf,'"',1);
                Buffer_Append(bf,tag,-1);
                Buffer_Fill_Append(bf,'"',1);







>







565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
  {
    __Gogo
      {
        YO_XVALUE *val = Xnode_First_Value(r);
        for ( ; val; val = Xnode_Next_Value(r,val) )
          {
            char *tag = Xnode_Value_Get_Tag(r,val);
            if ( Str_Starts_With(tag,"$$$") ) continue;
            
            Buffer_Fill_Append(bf,' ',indent*YO_XDEF_INDENT_WIDTH);
            if ( (flags&XDEF_FORMAT_MASK) == XDEF_FORMAT_JSON )
              {
                Buffer_Fill_Append(bf,'"',1);
                Buffer_Append(bf,tag,-1);
                Buffer_Fill_Append(bf,'"',1);