为什么 - 在Firebird中使用此代码块时 - v_start
和v_end
变量是否始终相等?为什么在没有suspend
语句的情况下它总是返回null?
execute block
returns (elapsed numeric(9,3),
v_start timestamp,
v_end timestamp)
as
declare variable i integer;
begin
i = 1000000;
v_start = current_timestamp;
while (i > 0) do
i = i - 1;
v_end = current_timestamp;
elapsed = v_end - v_start;
suspend;
end
答案 0 :(得分:4)
是的,SUSPEND
值在PSQL模块中保持不变,这是documented(引自注释部分):
在PSQL模块(过程,触发器或可执行块)中,每次读取时CURRENT_TIMESTAMP的值都将保持不变。如果多个模块相互调用或触发,则该值将在最外层模块的整个持续时间内保持不变。如果您需要PSQL中的进度值(例如,测量时间间隔),请使用' NOW'。
使用if (uri.matches(Constants.GET_ALL_APIS_STORE_REGEX)) {
long lastUpdatedTime = InBoundETagManager.apisGet(null, null, tenantDomain, null);
String eTag = ETagGenerator.getETag(lastUpdatedTime);
if (eTag.equals(ifNoneMatch)) {
message.getExchange().put("ETag", eTag);
generate304NotModifiedResponse(message);
}
message.getExchange().put("ETag", eTag);
}
else if (uri.matches(Constants.GET_API_FOR_ID_REGEX)) { // /apis/{apiId}
apiId = UUIDList.get(0);
String requestedTenantDomain = RestApiUtil.getRequestedTenantDomain(tenantDomain);
long lastUpdatedTime = InBoundETagManager.apisApiIdGet(apiId, requestedTenantDomain, uri);
String eTag = ETagGenerator.getETag(lastUpdatedTime);
handleInterceptorResponse(message, ifNoneMatch, eTag);
}
else if (uri.matches(Constants.GET_SWAGGER_FOR_API_ID_REGEX)) { // /apis/{apiId}/swagger
apiId = UUIDList.get(0);
long lastUpdatedTime = InBoundETagManager.apisApiIdSwaggerGet(apiId, tenantDomain);
String eTag = ETagGenerator.getETag(lastUpdatedTime);
if (lastUpdatedTime == 0L) {
log.info("No last updated time available for the desired API swagger json file");
}
handleInterceptorResponse(message, ifNoneMatch, eTag);
}
的要求也是documented:
如果块具有输出参数,则必须使用SUSPEND或不返回任何内容。
答案 1 :(得分:0)
使用此代码按预期工作...
execute block
returns (elapsed bigint,
v_start timestamp,
v_end timestamp)
as
declare variable i integer;
begin
i = 100000000;
v_start = 'now';
while (i > 0) do
i = i - 1;
v_end = 'now';
elapsed = datediff (second from cast(:v_start as timestamp) to cast('now' as timestamp));
suspend;
end