|
Dear all,
Is there something weird with Mono Data
Adapter?
My script code as attached below give different
result if I run using .NET and Mono.
Seems that there is a problem when filling
DataTable with DataAdapter.
Please your help.
-Aguss
private static string
p_GetNextSequence(string szPjkCode, string szFtrTypeCode, DateTime
dtmExtraction)
{ OraDatabase db = new OraDatabase(); string _debug = ""; //tambahan aguss try { _debug = "opening..;"; //tamabahn aguss db.Open(); _debug += "beginning...;"; //tambahan aguss db.Begin(); _debug += "getting text command...;"; //tambahan aguss OracleCommand cmd =
db.GetTextCommand();
// Check if the counter is already exist in the table. // Before getting the row, lock it first so that no one can modify it when we work on it. // Lock (by updating SEQ_NUMBER = SEQ_NUMBER + 1). // _debug +=
"executing updating sequence command...;"; //tambahan aguss
cmd.CommandText = "UPDATE UPLOADER_SEQUENCE SET"
+ " SEQ_NUMBER = SEQ_NUMBER + 1" + " WHERE" + " LOWER(PJK_CODE) = '" +
szPjkCode.ToLower() + "'" + " AND FTR_DATE = " +
DtmDateToOraDateString(dtmExtraction) + " AND LOWER(FTR_TYPE_CODE) = '" +
szFtrTypeCode.ToLower() +
"'";
_debug += cmd.CommandText + "...;"; cmd.ExecuteNonQuery();
// Read the row to check if the counter is already exist in the table. // cmd.CommandText = "SELECT SEQ_NUMBER" + " FROM UPLOADER_SEQUENCE" + " WHERE" + " LOWER(PJK_CODE) = '" + szPjkCode.ToLower() + "'" + " AND FTR_DATE = " + DtmDateToOraDateString(dtmExtraction) + " AND LOWER(FTR_TYPE_CODE) = '" + szFtrTypeCode.ToLower() + "'"; _debug +=
"creating data
adapater...;";
_debug += cmd.CommandText + "...;"; OracleDataAdapter da = new OracleDataAdapter(cmd); DataTable dt = new DataTable(); _debug +=
"filling data adapter...;";
da.Fill(dt);
int iNextSeqNo; _debug +="nilai Rows dari data adapter: " + dt.Rows.Count + "...;"; if (dt.Rows.Count == 0) { // If
counter not found, create (also set the SEQ_NUMBER =
1).
cmd.CommandText = "INSERT INTO UPLOADER_SEQUENCE (" + " PJK_CODE," + " FTR_DATE," + " FTR_TYPE_CODE," + " SEQ_NUMBER" + " ) VALUES (" + " '" + szPjkCode + "'," + " " + DtmDateToOraDateString(dtmExtraction) + "," + " '" + szFtrTypeCode + "'," + " 1" + " )"; _debug += "inserting into uploader sequence:..." + cmd.CommandText + "....;"; cmd.ExecuteNonQuery(); iNextSeqNo = 1; } else { // If found, return the counter. // No need to check if SEQ_NUMBER is null or not (it must not be null!). iNextSeqNo = System.Convert.ToInt32(dt.Rows[0]["SEQ_NUMBER"]); } // dt.Rows.Count. db.Commit(); //return iNextSeqNo; return "next sequence: " + iNextSeqNo.ToString() + "; " + _debug; } catch(Exception exp){ //tambahan aguss return ("Error get sequence: " + _debug + " " + exp.Message); //tambahan aguss } //tambahan aguss finally { db.Close(); } } Output from .NET:
opening..;beginning...;getting text
command...;executing updating sequence command...;UPDATE UPLOADER_SEQUENCE SET
SEQ_NUMBER = SEQ_NUMBER + 1 WHERE LOWER(PJK_CODE) = 'ppatk' AND FTR_DATE =
TO_DATE('27-7-2004', 'DD-MM-YYYY') AND LOWER(FTR_TYPE_CODE) = 'c'...;creating
data adapater...;SELECT SEQ_NUMBER FROM UPLOADER_SEQUENCE WHERE LOWER(PJK_CODE)
= 'ppatk' AND FTR_DATE = TO_DATE('27-7-2004', 'DD-MM-YYYY') AND
LOWER(FTR_TYPE_CODE) = 'c'...;filling data adapter...;nilai Rows dari data adapter: 1...;
Output from Mono
opening..;beginning...;getting text
command...;executing updating sequence command...;UPDATE UPLOADER_SEQUENCE SET
SEQ_NUMBER = SEQ_NUMBER + 1 WHERE LOWER(PJK_CODE) = 'ppatk' AND FTR_DATE =
TO_DATE('27-7-2004', 'DD-MM-YYYY') AND LOWER(FTR_TYPE_CODE) = 'c'...;creating
data adapater...;SELECT SEQ_NUMBER FROM UPLOADER_SEQUENCE WHERE LOWER(PJK_CODE)
= 'ppatk' AND FTR_DATE = TO_DATE('27-7-2004', 'DD-MM-YYYY') AND
LOWER(FTR_TYPE_CODE) = 'c'...;filling data adapter...;nilai Rows dari data adapter: 0...;
|
