@@ -377,6 +377,10 @@ public override Column[] GetColumns(string table)
377377 {
378378 column . MigratorDbType = MigratorDbType . Int32 ;
379379 }
380+ else if ( dataTypeString == "bigint" )
381+ {
382+ column . MigratorDbType = MigratorDbType . Int64 ;
383+ }
380384 else if ( dataTypeString == "smallint" )
381385 {
382386 column . MigratorDbType = MigratorDbType . Int16 ;
@@ -439,21 +443,42 @@ public override Column[] GetColumns(string table)
439443
440444 if ( defaultValueString != null )
441445 {
446+ var bracesStrippedString = defaultValueString . Replace ( "(" , "" ) . Replace ( ")" , "" ) . Trim ( ) ;
447+ var bracesAndSingleQuoteStrippedString = bracesStrippedString . Replace ( "'" , "" ) ;
448+
442449 if ( column . Type == DbType . Int16 || column . Type == DbType . Int32 || column . Type == DbType . Int64 )
443450 {
444- column . DefaultValue = long . Parse ( column . DefaultValue . ToString ( ) ) ;
451+ column . DefaultValue = long . Parse ( bracesStrippedString , CultureInfo . InvariantCulture ) ;
445452 }
446453 else if ( column . Type == DbType . UInt16 || column . Type == DbType . UInt32 || column . Type == DbType . UInt64 )
447454 {
448- column . DefaultValue = ulong . Parse ( column . DefaultValue . ToString ( ) ) ;
455+ column . DefaultValue = ulong . Parse ( bracesStrippedString , CultureInfo . InvariantCulture ) ;
449456 }
450457 else if ( column . Type == DbType . Double || column . Type == DbType . Single )
451458 {
452- column . DefaultValue = double . Parse ( column . DefaultValue . ToString ( ) ) ;
459+ column . DefaultValue = double . Parse ( bracesAndSingleQuoteStrippedString , CultureInfo . InvariantCulture ) ;
453460 }
454461 else if ( column . Type == DbType . Boolean )
455462 {
456- column . DefaultValue = column . DefaultValue . ToString ( ) . Trim ( ) == "1" || column . DefaultValue . ToString ( ) . Trim ( ) . ToUpper ( ) == "TRUE" || column . DefaultValue . ToString ( ) . Trim ( ) == "YES" ;
463+ var truthy = new string [ ] { "'TRUE'" , "1" } ;
464+ var falsy = new string [ ] { "'FALSE'" , "0" } ;
465+
466+ if ( truthy . Contains ( bracesStrippedString ) )
467+ {
468+ column . DefaultValue = true ;
469+ }
470+ else if ( falsy . Contains ( bracesStrippedString ) )
471+ {
472+ column . DefaultValue = false ;
473+ }
474+ else if ( bracesStrippedString == "NULL" )
475+ {
476+ column . DefaultValue = null ;
477+ }
478+ else
479+ {
480+ throw new NotImplementedException ( $ "Cannot parse the boolean default value '{ defaultValueString } ' of column '{ column . Name } '") ;
481+ }
457482 }
458483 else if ( column . Type == DbType . DateTime || column . Type == DbType . DateTime2 )
459484 {
@@ -478,8 +503,7 @@ public override Column[] GetColumns(string table)
478503 }
479504
480505 // We convert to UTC since we restrict date time default values to UTC on default value definition.
481- var d = DateTime . ParseExact ( dt , "yyyy-MM-dd HH:mm:ss" , CultureInfo . InvariantCulture , DateTimeStyles . AdjustToUniversal | DateTimeStyles . AssumeUniversal ) ;
482- column . DefaultValue = d ;
506+ column . DefaultValue = DateTime . ParseExact ( dt , "yyyy-MM-dd HH:mm:ss" , CultureInfo . InvariantCulture , DateTimeStyles . AdjustToUniversal | DateTimeStyles . AssumeUniversal ) ;
483507 }
484508 else
485509 {
@@ -488,29 +512,37 @@ public override Column[] GetColumns(string table)
488512 }
489513 else if ( column . Type == DbType . Guid )
490514 {
491- if ( column . DefaultValue is string defVal )
492- {
493- var dt = defVal ;
494-
495- if ( defVal . StartsWith ( "'" ) )
496- {
497- dt = defVal . Substring ( 1 , defVal . Length - 2 ) ;
498- }
499-
500- var d = Guid . Parse ( dt ) ;
501- column . DefaultValue = d ;
502- }
515+ column . DefaultValue = Guid . Parse ( bracesAndSingleQuoteStrippedString ) ;
503516 }
504517 else if ( column . MigratorDbType == MigratorDbType . Decimal )
505518 {
506519 // We assume ((1.234))
507- var decimalString = defaultValueString . Replace ( "(" , "" ) . Replace ( ")" , "" ) ;
520+ column . DefaultValue = decimal . Parse ( bracesStrippedString , CultureInfo . InvariantCulture ) ;
521+ }
522+ else if ( column . MigratorDbType == MigratorDbType . String )
523+ {
524+ column . DefaultValue = bracesAndSingleQuoteStrippedString ;
525+ }
526+ else if ( column . MigratorDbType == MigratorDbType . Binary )
527+ {
528+ if ( bracesStrippedString . StartsWith ( "0x" ) )
529+ {
530+ var hexString = bracesStrippedString . Substring ( 2 ) ;
531+
532+ // Not available in old .NET version: Convert.FromHexString(hexString);
508533
509- column . DefaultValue = decimal . Parse ( decimalString , CultureInfo . InvariantCulture ) ;
534+ column . DefaultValue = Enumerable . Range ( 0 , hexString . Length / 2 )
535+ . Select ( x => Convert . ToByte ( hexString . Substring ( x * 2 , 2 ) , 16 ) )
536+ . ToArray ( ) ;
537+ }
538+ else
539+ {
540+ throw new NotImplementedException ( $ "Cannot parse the binary default value of '{ column . Name } '. The value is '{ defaultValueString } '") ;
541+ }
510542 }
511543 else
512544 {
513- throw new NotImplementedException ( $ "Cannot parse the default value of { column . Name } . Type '' is not implemented yet .") ;
545+ throw new NotImplementedException ( $ "Cannot parse the default value of { column . Name } type ' { column . MigratorDbType } '. It is not yet implemented - file an issue .") ;
514546 }
515547 }
516548 if ( ! reader . IsDBNull ( 5 ) )
0 commit comments