📄 embed.cpp
字号:
#include <rdbCom.h>
#include <RDB.h>
#include <RInterpret.h>
#include <SYSTEM.h>
#include <RTuple.h>
#include <InOut.h>
SortLists sl;
Ref ref;
char kode[32];
SortList slr;
Relation r;
char name[10];
pTuple codeVec[16];
unsigned int i;
boolean AddAllAttrs(Relation r, SortList &s, RFs &keys)
{
unsigned int i, asize;
Attribute aptr;
char aname[32], atype[32], avalue[32];
i = 0;
keys[0].relation = 0;
for( ;; ) { /*iterate over all attributes of relation r*/
aptr = RGetAttr(r, i, aname, atype, asize); /*retrieve name,type name, field width*/
if ( aptr == Attribute(NULL) ) { break; }
INC(keys[0].relation); /*create an output permutation vector; [0] contains count of fields*/
keys[i+1].relation = 0;
keys[i+1].field = i;
atype = "ascending";
if ( ! RAddKey(s, aname, atype) ) { return false; }
INC(i);
}
return i!=0;
};
char PN[32];
void main(void)
{ char ncode[4];
ncode[0] = '\0';
for ( ;; ) { // LOOP
WriteLn();
WriteString("enter pn e.g. p1 or p2> ");
ReadString(PN);
/*************** select sn from spj where pn="p2"; ****************/
name = "spj";
ref.rcnt = 0;
ref.keys[0].relation = 1; /* the output permutation vector */
ref.keys[1].relation = 0; /* sn refers to relation 0 in the SortLists */
ref.keys[1].field = 0; /* and sn is field 0 in spj, pn 1, jn 2 etc.*/
r = RFind(name); /* make the relation accessible to the program*/
if ( r == Relation(NULL) ) { break; }
sl = NULL;
ROpenSortLists(sl); /* a list of permutation vectors on each relation*/
if ( sl == NULL ) { break; }
slr = NULL;
ROpenSort(r, slr); /* a permutation vector on a relation */
if ( slr == NULL ) { break; }
if ( AddAllAttrs(r, slr, ref.keys)==false ) { break; }
RAddSortList(sl, slr);
kode[0] = lkf;
kode[1] = '0';
kode[2] = '0';
kode[3] = '0';
kode[4] = '1';
kode[5] = lis;
kode[6] = '0';
kode[7] = '2';
kode[8] = PN[0];
kode[9] = PN[1];
kode[10] = cmp;
kode[11] = eql;
kode[12] = stop;
kode[13] = '\0'; /* OR if you are in the know*/
for ( i = 1 ; i <= ref.keys[0].relation ; i = i + 1 ) { /*number of output fields*/
codeVec[i] = ADR(ncode);
}
codeVec[0] = ADR(kode);
if ( Project(sl, ref, codeVec, "rdbcur", true) == 0 ) {
WriteString("no matching part number");
WriteLn();
break;
}
RCloseSortLists(sl);
RCDone(r);
/********************************* join rdbcur,s into temp; */
if ( Join("rdbcur", "s", "temp") == 0 ) { /* pretty simple!! */
WriteString("itegrity problem: missing supplier number");
WriteLn();
break;
}
/********************************** print * from temp; */
name = "temp";
r = RFind(name); /* make the relation accessible to the program*/
if ( r == Relation(NULL) ) { break; }
// Resize(r, 300); /*just for fun, add more tuples to temp*/
sl = NULL;
ROpenSortLists(sl); /* repeat the same operations as for Select */
if ( sl == NULL ) { break; }
slr = NULL;
ROpenSort(r, slr);
if ( slr == NULL ) { break; }
if ( AddAllAttrs(r, slr, ref.keys)==false ) { return; }
RAddSortList(sl, slr);
ref.rcnt = 0;
//kode = "t!"; /* just select all attributes from every tuple */
kode[0] = 't';
kode[1] = '!';
kode[2] = '\0';
for ( i = 1 ; i <= 10; i = i + 1 ) { /*number of output fields*/
codeVec[i] = ADR(ncode);
}
codeVec[0] = ADR(kode);
WriteLn();
WriteString("Here are the suppliers for jobs that use part ");
WriteString(PN); WriteLn();
if ( Print(sl, ref, codeVec, 1,"txt",true) == 0 ) {
WriteString("nothing printed");
WriteLn();
}
RCloseSortLists(sl);
RCDone(r);
} // LOOP
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -