00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <lTrace.h>
00017 #include <lDefs.h>
00018
00019
00020 #include <cOneToOneRelationBase.h>
00021
00022
00023 #include <cChainedRelationBase.h>
00024 #include <cClassRegister.h>
00025 #include <cRefBase.h>
00026 #include <cConnection.h>
00027 #include <cComplexQuery.h>
00028
00029 OneToOneRelationBase::OneToOneRelationBase(
00030 const char *a_left_class_name,
00031 const char *a_right_class_name,
00032 const char *a_table_name,
00033 class Connection *a_database_connection,
00034 const char *a_left_column_name,
00035 const char *a_right_column_name
00036 ) :
00037 Relation(
00038 a_left_class_name,
00039 a_right_class_name,
00040 a_table_name,
00041 a_database_connection
00042 )
00043 {
00044 ProtoBase *_left_prototype=Class[a_left_class_name];
00045 ProtoBase *_right_prototype=Class[a_right_class_name];
00046 char *_column = NULL;
00047 char *_str = NULL;
00048 const char *_separator;
00049
00050 if (!a_left_column_name || !*a_left_column_name)
00051 {
00052 _separator = NULL;
00053 StrCpy(_str,_left_prototype->KeySelect());
00054 while (StrSplit(_str,',',_column))
00055 {
00056 StrPrefixCut(_column,'.');
00057 StrCat(_leftColumnName,4,_separator,_tableName,"_L_",_column);
00058 _separator = ", ";
00059 };
00060 }
00061 else
00062 StrCpy(_leftColumnName=NULL,a_left_column_name);
00063
00064 if (!a_right_column_name || !*a_right_column_name)
00065 {
00066 _separator = NULL;
00067 StrCpy(_str,_right_prototype->KeySelect());
00068 while (StrSplit(_str,',',_column))
00069 {
00070 StrPrefixCut(_column,'.');
00071 StrCat(_rightColumnName,4,_separator,_tableName,"_R_",_column);
00072 _separator = ", ";
00073 };
00074 }
00075 else
00076 StrCpy(_rightColumnName=NULL,a_right_column_name);
00077
00078 StrFree(_str);
00079 };
00080
00081 bool OneToOneRelationBase::InsertCouple(RefBase &left, RefBase &right)
00082
00083 {
00084 if (left.IsTransient() || right.IsTransient())
00085 return false;
00086 ProtoBase *_left_prototype = Class[_leftClassName];
00087 ProtoBase *_right_prototype = Class[_rightClassName];
00088
00089
00090
00091
00092
00093 bool _retval = LDeleteAll(right) && RDeleteAll(left);
00094
00095
00096 char *_update = StrCpy(_update = NULL, _left_prototype->From());
00097 StrClause(_update,"UPDATE");
00098 char *_columns = StrCpy(_columns = NULL, _rightColumnName);
00099 char *_1column = NULL;
00100 char *_values = right._KeyValues();
00101 char *_1value = NULL;
00102 char *_set = NULL;
00103 char *_separator = NULL;
00104 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00105 StrCat(_set,4,_separator,_1column," = ",_1value);
00106 _separator = ", ";
00107 };
00108 StrClause(_set,"SET");
00109 StrCpy(_columns,_left_prototype->KeySelect());
00110 StrFree(_1column);
00111 StrFree(_values);
00112 _values = left._KeyValues();
00113 StrFree(_1value);
00114 char *_where = NULL;
00115 _separator = "(";
00116 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00117 StrPrefixCut(_1column,'.');
00118 StrCat(_where,4,_separator,_1column," = ",_1value);
00119 _separator = ") AND (";
00120 };
00121 StrCat(_where,")");
00122 StrClause(_where,"WHERE");
00123 StrFree(_columns);
00124 StrFree(_1column);
00125 StrFree(_values);
00126 StrFree(_1value);
00127 StrCat(_update,2,_set,_where);
00128 StrFree(_set);
00129 StrFree(_where);
00130 if (_databaseConnection == NULL)
00131 throw ObjLibException_ConnectionError();
00132 _retval = _retval && _databaseConnection -> _Sql(_update);
00133 StrFree(_update);
00134
00135 StrCpy(_update, _right_prototype -> From());
00136 StrClause(_update,"UPDATE");
00137 StrCpy(_columns, _leftColumnName);
00138 _1column = NULL;
00139 _values = left._KeyValues();
00140 _1value = NULL;
00141 _set = NULL;
00142 _separator = NULL;
00143 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00144 StrCat(_set,4,_separator,_1column," = ",_1value);
00145 _separator = ", ";
00146 };
00147 StrClause(_set,"SET");
00148 StrCpy(_columns,_right_prototype->KeySelect());
00149 StrFree(_1column);
00150 StrFree(_values);
00151 _values = right._KeyValues();
00152 StrFree(_1value);
00153 _where = NULL;
00154 _separator = "(";
00155 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00156 StrPrefixCut(_1column,'.');
00157 StrCat(_where,4,_separator,_1column," = ",_1value);
00158 _separator = ") AND (";
00159 };
00160 StrCat(_where,")");
00161 StrClause(_where,"WHERE");
00162 StrFree(_columns);
00163 StrFree(_1column);
00164 StrFree(_values);
00165 StrFree(_1value);
00166 StrCat(_update,2,_set,_where);
00167 StrFree(_set);
00168 StrFree(_where);
00169 _retval = _retval && _databaseConnection -> _Sql(_update);
00170 StrFree(_update);
00171 return _retval;
00172 };
00173
00174 bool OneToOneRelationBase::DeleteCouple(RefBase &left, RefBase &right)
00175 {
00176 if (left.IsTransient() || right.IsTransient())
00177 return false;
00178 ProtoBase *_left_prototype = Class[_leftClassName];
00179 ProtoBase *_right_prototype = Class[_rightClassName];
00180
00181
00182
00183
00184 bool _retval;
00185 char *_update = StrCpy(_update = NULL, _left_prototype -> From());
00186 StrClause(_update,"UPDATE");
00187 char *_columns = StrCpy(_columns = NULL, _rightColumnName);
00188 char *_1column = NULL;
00189 char *_set = NULL;
00190 char *_separator = NULL;
00191 while (StrSplit(_columns,',',_1column)) {
00192 StrCat(_set,3,_separator,_1column," = NULL");
00193 _separator = ", ";
00194 };
00195 StrClause(_set,"SET");
00196 StrFree(_1column);
00197 StrCpy(_columns,_left_prototype->KeySelect());
00198 StrCat(_columns,2,", ",_rightColumnName);
00199 char *_1value = NULL;
00200 char *_values = left._KeyValues();
00201 StrCat(_values,2,", ",_1value = right._KeyValues());
00202 StrFree(_1value);
00203 char *_where = NULL;
00204 _separator = "(";
00205 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00206 StrPrefixCut(_1column,'.');
00207 StrCat(_where,4,_separator,_1column," = ",_1value);
00208 _separator = ") AND (";
00209 };
00210 StrCat(_where,")");
00211 StrClause(_where,"WHERE");
00212 StrFree(_columns);
00213 StrFree(_1column);
00214 StrFree(_values);
00215 StrFree(_1value);
00216 StrCat(_update,2,_set,_where);
00217 StrFree(_set);
00218 StrFree(_where);
00219 if (_databaseConnection == NULL)
00220 throw ObjLibException_ConnectionError();
00221 _retval = _databaseConnection -> _Sql(_update);
00222 StrFree(_update);
00223
00224 StrCpy(_update, _right_prototype -> From());
00225 StrClause(_update,"UPDATE");
00226 StrCpy(_columns, _leftColumnName);
00227 _1column = NULL;
00228 _set = NULL;
00229 _separator = NULL;
00230 while (StrSplit(_columns,',',_1column)) {
00231 StrCat(_set,3,_separator,_1column," = NULL");
00232 _separator = ", ";
00233 };
00234 StrClause(_set,"SET");
00235 StrCpy(_columns,_right_prototype->KeySelect());
00236 StrCat(_columns,2,", ",_leftColumnName);
00237 StrFree(_1column);
00238 StrFree(_values);
00239 StrFree(_1value);
00240 _values = right._KeyValues();
00241 StrCat(_values,2,", ",_1value = left._KeyValues());
00242 StrFree(_1value);
00243 _where = NULL;
00244 _separator = "(";
00245 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00246 StrPrefixCut(_1column,'.');
00247 StrCat(_where,4,_separator,_1column," = ",_1value);
00248 _separator = ") AND (";
00249 };
00250 StrCat(_where,")");
00251 StrClause(_where,"WHERE");
00252 StrFree(_columns);
00253 StrFree(_1column);
00254 StrFree(_values);
00255 StrFree(_1value);
00256 StrCat(_update,2,_set,_where);
00257 StrFree(_set);
00258 StrFree(_where);
00259 _retval = _retval && _databaseConnection -> _Sql(_update);
00260 StrFree(_update);
00261 return _retval;
00262 };
00263
00264 bool OneToOneRelationBase::LDeleteAll(class RefBase &right)
00265
00266 {
00267 if (right.IsTransient())
00268 return false;
00269 ProtoBase *_left_prototype = Class[_leftClassName];
00270 ProtoBase *_right_prototype = Class[_rightClassName];
00271
00272
00273
00274
00275 bool _retval;
00276 char *_update = StrCpy(_update = NULL, _left_prototype -> From());
00277 StrClause(_update,"UPDATE");
00278 char *_columns = StrCpy(_columns = NULL, _rightColumnName);
00279 char *_1column = NULL;
00280 char *_set = NULL;
00281 char *_separator = NULL;
00282 while (StrSplit(_columns,',',_1column)) {
00283 StrCat(_set,3,_separator,_1column," = NULL");
00284 _separator = ", ";
00285 };
00286 StrClause(_set,"SET");
00287 StrCpy(_columns, _rightColumnName);
00288 StrFree(_1column);
00289 char *_values = right._KeyValues();
00290 char *_1value = NULL;
00291 char *_where = NULL;
00292 _separator = "(";
00293 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00294 StrPrefixCut(_1column,'.');
00295 StrCat(_where,4,_separator,_1column," = ",_1value);
00296 _separator = ") AND (";
00297 };
00298 StrCat(_where,")");
00299 StrClause(_where,"WHERE");
00300 StrFree(_columns);
00301 StrFree(_1column);
00302 StrFree(_values);
00303 StrFree(_1value);
00304 StrCat(_update,2,_set,_where);
00305 StrFree(_set);
00306 StrFree(_where);
00307 if (_databaseConnection == NULL)
00308 throw ObjLibException_ConnectionError();
00309 _retval = _databaseConnection -> _Sql(_update);
00310 StrFree(_update);
00311
00312 StrCpy(_update, _right_prototype -> From());
00313 StrClause(_update,"UPDATE");
00314 StrCpy(_columns, _leftColumnName);
00315 _1column = NULL;
00316 _set = NULL;
00317 _separator = NULL;
00318 while (StrSplit(_columns,',',_1column)) {
00319 StrCat(_set,3,_separator,_1column," = NULL");
00320 _separator = ", ";
00321 };
00322 StrClause(_set,"SET");
00323 StrCpy(_columns,_right_prototype->KeySelect());
00324 StrFree(_1column);
00325 StrFree(_values);
00326 _values = right._KeyValues();
00327 StrFree(_1value);
00328 _where = NULL;
00329 _separator = "(";
00330 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00331 StrPrefixCut(_1column,'.');
00332 StrCat(_where,4,_separator,_1column," = ",_1value);
00333 _separator = ") AND (";
00334 };
00335 StrCat(_where,")");
00336 StrClause(_where,"WHERE");
00337 StrFree(_columns);
00338 StrFree(_1column);
00339 StrFree(_values);
00340 StrFree(_1value);
00341 StrCat(_update,2,_set,_where);
00342 StrFree(_set);
00343 StrFree(_where);
00344 _retval = _retval && _databaseConnection -> _Sql(_update);
00345 StrFree(_update);
00346 return _retval;
00347 };
00348
00349 bool OneToOneRelationBase::RDeleteAll(class RefBase &left)
00350
00351 {
00352 if (left.IsTransient())
00353 return false;
00354 ProtoBase *_left_prototype = Class[_leftClassName];
00355 ProtoBase *_right_prototype = Class[_rightClassName];
00356
00357
00358
00359
00360 bool _retval;
00361 char *_update = StrCpy(_update = NULL, _left_prototype -> From());
00362 StrClause(_update,"UPDATE");
00363 char *_columns = StrCpy(_columns = NULL, _rightColumnName);
00364 char *_1column = NULL;
00365 char *_set = NULL;
00366 char *_separator = NULL;
00367 while (StrSplit(_columns,',',_1column)) {
00368 StrCat(_set,3,_separator,_1column," = NULL");
00369 _separator = ", ";
00370 };
00371 StrClause(_set,"SET");
00372 StrCpy(_columns,_left_prototype->KeySelect());
00373 StrFree(_1column);
00374 char *_values = left._KeyValues();
00375 char *_1value = NULL;
00376 char *_where = NULL;
00377 _separator = "(";
00378 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00379 StrPrefixCut(_1column,'.');
00380 StrCat(_where,4,_separator,_1column," = ",_1value);
00381 _separator = ") AND (";
00382 };
00383 StrCat(_where,")");
00384 StrClause(_where,"WHERE");
00385 StrFree(_columns);
00386 StrFree(_1column);
00387 StrFree(_values);
00388 StrFree(_1value);
00389 StrCat(_update,2,_set,_where);
00390 StrFree(_set);
00391 StrFree(_where);
00392 if (_databaseConnection == NULL)
00393 throw ObjLibException_ConnectionError();
00394 _retval = _databaseConnection -> _Sql(_update);
00395 StrFree(_update);
00396
00397 StrCpy(_update, _right_prototype -> From());
00398 StrClause(_update,"UPDATE");
00399 StrCpy(_columns, _leftColumnName);
00400 _1column = NULL;
00401 _set = NULL;
00402 _separator = NULL;
00403 while (StrSplit(_columns,',',_1column)) {
00404 StrCat(_set,3,_separator,_1column," = NULL");
00405 _separator = ", ";
00406 };
00407 StrClause(_set,"SET");
00408 StrCpy(_columns,_leftColumnName);
00409 StrFree(_1column);
00410 StrFree(_values);
00411 _values = left._KeyValues();
00412 StrFree(_1value);
00413 _where = NULL;
00414 _separator = "(";
00415 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value)) {
00416 StrPrefixCut(_1column,'.');
00417 StrCat(_where,4,_separator,_1column," = ",_1value);
00418 _separator = ") AND (";
00419 };
00420 StrCat(_where,")");
00421 StrClause(_where,"WHERE");
00422 StrFree(_columns);
00423 StrFree(_1column);
00424 StrFree(_values);
00425 StrFree(_1value);
00426 StrCat(_update,2,_set,_where);
00427 StrFree(_set);
00428 StrFree(_where);
00429 _retval = _retval && _databaseConnection -> _Sql(_update);
00430 StrFree(_update);
00431 return _retval;
00432 };
00433
00434 ResultBase *OneToOneRelationBase::_LGetAll(
00435 ResultBase *rb,
00436 const class RefBase &right,
00437 const class QueRefProto &query
00438 )
00439
00440 {
00441 ProtoBase *_left_prototype = Class[_leftClassName];
00442 RefBase r = right;
00443
00444 #ifdef GC_REL11_TRACE
00445 logmsg("OneToOneRelationBase::LGetAll(...) invoked");
00446 #endif
00447
00448 if (right.IsTransient())
00449 return NULL;
00450
00451
00452
00453 char *_Columns = StrCpy(
00454 _Columns=NULL,
00455 _rightColumnName
00456 );
00457 char *_Values = r._KeyValues();
00458 char *_1Column = NULL;
00459 char *_1Value = NULL;
00460 char *_KeyCondition = NULL;
00461 char *_Separator = "(";
00462
00463 while (
00464 StrSplit(_Columns,',',_1Column)
00465 && StrSplit(_Values,',',_1Value)
00466 ) {
00467 StrCat(_KeyCondition,4,_Separator,_1Column," = ",_1Value);
00468 _Separator = ") AND (";
00469 };
00470 StrCat(_KeyCondition,")");
00471 StrFree(_Columns);
00472 StrFree(_Values);
00473 StrFree(_1Column);
00474 StrFree(_1Value);
00475
00476 ComplexQuery CQ(
00477 _KeyCondition,
00478 NULL,
00479 NULL,
00480 NULL
00481 );
00482 CQ.And(query);
00483
00484 CQ._order_by = query._OrderBy();
00485
00486 rb = _left_prototype -> ExecuteQuery(CQ,_databaseConnection,1,rb);
00487
00488 #ifdef GC_REL11_TRACE
00489 logmsg("OneToOneRelationBase::LGetAll() finished");
00490 #endif
00491
00492 return rb;
00493 };
00494
00495 ResultBase *OneToOneRelationBase::_RGetAll(
00496 ResultBase *rb,
00497 const class RefBase &left,
00498 const class QueRefProto &query
00499 )
00500
00501 {
00502 ProtoBase *_right_prototype = Class[_rightClassName];
00503 RefBase l = left;
00504
00505 #ifdef GC_REL11_TRACE
00506 logmsg("OneToOneRelationBase::RGetAll(...) invoked");
00507 #endif
00508
00509 if (left.IsTransient())
00510 return NULL;
00511
00512
00513
00514 char *_Columns = StrCpy(
00515 _Columns=NULL,
00516 _leftColumnName
00517 );
00518 char *_Values = l._KeyValues();
00519 char *_1Column = NULL;
00520 char *_1Value = NULL;
00521 char *_KeyCondition = NULL;
00522 char *_Separator = "(";
00523
00524 while (
00525 StrSplit(_Columns,',',_1Column)
00526 && StrSplit(_Values,',',_1Value)
00527 ) {
00528 StrCat(_KeyCondition,4,_Separator,_1Column," = ",_1Value);
00529 _Separator = ") AND (";
00530 };
00531 StrCat(_KeyCondition,")");
00532 StrFree(_Columns);
00533 StrFree(_Values);
00534 StrFree(_1Column);
00535 StrFree(_1Value);
00536
00537 ComplexQuery CQ(
00538 _KeyCondition,
00539 NULL,
00540 NULL,
00541 NULL
00542 );
00543 CQ.And(query);
00544 CQ._order_by = query._OrderBy();
00545
00546 rb = _right_prototype -> ExecuteQuery(CQ,_databaseConnection,1,rb);
00547
00548 #ifdef GC_REL11_TRACE
00549 logmsg("OneToOneRelationBase::RGetAll() finished");
00550 #endif
00551
00552 return rb;
00553 };
00554
00555 bool OneToOneRelationBase::ExistsCouple(
00556 const class RefBase &left,
00557 const class RefBase &right
00558 )
00559
00560 {
00561
00562
00563
00564
00565 bool _retval = false;
00566 ProtoBase *_left_prototype = Class[_leftClassName];
00567 RefBase l = left;
00568 RefBase r = right;
00569 int _sql_result_buffer = 0;
00570
00571 if (left.IsTransient() || right.IsTransient())
00572 return false;
00573 char *_select = StrCpy(_select = NULL, "0");
00574 StrClause(_select,"SELECT");
00575 char *_from = StrCpy(_from = NULL, _left_prototype -> From());
00576 StrClause(_from, "FROM");
00577 char *_1column = NULL;
00578 char *_columns = StrCpy(_columns = NULL, _left_prototype->KeySelect());
00579 StrCat(_columns,2,", ",_rightColumnName);
00580 char *_1value = NULL;
00581 char *_values = l._KeyValues();
00582 StrCat(_values,2,", ",_1value = r._KeyValues());
00583 StrFree(_1value);
00584 char *_where = NULL;
00585 char *_separator = "(";
00586 while (StrSplit(_columns,',',_1column) && StrSplit(_values,',',_1value))
00587 {
00588 StrPrefixCut(_1column,'.');
00589 StrCat(_where,4,_separator,_1column," = ",_1value);
00590 _separator = ") AND (";
00591 };
00592 StrCat(_where,")");
00593 StrClause(_where,"WHERE");
00594 StrFree(_columns);
00595 StrFree(_1column);
00596 StrFree(_values);
00597 StrFree(_1value);
00598 StrCat(_select,2,_from,_where);
00599 StrFree(_from);
00600 StrFree(_where);
00601 if (_databaseConnection == NULL)
00602 throw ObjLibException_ConnectionError();
00603 if (_databaseConnection -> _Open())
00604 {
00605 if (_databaseConnection -> _Prepare(_select))
00606 {
00607 if (_databaseConnection -> _Execute())
00608 {
00609 if (_databaseConnection -> _PreFetchBind(
00610 1,
00611 &_sql_result_buffer,
00612 0,
00613 'i'
00614 )
00615 )
00616 {
00617 if (_databaseConnection -> _FetchNext())
00618 {
00619 _retval = true;
00620 };
00621 };
00622 };
00623 };
00624 _databaseConnection -> _Close();
00625 };
00626 StrFree(_select);
00627 return _retval;
00628 };
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662 const char *OneToOneRelationBase::_TableName() const {
00663 return Class[_rightClassName]->From();
00664 };
00665
00666
00667
00668
00669 bool OneToOneRelationBase::WriteDDL(ofstream &S, class Database &Db)
00670
00671 {
00672 if (!S.rdbuf()->is_open())
00673 return false;
00674 ProtoBase *_left_prototype=Class[_leftClassName];
00675 ProtoBase *_right_prototype=Class[_rightClassName];
00676 char *_pk = NULL;
00677 char *_pk1 = NULL;
00678 char *_pklt = NULL;
00679 char *_pkrt = NULL;
00680 char *_fk = NULL;
00681 char *_fk1 = NULL;
00682 char *_fklt = NULL;
00683 char *_fkrt = NULL;
00684 char *typ = NULL;
00685 int c;
00686 const char *delimcols = "";
00687 const char *delimkeys;
00688 S << "-- One to one relation " << _tableName << " between classes " << _leftClassName << " and " << _rightClassName << endl;
00689
00690 S << "ALTER TABLE " << _left_prototype->From() << " ADD(";
00691
00692 c = 0;
00693 StrCpy(_pk,_right_prototype->KeySelect());
00694 StrCpy(_fk,_rightColumnName);
00695 delimkeys = "";
00696 while (StrSplit(_fk,',',_fk1) && StrSplit(_pk,',',_pk1))
00697 {
00698 StrPrefixCut(_pk1,'.');
00699 StrPrefixCut(_fk1,'.');
00700 StrCat(_pkrt,2,delimkeys,_pk1);
00701 StrCat(_fkrt,2,delimkeys,_fk1);
00702 delimkeys = ",";
00703 typ = _right_prototype->ColumnTypeDDL(c,Db);
00704 S << delimcols << endl << _fk1 << " " << typ;
00705 StrFree(typ);
00706 delimcols = ",";
00707 c++;
00708 };
00709 StrFree(_pk);
00710 StrFree(_pk1);
00711 StrFree(_fk);
00712 StrFree(_fk1);
00713
00714 S << delimcols << endl << "CONSTRAINT " << _tableName << "_FK_R FOREIGN KEY(" << _fkrt << ") REFERENCES " << _right_prototype->From() << "(" << _pkrt << ")";
00715 delimcols = ",";
00716
00717 S << endl << ");"<< endl << endl;
00718
00719 S << "CREATE UNIQUE INDEX " << _tableName << "_RK_R ON " << _left_prototype->From() << "(" << _fkrt << ");" << endl << endl;
00720
00721 S << "ALTER TABLE " << _right_prototype->From() << " ADD(";
00722
00723 c = 0;
00724 StrCpy(_pk,_left_prototype->KeySelect());
00725 StrCpy(_fk,_leftColumnName);
00726 delimkeys = "";
00727 while (StrSplit(_fk,',',_fk1) && StrSplit(_pk,',',_pk1))
00728 {
00729 StrPrefixCut(_pk1,'.');
00730 StrPrefixCut(_fk1,'.');
00731 StrCat(_pklt,2,delimkeys,_pk1);
00732 StrCat(_fklt,2,delimkeys,_fk1);
00733 delimkeys = ",";
00734 typ = _left_prototype->ColumnTypeDDL(c,Db);
00735 S << delimcols << endl << _fk1 << " " << typ;
00736 StrFree(typ);
00737 delimcols = ",";
00738 c++;
00739 };
00740 StrFree(_pk);
00741 StrFree(_pk1);
00742 StrFree(_fk);
00743 StrFree(_fk1);
00744
00745 S << delimcols << endl << "CONSTRAINT " << _tableName << "_FK_L FOREIGN KEY(" << _fklt << ") REFERENCES " << _left_prototype->From() << "(" << _pklt << ")";
00746
00747
00748 S << endl << ");"<< endl << endl;
00749
00750 S << "CREATE UNIQUE INDEX " << _tableName << "_RK_L ON " << _right_prototype->From() << "(" << _fklt << ");" << endl << endl;
00751 S.flush();
00752 StrFree(_pkrt);
00753 StrFree(_pklt);
00754 StrFree(_fkrt);
00755 StrFree(_fklt);
00756 return true;
00757 };