@@ -310,66 +310,56 @@ public static string ConvertToSqlFormat(object ob, bool wrapStringWithSingleQuot
310
310
if ( wrapStringWithSingleQuote )
311
311
sb . AppendFormat ( "'" ) ;
312
312
}
313
- //else if (ob is MySql.Data.Types.MySqlDateTime)
314
- //{
315
- // MySql.Data.Types.MySqlDateTime mdt = (MySql.Data.Types.MySqlDateTime)ob;
316
-
317
- // if (mdt.IsNull)
318
- // {
319
- // sb.AppendFormat("NULL");
320
- // }
321
- // else
322
- // {
323
- // if (mdt.IsValidDateTime)
324
- // {
325
- // DateTime dtime = mdt.Value;
326
-
327
- // if (wrapStringWithSingleQuote)
328
- // sb.AppendFormat("'");
329
-
330
- // if (col.MySqlDataType == "datetime")
331
- // sb.AppendFormat(dtime.ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));
332
- // else if (col.MySqlDataType == "date")
333
- // sb.AppendFormat(dtime.ToString("yyyy-MM-dd", _dateFormatInfo));
334
- // else if (col.MySqlDataType == "time")
335
- // sb.AppendFormat("{0}:{1}:{2}", mdt.Hour, mdt.Minute, mdt.Second);
336
- // //sb.AppendFormat(dtime.ToString("HH:mm:ss", _dateFormatInfo));
337
- // else
338
- // sb.AppendFormat(dtime.ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));
339
-
340
- // if (col.TimeFractionLength > 0)
341
- // {
342
- // sb.Append(".");
343
- // sb.Append(((MySql.Data.Types.MySqlDateTime)ob).Microsecond.ToString().PadLeft(col.TimeFractionLength, '0'));
344
- // }
345
-
346
- // if (wrapStringWithSingleQuote)
347
- // sb.AppendFormat("'");
348
- // }
349
- // else
350
- // {
351
- // if (wrapStringWithSingleQuote)
352
- // sb.AppendFormat("'");
353
-
354
- // if (col.MySqlDataType == "datetime")
355
- // sb.AppendFormat("0000-00-00 00:00:00");
356
- // else if (col.MySqlDataType == "date")
357
- // sb.AppendFormat("0000-00-00");
358
- // else if (col.MySqlDataType == "time")
359
- // sb.AppendFormat("00:00:00");
360
- // else
361
- // sb.AppendFormat("0000-00-00 00:00:00");
362
-
363
- // if (col.TimeFractionLength > 0)
364
- // {
365
- // sb.Append(".".PadRight(col.TimeFractionLength, '0'));
366
- // }
367
-
368
- // if (wrapStringWithSingleQuote)
369
- // sb.AppendFormat("'");
370
- // }
371
- // }
372
- //}
313
+ else if ( ob is MySqlDateTime mdt )
314
+ {
315
+ if ( mdt . IsValidDateTime )
316
+ {
317
+ DateTime dtime = mdt . GetDateTime ( ) ;
318
+
319
+ if ( wrapStringWithSingleQuote )
320
+ sb . AppendFormat ( "'" ) ;
321
+
322
+ if ( col . MySqlDataType == "datetime" )
323
+ sb . AppendFormat ( dtime . ToString ( "yyyy-MM-dd HH:mm:ss" , _dateFormatInfo ) ) ;
324
+ else if ( col . MySqlDataType == "date" )
325
+ sb . AppendFormat ( dtime . ToString ( "yyyy-MM-dd" , _dateFormatInfo ) ) ;
326
+ else if ( col . MySqlDataType == "time" )
327
+ sb . AppendFormat ( "{0}:{1}:{2}" , mdt . Hour , mdt . Minute , mdt . Second ) ;
328
+ else
329
+ sb . AppendFormat ( dtime . ToString ( "yyyy-MM-dd HH:mm:ss" , _dateFormatInfo ) ) ;
330
+
331
+ if ( col . TimeFractionLength > 0 )
332
+ {
333
+ sb . Append ( "." ) ;
334
+ sb . Append ( ( ( MySqlDateTime ) ob ) . Microsecond . ToString ( ) . PadLeft ( col . TimeFractionLength , '0' ) ) ;
335
+ }
336
+
337
+ if ( wrapStringWithSingleQuote )
338
+ sb . AppendFormat ( "'" ) ;
339
+ }
340
+ else
341
+ {
342
+ if ( wrapStringWithSingleQuote )
343
+ sb . AppendFormat ( "'" ) ;
344
+
345
+ if ( col . MySqlDataType == "datetime" )
346
+ sb . AppendFormat ( "0000-00-00 00:00:00" ) ;
347
+ else if ( col . MySqlDataType == "date" )
348
+ sb . AppendFormat ( "0000-00-00" ) ;
349
+ else if ( col . MySqlDataType == "time" )
350
+ sb . AppendFormat ( "00:00:00" ) ;
351
+ else
352
+ sb . AppendFormat ( "0000-00-00 00:00:00" ) ;
353
+
354
+ if ( col . TimeFractionLength > 0 )
355
+ {
356
+ sb . Append ( "." . PadRight ( col . TimeFractionLength , '0' ) ) ;
357
+ }
358
+
359
+ if ( wrapStringWithSingleQuote )
360
+ sb . AppendFormat ( "'" ) ;
361
+ }
362
+ }
373
363
else if ( ob is System . Guid )
374
364
{
375
365
if ( col . MySqlDataType == "binary(16)" )
0 commit comments