コード例 #1
0
ファイル: DbAction.C プロジェクト: bvanhauwaert/wt
void SaveBaseAction::exec()
{
  statement_->execute();

  if (isInsert_ && mapping().surrogateIdFieldName)
    dbo().setAutogeneratedId(statement_->insertedId());

  dbo().setTransactionState(MetaDboBase::SavedInTransaction);
}
コード例 #2
0
ファイル: main.c プロジェクト: eleuteriotrindade/bcciqa
int main(){

	printf("Entre com os parâmetros\n\n");
	
	oxigenio();
	
	coliformesfecais();
	
	ph();
	
	dbo();
	
	totalnitrato();
	
	totalfosfato();
	
	temperatura();
	
	turbidez();
	
	residuostotais();

	somatorio();
	
	return 0;
}
コード例 #3
0
ファイル: DbAction.C プロジェクト: bvanhauwaert/wt
void LoadBaseAction::start()
{
  if (mapping().versionFieldName) {
    int version;
    statement_->getResult(column_++, &version);
    dbo().setVersion(version);
  }
}
コード例 #4
0
ファイル: DbAction.C プロジェクト: bvanhauwaert/wt
void SaveBaseAction::startSelfPass()
{
  pass_ = Self;
  needSetsPass_ = false;

  statement_->reset();
  column_ = 0;

  if (mapping().versionFieldName)
    statement_->bind(column_++, dbo().version() + 1);
}
コード例 #5
0
ファイル: DatabaseServer.cpp プロジェクト: Idylia/OpenOTP
		virtual void handle_datagram(Datagram &in_dg, DatagramIterator &dgi)
		{
			channel_t sender = dgi.read_uint64();
			unsigned short msg_type = dgi.read_uint16();
			switch(msg_type)
			{
				case DBSERVER_CREATE_STORED_OBJECT:
				{
					unsigned int context = dgi.read_uint32();

					// Start response with generic header
					Datagram resp;
					resp.add_server_header(sender, m_control_channel, DBSERVER_CREATE_STORED_OBJECT_RESP);
					resp.add_uint32(context);

					// Get DistributedClass
					unsigned short dc_id = dgi.read_uint16();
					DCClass *dcc = gDCF->get_class(dc_id);
					if(!dcc)
					{
						m_log->error() << "Invalid DCClass when creating object: #" << dc_id << std::endl;
						resp.add_uint32(0);
						send(resp);
						return;
					}

					// Unpack fields to be passed to database
					DatabaseObject dbo(dc_id);
					unsigned short field_count = dgi.read_uint16();
					m_log->spam() << "Unpacking fields..." << std::endl;
					try
					{
						for(unsigned int i = 0; i < field_count; ++i)
						{
							unsigned short field_id = dgi.read_uint16();
							DCField *field = dcc->get_field_by_index(field_id);
							if(field)
							{
								if(field->is_db())
								{
									dgi.unpack_field(field, dbo.fields[field]);
								}
								else
								{
									std::string tmp;
									dgi.unpack_field(field, tmp);
								}
							}
						}
					}
					catch(std::exception &e)
					{
						m_log->error() << "Error while unpacking fields, msg may be truncated. e.what(): "
							<< e.what() << std::endl;

						resp.add_uint32(0);
						send(resp);
						return;
					}

					// Check for required fields, and populate with defaults
					m_log->spam() << "Checking all required fields exist..." << std::endl;
					for(int i = 0; i < dcc->get_num_inherited_fields(); ++i)
					{
						DCField *field = dcc->get_inherited_field(i);
						if(field->is_required() && field->is_db() && !field->as_molecular_field())
						{
							if(dbo.fields.find(field) == dbo.fields.end())
							{
								if(!field->has_default_value())
								{
									m_log->error() << "Field " << field->get_name() << " missing when trying to create "
										"object of type " << dcc->get_name();

									resp.add_uint32(0);
									send(resp);
									return;
								}
								else
								{
									dbo.fields[field] = field->get_default_value();
								}
							}
						}
					}

					// Create object in database
					m_log->spam() << "Creating stored object..." << std::endl;
					unsigned int do_id = m_db_engine->create_object(dbo);
					if(do_id == 0 || do_id < m_min_id || do_id > m_max_id)
					{
						m_log->error() << "Ran out of DistributedObject ids while creating new object." << std::endl;
						resp.add_uint32(0);
						send(resp);
						return;
					}

					m_log->spam() << "... created with ID: " << do_id << std::endl;
					resp.add_uint32(do_id);
					send(resp);
				}
				break;
				case DBSERVER_SELECT_STORED_OBJECT_ALL:
				{
					unsigned int context = dgi.read_uint32();

					Datagram resp;
					resp.add_server_header(sender, m_control_channel, DBSERVER_SELECT_STORED_OBJECT_ALL_RESP);
					resp.add_uint32(context);

					unsigned int do_id = dgi.read_uint32();

					DatabaseObject dbo;
					if(m_db_engine->get_object(do_id, dbo))
					{
						resp.add_uint8(1);
						resp.add_uint16(dbo.dc_id);
						resp.add_uint16(dbo.fields.size());
						for(auto it = dbo.fields.begin(); it != dbo.fields.end(); ++it)
						{
							resp.add_uint16(it->first->get_number());
							resp.add_data(it->second);
						}
					}
					else
					{
						resp.add_uint8(0);
					}
					send(resp);
				}
				break;
				case DBSERVER_DELETE_STORED_OBJECT:
				{
					if(dgi.read_uint32() == DBSERVER_DELETE_STORED_OBJECT_VERIFY_CODE)
					{
						unsigned int do_id = dgi.read_uint32();
						m_db_engine->delete_object(do_id);
						m_log->debug() << "Deleted object with ID: " << do_id << std::endl;
					}
					else
					{
						m_log->warning() << "Wrong delete verify code." << std::endl;
					}
				}
				break;
				default:
					m_log->error() << "Recieved unknown MsgType: " << msg_type << std::endl;
			};
		}
コード例 #6
0
ファイル: OldDatabaseBackend.cpp プロジェクト: Astron/Astron
void OldDatabaseBackend::submit(DBOperation *operation)
{
    std::lock_guard<std::mutex> lock(m_submit_lock);
    switch(operation->type()) {
    case DBOperation::OperationType::CREATE_OBJECT: {
        ObjectData dbo(operation->dclass()->get_id());
        dbo.fields = operation->set_fields();

        doid_t doid = create_object(dbo);
        if(doid == INVALID_DO_ID || doid < m_min_id || doid > m_max_id) {
            operation->on_failure();
        } else {
            operation->on_complete(doid);
        }
        return;
    }
    break;
    case DBOperation::OperationType::DELETE_OBJECT: {
        delete_object(operation->doid());
        operation->on_complete();
        return;
    }
    break;
    case DBOperation::OperationType::GET_OBJECT:
    case DBOperation::OperationType::GET_FIELDS: {
        ObjectData dbo;
        if(!get_object(operation->doid(), dbo)) {
            operation->on_failure();
            return;
        }

        const dclass::Class *dclass = g_dcf->get_class_by_id(dbo.dc_id);
        if(!dclass || !operation->verify_class(dclass)) {
            operation->on_failure();
            return;
        }

        // Send object to server
        DBObjectSnapshot *snap = new DBObjectSnapshot();
        snap->m_dclass = dclass;
        snap->m_fields = dbo.fields;
        operation->on_complete(snap);
        return;
    }
    break;
    case DBOperation::OperationType::SET_FIELDS: {
        // Check the object's class and fields
        const dclass::Class *dclass = get_class(operation->doid());
        if(!dclass || !operation->verify_class(dclass)) {
            operation->on_failure();
            return;
        }

        // If everthing checks out, update our fields
        for(auto it = operation->set_fields().begin(); it != operation->set_fields().end(); ++it) {
            if(!it->second.empty()) {
                set_field(operation->doid(), it->first, it->second);
            } else {
                del_field(operation->doid(), it->first);
            }
        }

        operation->on_complete();
        return;
    }
    break;
    case DBOperation::UPDATE_FIELDS: {
        // TODO: This can be implemented *much* more efficiently, but for now:
        ObjectData dbo;
        if(!get_object(operation->doid(), dbo)) {
            operation->on_failure();
            return;
        }

        // Make sure all the fields are valid for the class
        const dclass::Class *dclass = g_dcf->get_class_by_id(dbo.dc_id);
        if(!dclass || !operation->verify_class(dclass)) {
            operation->on_failure();
            return;
        }

        // Check to make sure the update is valid
        for(auto it = operation->criteria_fields().begin(); it != operation->criteria_fields().end();
            ++it) {
            if(dbo.fields[it->first] != it->second) {
                DBObjectSnapshot *snap = new DBObjectSnapshot();
                snap->m_fields = dbo.fields;
                operation->on_criteria_mismatch(snap);
                return;
            }
        }

        // Everything checks out, so update the fields
        for(auto it = operation->set_fields().begin(); it != operation->set_fields().end(); ++it) {
            if(!it->second.empty()) {
                set_field(operation->doid(), it->first, it->second);
            } else {
                del_field(operation->doid(), it->first);
            }
        }

        operation->on_complete();
        return;
    }
    }
}