inline void putFields(const std::vector<field_t> &fields) { ++indent; for (const field_t &i: fields) { putField(i); } --indent; }
TableCursorKey::TableCursorKey(const KeyFileDefinition &keydef, const Tuple *keytuple, UINT fieldCount, RelationType relop) : m_keydef(keydef) { m_fieldCount = fieldCount; m_key.init(); m_relop = relop; if(relop == RELOP_FALSE || relop == RELOP_TRUE) return; if(relop == RELOP_NQ) { m_relop = RELOP_TRUE; m_fieldCount = 0; return; } if(fieldCount == 0) { return; } if(keytuple == NULL) { throwSqlError(SQL_FATAL_ERROR,_T("TableCursorKey:No Tuple specified but field = %d"),fieldCount); } const Tuple &tuple = *keytuple; if(fieldCount > tuple.size()) { throwSqlError(SQL_FATAL_ERROR,_T("TableCursorKey:invalid fieldCount (=%d) specified. Tuple.size = %zd") ,fieldCount,tuple.size()); } for(UINT i = 0; i < fieldCount; i++) { DbFieldType tupleType = tuple[i].getType(); DbFieldType keyType = keydef.getFieldDef(i).getType(); if(!isCompatibleType(keyType,tupleType)) { throwSqlError(SQL_TYPEMISMATCH,_T("Incompatible types in keydefinition(%s) and tupledefinition(%s)") ,getTypeString(keyType) ,getTypeString(tupleType)); } const TupleField &tupField = tuple[i]; switch(getMainType(tupleType)) { case MAINTYPE_NUMERIC : { if(!tupField.isDefined()) { setUndefinedField(i); return; } double d; tupField.get(d); if(putField(i,d)) return; break; } case MAINTYPE_STRING : { if(!tupField.isDefined()) { setUndefinedField(i); return; } String str; tupField.get(str); switch(getMainType(keyType)) { case MAINTYPE_STRING: if(putField(i,str)) return; break; case MAINTYPE_VARCHAR: { varchar vch(str.cstr()); if(putField(i,vch)) return; } } } break; case MAINTYPE_VARCHAR : { if(!tupField.isDefined()) { setUndefinedField(i); return; } varchar vch; tupField.get(vch); switch(getMainType(keyType)) { case MAINTYPE_STRING: { String str((TCHAR*)vch.data()); if(putField(i,str)) return; break; } case MAINTYPE_VARCHAR: if(putField(i,vch)) return; break; } } break; case MAINTYPE_DATE : { if(!tupField.isDefined()) { setUndefinedField(i); return; } Date d; tupField.get(d); keydef.put(m_key, i, d); } break; case MAINTYPE_TIME : { if(!tupField.isDefined()) { setUndefinedField(i); return; } Time d; tupField.get(d); keydef.put(m_key, i, d); } break; case MAINTYPE_TIMESTAMP: { if(!tupField.isDefined()) { setUndefinedField(i); return; } Timestamp d; tupField.get(d); keydef.put(m_key, i, d); } break; default: throwSqlError(SQL_FATAL_ERROR,_T("TableCursorKey:Invalid DbMainType :%d") ,getMainType(tupleType)); break; } } }
RecordBuffer* DbCreatorsList::getList(thread_db* tdbb, jrd_rel* relation) { fb_assert(relation); fb_assert(relation->rel_id == rel_sec_db_creators); RecordBuffer* buffer = getData(relation); if (buffer) { return buffer; } RefPtr<IAttachment> att; RefPtr<ITransaction> tra; const char* dbName = tdbb->getDatabase()->dbb_config->getSecurityDatabase(); if (!openDb(dbName, att, tra)) { // In embedded mode we are not raising any errors - silent return if (MasterInterfacePtr()->serverMode(-1) < 0) return makeBuffer(tdbb); (Arg::Gds(isc_crdb_nodb) << dbName).raise(); } Message gr; Field<ISC_SHORT> uType(gr); Field<Varying> u(gr, MAX_SQL_IDENTIFIER_LEN); FbLocalStatus st; RefPtr<IResultSet> curs(att->openCursor(&st, tra, 0, "select RDB$USER_TYPE, RDB$USER from RDB$DB_CREATORS", SQL_DIALECT_V6, NULL, NULL, gr.getMetadata(), NULL, 0)); if (st->getState() & IStatus::STATE_ERRORS) { if (!fb_utils::containsErrorCode(st->getErrors(), isc_dsql_relation_err)) check("IAttachment::openCursor", &st); // isc_dsql_relation_err when opening cursor - i.e. table // is missing due to non-FB3 security DB // In embedded mode we are not raising any errors - silent return if (MasterInterfacePtr()->serverMode(-1) < 0) return makeBuffer(tdbb); (Arg::Gds(isc_crdb_notable) << dbName).raise(); } try { buffer = makeBuffer(tdbb); while (curs->fetchNext(&st, gr.getBuffer()) == IStatus::RESULT_OK) { Record* record = buffer->getTempRecord(); record->nullify(); putField(tdbb, record, DumpField(f_sec_crt_user, VALUE_STRING, u->len, u->data)); SINT64 v = uType; putField(tdbb, record, DumpField(f_sec_crt_u_type, VALUE_INTEGER, sizeof(v), &v)); buffer->store(record); } check("IResultSet::fetchNext", &st); } catch (const Exception&) { clearSnapshot(); throw; } return getData(relation); }
int main(int argc, char *argv[]) { // expects no arguments because we are using a particular class file if (argc != 1) { fprintf(stderr, "Usage: heapTest\n"); exit(-1); } // initialize: need to use a class with a user class that has at least // four fields initializeVM(10000, "userClass.class"); // okay, begin the testing... Class A = getIthClass(4); Reference objectRef = allocateObject(getObjectClass()); Reference integerRef = allocateObject(getIntegerClass()); Reference aRef = allocateObject(A); Reference stringRef = allocateString("abcdefghijklmnopqrstuvwxyz"); if (getObjectClass() != getClass(objectRef)) { fprintf(stderr, "FAIL: getClass from objectRef\n"); } if (getIntegerClass() != getClass(integerRef)) { fprintf(stderr, "FAIL: getClass from integerRef\n"); } if (getStringClass() != getClass(stringRef)) { fprintf(stderr, "FAIL: getClass from stringRef\n"); } if (A != getClass(aRef)) { fprintf(stderr, "FAIL: getClass from aRef\n"); } if (strcmp(getStringValue(stringRef), "abcdefghijklmnopqrstuvwxyz")) { fprintf(stderr, "FAIL: getStringValue\n"); } putIntegerValue(integerRef, 1066); if (getIntegerValue(integerRef) != 1066) { fprintf(stderr, "FAIL: getIntegerValue\n"); } putField(aRef, 0, integerRef); if (getField(aRef, 0) != integerRef) { fprintf(stderr, "FAIL: getField 0\n"); } putField(aRef, 3, objectRef); if (getField(aRef, 3) != objectRef) { fprintf(stderr, "FAIL: getField 3\n"); } printf("testing complete.\n"); return 0; }