我在php脚本中运行了以下查询,就插入所选值而言,它们完美地工作。但是第一次运行时,时间戳(time_of_report字段)的正确日期为00:00:00作为时间。当我再次运行它时,时间是正确的。
我假设它可能与我的更新/重复语法有关。我的Time_of_report字段确实是时间戳数据类型。
为什么必须运行两次才能正确更新时间戳?
$data = mysqli_query($conn,
"SELECT
c.extension
, sum(Duration) AS Total_Talk_Time_seconds
, round(sum(Duration) / 60,2) AS Total_Talk_Time_minutes
, sum(if(LEGTYPE1 = 1,1,0)) AS Total_Outbound
, sum( case when(legtype1 = 1 and duration > 60) then 1 else 0 end) AS Credit_for_outbound
, sum(if(LEGTYPE1 = 2,1,0) and ANSWERED = 1) AS Total_Inbound
, sum(if(Answered = 1,0,1)) AS Total_Missed
, SUM(IF(LEGTYPE1 = 1, 1, 0)) + -- outbound calls
SUM(IF(LEGTYPE1 = 2, 1, 0) AND ANSWERED = 1) + -- inbound calls
SUM(IF(Answered = 1, 0, 1)) AS Total_Calls
, NOW() AS Time_of_report
, curdate() AS Date_of_report
FROM cdrdb.session a
INNER JOIN cdrdb.callsummary b
ON a.NOTABLECALLID = b.NOTABLECALLID
INNER join cdrdb.mxuser c
ON a.RESPONSIBLEUSEREXTENSIONID = c.EXTENSIONID
WHERE b.ts >= curdate()
AND c.extension IN (7276,7314,7295,7306,7357,7200,7218,7247,7331,7255,7330,7000,7215,7240,7358,7312)
group by c.extension") or die(mysqli_error( $conn));
//statement 1, this inserts and updates upon duplicates into the
ambition.ambitionphone table which is our main table for all ambition
metric data.
$stmt = mysqli_prepare($conn2,
"INSERT into ambition.ambitionphone
(Extension,
Total_Talk_Time_seconds,
Total_Talk_Time_minutes,
Total_Outbound,
Credit_for_outbound,
Total_Inbound,
Missed_Calls,
Total_Calls,
Date_of_report,
Time_of_report )
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON duplicate key
update
Total_Talk_Time_seconds = values(Total_Talk_Time_seconds),
Total_Talk_Time_minutes = values(Total_Talk_Time_minutes),
Total_Inbound = values(Total_Inbound),
Total_Outbound = values(Total_Outbound),
Credit_for_outbound = values(Credit_for_outbound),
Missed_Calls = values(Missed_Calls),
Total_Calls = values(Total_Calls),
Time_of_report = NOW()
") or die(mysqli_error( $conn2));
答案 0 :(得分:1)
你是对的。第一次从php值设置Time_of_report(你没有显示你在 @Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
if (!this._text.isEmpty())
{
float textHorizontallyCenteredOriginX = this._measuredHeight / 2f;
float textHorizontallyCenteredOriginY = this._ascent;
canvas.translate(textHorizontallyCenteredOriginY, textHorizontallyCenteredOriginX);
canvas.rotate(-90);
canvas.drawText(this._text, 0, 0, this._textPaint);
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
try
{
this._textPaint.getTextBounds(this._text, 0, this._text.length(), this._textBounds);
this._tempView = new TextView(getContext());
this._tempView.setPadding(this._leftPadding, this._topPadding, this._rightPadding, this._bottomPadding);
this._tempView.setText(this._text);
this._tempView.setTextSize(TypedValue.COMPLEX_UNIT_PX, this._textSize);
this._tempView.setTypeface(this._typeface);
this._tempView.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
this._measuredWidth = this._tempView.getMeasuredHeight();
this._measuredHeight = this._tempView.getMeasuredWidth();
this._ascent = this._textBounds.height() / 2 + this._measuredWidth / 2;
setMeasuredDimension(this._measuredWidth, this._measuredHeight);
}
catch (Exception e)
{
setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
Log.e(LOG_TAG, Log.getStackTraceString(e));
}
}
之后设置的内容)。当你更新它时,你将Time_of_report设置为mysqli_prepare
。
我建议将Time_of_report的默认值设置为NOW()
:
NOW()
然后,您应该从插入代码中删除字段ALTER TABLE ambition.ambitionphone MODIFY COLUMN Time_of_report datetime NOT NULL DEFAULT NOW();
。