mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
server/mssql: fix parsing of text column values
GitOrigin-RevId: c4692cdc254af074f70cdceb78c7dc6211e7e084
This commit is contained in:
parent
6d04f587b4
commit
5a1f71b3bc
@ -15,6 +15,7 @@
|
|||||||
- server/mssql: fix malformed JSON answer on empty tables
|
- server/mssql: fix malformed JSON answer on empty tables
|
||||||
- server/mssql: fix runtime errors when selecting geography/geometry columns
|
- server/mssql: fix runtime errors when selecting geography/geometry columns
|
||||||
- server/mssql: supports connection pooling to sql server
|
- server/mssql: supports connection pooling to sql server
|
||||||
|
- server/mssql: fix text values erroneously being parsed as varchar
|
||||||
- server: improve errors messages for inconsistent sources
|
- server: improve errors messages for inconsistent sources
|
||||||
- console: add relationship tab for mssql tables (#677)
|
- console: add relationship tab for mssql tables (#677)
|
||||||
- build: fix the packaging of static console assets (fix #6610)
|
- build: fix the packaging of static console assets (fix #6610)
|
||||||
|
@ -9,6 +9,7 @@ import qualified Data.List.NonEmpty as NE
|
|||||||
import qualified Database.ODBC.SQLServer as ODBC
|
import qualified Database.ODBC.SQLServer as ODBC
|
||||||
import qualified Language.GraphQL.Draft.Syntax as G
|
import qualified Language.GraphQL.Draft.Syntax as G
|
||||||
|
|
||||||
|
import Data.Text.Encoding (encodeUtf8)
|
||||||
import Data.Text.Extended
|
import Data.Text.Extended
|
||||||
|
|
||||||
import qualified Hasura.Backends.MSSQL.Types as MSSQL
|
import qualified Hasura.Backends.MSSQL.Types as MSSQL
|
||||||
@ -176,15 +177,30 @@ msColumnParser
|
|||||||
msColumnParser columnType (G.Nullability isNullable) =
|
msColumnParser columnType (G.Nullability isNullable) =
|
||||||
opaque . fmap (ColumnValue columnType) <$> case columnType of
|
opaque . fmap (ColumnValue columnType) <$> case columnType of
|
||||||
ColumnScalar scalarType -> possiblyNullable scalarType <$> case scalarType of
|
ColumnScalar scalarType -> possiblyNullable scalarType <$> case scalarType of
|
||||||
MSSQL.WcharType -> pure (ODBC.TextValue <$> P.string)
|
-- bytestring
|
||||||
MSSQL.WvarcharType -> pure (ODBC.TextValue <$> P.string)
|
MSSQL.CharType -> pure $ ODBC.ByteStringValue . encodeUtf8 <$> P.string
|
||||||
MSSQL.WtextType -> pure (ODBC.TextValue <$> P.string)
|
MSSQL.VarcharType -> pure $ ODBC.ByteStringValue . encodeUtf8 <$> P.string
|
||||||
|
|
||||||
-- text
|
-- text
|
||||||
MSSQL.FloatType -> pure (ODBC.DoubleValue <$> P.float)
|
MSSQL.WcharType -> pure $ ODBC.TextValue <$> P.string
|
||||||
-- integer types
|
MSSQL.WvarcharType -> pure $ ODBC.TextValue <$> P.string
|
||||||
MSSQL.IntegerType -> pure (ODBC.IntValue . fromIntegral <$> P.int)
|
MSSQL.WtextType -> pure $ ODBC.TextValue <$> P.string
|
||||||
-- boolean type
|
MSSQL.TextType -> pure $ ODBC.TextValue <$> P.string
|
||||||
MSSQL.BitType -> pure (ODBC.BoolValue <$> P.boolean)
|
|
||||||
|
-- integer
|
||||||
|
MSSQL.IntegerType -> pure $ ODBC.IntValue . fromIntegral <$> P.int
|
||||||
|
MSSQL.SmallintType -> pure $ ODBC.IntValue . fromIntegral <$> P.int
|
||||||
|
MSSQL.BigintType -> pure $ ODBC.IntValue . fromIntegral <$> P.int
|
||||||
|
MSSQL.TinyintType -> pure $ ODBC.IntValue . fromIntegral <$> P.int
|
||||||
|
|
||||||
|
-- float
|
||||||
|
MSSQL.NumericType -> pure $ ODBC.DoubleValue <$> P.float
|
||||||
|
MSSQL.DecimalType -> pure $ ODBC.DoubleValue <$> P.float
|
||||||
|
MSSQL.FloatType -> pure $ ODBC.DoubleValue <$> P.float
|
||||||
|
MSSQL.RealType -> pure $ ODBC.DoubleValue <$> P.float
|
||||||
|
|
||||||
|
-- boolean
|
||||||
|
MSSQL.BitType -> pure $ ODBC.BoolValue <$> P.boolean
|
||||||
_ -> do
|
_ -> do
|
||||||
name <- mkMSSQLScalarTypeName scalarType
|
name <- mkMSSQLScalarTypeName scalarType
|
||||||
let schemaType = P.NonNullable $ P.TNamed $ P.mkDefinition name Nothing P.TIScalar
|
let schemaType = P.NonNullable $ P.TNamed $ P.mkDefinition name Nothing P.TIScalar
|
||||||
|
@ -7,10 +7,11 @@ module Hasura.Backends.MSSQL.Types.Internal where
|
|||||||
import Hasura.Prelude
|
import Hasura.Prelude
|
||||||
|
|
||||||
import qualified Data.Aeson as J
|
import qualified Data.Aeson as J
|
||||||
import Data.Text.Encoding (encodeUtf8)
|
|
||||||
import qualified Database.ODBC.SQLServer as ODBC
|
import qualified Database.ODBC.SQLServer as ODBC
|
||||||
import qualified Language.GraphQL.Draft.Syntax as G
|
import qualified Language.GraphQL.Draft.Syntax as G
|
||||||
|
|
||||||
|
import Data.Text.Encoding (encodeUtf8)
|
||||||
|
|
||||||
import Hasura.RQL.Types.Error
|
import Hasura.RQL.Types.Error
|
||||||
import Hasura.SQL.Backend
|
import Hasura.SQL.Backend
|
||||||
|
|
||||||
@ -302,32 +303,45 @@ scalarTypeDBName = \case
|
|||||||
|
|
||||||
parseScalarValue :: ScalarType -> J.Value -> Either QErr Value
|
parseScalarValue :: ScalarType -> J.Value -> Either QErr Value
|
||||||
parseScalarValue scalarType jValue = case scalarType of
|
parseScalarValue scalarType jValue = case scalarType of
|
||||||
|
-- bytestring
|
||||||
CharType -> ODBC.ByteStringValue . encodeUtf8 <$> parseJValue jValue
|
CharType -> ODBC.ByteStringValue . encodeUtf8 <$> parseJValue jValue
|
||||||
VarcharType -> ODBC.ByteStringValue . encodeUtf8 <$> parseJValue jValue
|
VarcharType -> ODBC.ByteStringValue . encodeUtf8 <$> parseJValue jValue
|
||||||
TextType -> ODBC.ByteStringValue . encodeUtf8 <$> parseJValue jValue
|
|
||||||
NumericType -> ODBC.FloatValue <$> parseJValue jValue
|
-- text
|
||||||
DecimalType -> ODBC.FloatValue <$> parseJValue jValue
|
TextType -> ODBC.TextValue <$> parseJValue jValue
|
||||||
IntegerType -> ODBC.IntValue <$> parseJValue jValue
|
|
||||||
SmallintType -> ODBC.IntValue <$> parseJValue jValue
|
|
||||||
FloatType -> ODBC.FloatValue <$> parseJValue jValue
|
|
||||||
RealType -> ODBC.FloatValue <$> parseJValue jValue
|
|
||||||
DateType -> ODBC.DayValue <$> parseJValue jValue
|
|
||||||
Ss_time2Type -> ODBC.TimeOfDayValue <$> parseJValue jValue
|
|
||||||
WcharType -> ODBC.TextValue <$> parseJValue jValue
|
WcharType -> ODBC.TextValue <$> parseJValue jValue
|
||||||
WvarcharType -> ODBC.TextValue <$> parseJValue jValue
|
WvarcharType -> ODBC.TextValue <$> parseJValue jValue
|
||||||
WtextType -> ODBC.TextValue <$> parseJValue jValue
|
WtextType -> ODBC.TextValue <$> parseJValue jValue
|
||||||
TimestampType -> ODBC.LocalTimeValue <$> parseJValue jValue
|
|
||||||
BinaryType -> ODBC.BinaryValue . ODBC.Binary . txtToBs <$> parseJValue jValue
|
-- integer
|
||||||
VarbinaryType -> ODBC.BinaryValue . ODBC.Binary . txtToBs <$> parseJValue jValue
|
IntegerType -> ODBC.IntValue <$> parseJValue jValue
|
||||||
|
SmallintType -> ODBC.IntValue <$> parseJValue jValue
|
||||||
BigintType -> ODBC.IntValue <$> parseJValue jValue
|
BigintType -> ODBC.IntValue <$> parseJValue jValue
|
||||||
TinyintType -> ODBC.IntValue <$> parseJValue jValue
|
TinyintType -> ODBC.IntValue <$> parseJValue jValue
|
||||||
BitType -> ODBC.ByteValue <$> parseJValue jValue
|
|
||||||
GuidType -> ODBC.TextValue <$> parseJValue jValue
|
|
||||||
|
|
||||||
|
-- float
|
||||||
|
NumericType -> ODBC.FloatValue <$> parseJValue jValue
|
||||||
|
DecimalType -> ODBC.FloatValue <$> parseJValue jValue
|
||||||
|
FloatType -> ODBC.FloatValue <$> parseJValue jValue
|
||||||
|
RealType -> ODBC.FloatValue <$> parseJValue jValue
|
||||||
|
|
||||||
|
-- boolean
|
||||||
|
BitType -> ODBC.ByteValue <$> parseJValue jValue
|
||||||
|
|
||||||
|
|
||||||
|
-- geo
|
||||||
-- TODO: We'll need to wrap this with geography::STGeomFromText
|
-- TODO: We'll need to wrap this with geography::STGeomFromText
|
||||||
GeographyType -> ODBC.TextValue <$> parseJValue jValue
|
GeographyType -> ODBC.TextValue <$> parseJValue jValue
|
||||||
GeometryType -> ODBC.TextValue <$> parseJValue jValue
|
GeometryType -> ODBC.TextValue <$> parseJValue jValue
|
||||||
|
|
||||||
|
-- misc
|
||||||
|
BinaryType -> ODBC.BinaryValue . ODBC.Binary . txtToBs <$> parseJValue jValue
|
||||||
|
VarbinaryType -> ODBC.BinaryValue . ODBC.Binary . txtToBs <$> parseJValue jValue
|
||||||
|
Ss_time2Type -> ODBC.TimeOfDayValue <$> parseJValue jValue
|
||||||
|
TimestampType -> ODBC.LocalTimeValue <$> parseJValue jValue
|
||||||
|
DateType -> ODBC.DayValue <$> parseJValue jValue
|
||||||
|
GuidType -> ODBC.TextValue <$> parseJValue jValue
|
||||||
|
|
||||||
-- the input format for types that aren't explicitly supported is a string
|
-- the input format for types that aren't explicitly supported is a string
|
||||||
UnknownType _ -> ODBC.TextValue <$> parseJValue jValue
|
UnknownType _ -> ODBC.TextValue <$> parseJValue jValue
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user