I want to set the length to MAX for one of my XML fields.
XML Code:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharFixed" LENGTH="3" />
<FIELD ID="2" xsi:type="CharFixed" LENGTH="MAXLENGTH" />
<FIELD ID="3" xsi:type="CharFixed" LENGTH="10" />
<FIELD ID="4" xsi:type="CharFixed" LENGTH="8" />
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="Field1" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="2" NAME="Field2" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="3" NAME="Field3" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="4" NAME="Field4" xsi:type="SQLNVARCHAR"/>
</ROW>
</BCPFORMAT>
But 'MAXLENGTH' does not seem to work.
Error message:
bad value MAXLENGTH for attribute "LENGTH"
Any suggestions on how to put the LENGTH to maximum ?
The length of a string is limited to 4000 (nchar) or 8000 (char) type. There is no max length-constant - AFAIC
Refer to this, "Field Attributes"
If you look up the schema meta-data just as SQL Server does, you can follow this link
http://schemas.microsoft.com/sqlserver/2004/bulkload/format/bulkloadschema.xsd
to find this
<xsd:attribute name="LENGTH" type="xsd:positiveInteger" use="required"/>
[...]
<xsd:attribute name="MAX_LENGTH" type="xsd:positiveInteger" use="optional"/>
So the length is required while max_length seems to be optional, but if you specify it, it must be a positive integer.
Related
I'm trying to create an initiator based on QuickFix/n.
My counterpart (server) demand the logon message to carry two custom fields.I already added those to the Data Dictionary, in the Fields as well as in the Logon message.
In the code i can manipulate the message to add the username and password, but i can't find how to load custom fields.
Here are some excerpts from what i've done so far:
TradeClientApp.cs
...
public void ToAdmin(Message message, SessionID sessionID)
{
QuickFix.SessionSettings settings = new QuickFix.SessionSettings("./initiator.cfg");
List<SessionID> sids = settings.GetSessions().ToList();
Dictionary settingsDict = settings.Get(sids.First());
var appName = settingsDict.GetString("ApplicationName");
var userType = settingsDict.GetString("UserType");
if (message.GetType() == typeof(QuickFix.FIX44.Logon))
{
message.SetField(new Username("USERNAME"));
message.SetField(new Password("PASSWORD"));
message.SetField(new QuickFix.Fields.ResetSeqNumFlag(true));
//tag 9933
message.SetField(new RawData(string.Format($"9933={appName}")));
//tag 20110
message.SetField(new RawData(string.Format($"20110={userType}")));
}
}
The initiator.cfg file:
[DEFAULT]
UseDataDictionary=Y
DataDictionary=./spec/FIX44.xml
FileStorePath=store
FileLogPath=log
ConnectionType=initiator
ReconnectInterval=60
[SESSION]
BeginString=FIX.4.4
SenderCompID=USERNAME
ResetSeqNumFlag=Y
Username=USERNAME
Password=PASSWORD
TargetCompID=TARGETCOMPID
StartTime=12:30:00
EndTime=23:30:00
HeartBtInt=10
ApplicationName=app-name
UserType=V
SocketConnectPort=446
SocketConnectHost=SERVERHOST
Inside the FIX44.XML
<message name="Logon" msgtype="A" msgcat="admin">
<field name="EncryptMethod" required="Y" />
<field name="HeartBtInt" required="Y" />
<field name="RawDataLength" required="N" />
<field name="RawData" required="N" />
<field name="ResetSeqNumFlag" required="N" />
<field name="NextExpectedMsgSeqNum" required="N" />
<field name="MaxMessageSize" required="N" />
<group name="NoMsgTypes" required="N">
<field name="RefMsgType" required="N" />
<field name="MsgDirection" required="N" />
</group>
<field name="TestMessageIndicator" required="N" />
<field name="Username" required="N" />
<field name="Password" required="N" />
<field name="ApplicationName" required="N" />
<field name="UserType" required="N" />
</message>
<fields>
...
<field number="9933" name="ApplicationName" type="STRING"/>
<field number="20110" name="UserType" type="STRING" />
</fields>
</fix>
When i try to connect i get this log:
<outgoing> 8=FIX.4.49=12035=A34=149=USERNAME52=20191008-21:19:41.49856=TARGETCOMPID96=20110=V98=0108=10141=Y553=USERNAME554=PASSWORD10=097
Using the RawData as shown in my example, the message carries 20110=V as RawData, which is tag 96, which doesn't help me.
I already tried inside ToAdmin:
message.Header.SetField(new StringField(QuickFix.Fields.Tags.UserType, ""));
or
message.SetField(new QuickFix.Fields.UserType(true));
but neither work.
How on earth do you add custom fields to the logon message?
I think you are getting the RawData data type wrong. That is literally meant for raw data, not for Strings that follow the default encoding.
From the spec:
string field containing raw data with no format or content
restrictions. Data fields are always immediately preceded by a length
field. The length field should specify the number of bytes of the
value of the data field (up to but not including the terminating SOH).
I am not so familiar with the C# implementation of QuickFIX but you should simply be able to add these fields with the specific tag number, e.g.
message.SetField(new StringField(20110, "V"));
I hope there are no syntax errors, but you should get the idea.
Edit: I see you are manually setting the ResetSeqNum field on the Logon message. This is discouraged. quickFIX/n should deal with this when you set ResetSeqNum=Y in the settings (you already have that setting).
Could you please assist with next:
I have a table with column of type SYSTIMESTAMP WITH TIME ZONE and with default value - SYSTIMESTAMP. I use Entity Framework 5 database first. When I try to insert entity in this table I get an exception. The exception message is “A store-generated value of type 'System.DateTime' could not be converted to a value of type 'System.DateTimeOffset' required for member 'INSERT_DATE' of type 'Model.SAMPLE'.”. The inner exception message is: “Invalid cast from 'System.DateTime' to 'System.DateTimeOffset'.”
I use ODAC 12.1012 unmanaged driver.
How should I solve this problem?Sample table script:
CREATE TABLE "TEST"."SAMPLE"
( "ID" NUMBER NOT NULL ENABLE,
"INSERT_DATE" TIMESTAMP (6) WITH TIME ZONE DEFAULT systimestamp,
"TEXT_COLUMN" VARCHAR2(200 BYTE),
CONSTRAINT "SAMPLE_PK" PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSTEM" ENABLE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSTEM" ;
edmx file content:
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Model.Store" Provider="Oracle.DataAccess.Client" ProviderManifestToken="11.2" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
<EntityType Name="SAMPLE">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="number" Precision="38" Scale="0" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="INSERT_DATE" Type="timestamp with time zone" Precision="6" StoreGeneratedPattern="Identity" />
<Property Name="TEXT_COLUMN" Type="varchar2" MaxLength="200" />
</EntityType>
<EntityContainer Name="ModelStoreContainer">
<EntitySet Name="SAMPLE" EntityType="Self.SAMPLE" Schema="TEST" store:Type="Tables" />
</EntityContainer>
</Schema>
</edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema Namespace="Model" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityContainer Name="vm2" annotation:LazyLoadingEnabled="true">
<EntitySet Name="SAMPLE" EntityType="Model.SAMPLE" />
</EntityContainer>
<EntityType Name="SAMPLE">
<Key>
<PropertyRef Name="ID" />
</Key>
<Property Name="ID" Type="Decimal" Nullable="false" Precision="38" Scale="0" annotation:StoreGeneratedPattern="Identity" />
<Property Name="INSERT_DATE" Type="DateTimeOffset" Precision="9" annotation:StoreGeneratedPattern="Identity" />
<Property Name="TEXT_COLUMN" Type="String" MaxLength="200" FixedLength="false" Unicode="false" />
</EntityType>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
<EntityContainerMapping StorageEntityContainer="ModelStoreContainer" CdmEntityContainer="vm2">
<EntitySetMapping Name="SAMPLE">
<EntityTypeMapping TypeName="Model.SAMPLE">
<MappingFragment StoreEntitySet="SAMPLE">
<ScalarProperty Name="TEXT_COLUMN" ColumnName="TEXT_COLUMN" />
<ScalarProperty Name="INSERT_DATE" ColumnName="INSERT_DATE" />
<ScalarProperty Name="ID" ColumnName="ID" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
Thanks in advance!
I have a problem with parsing above XML code. It doesn't look like normal XML structure - in the top of document is schema, which describe fields. Is there any simple method for parsing it?
<metadata>
<item name="number" type="xs:string" length="42"/>
<item name="artist" type="xs:string" length="62"/>
<item name="title" type="xs:string" length="502"/>
<item name="title supplement" type="xs:string" length="502"/>
<item name="price" type="xs:decimal" scale="2" precision="12"/>
</metadata>
<data>
<row>
<value>88697562032</value>
<value>1979 Revival Cast Recording</value>
<value>Oklahoma!</value>
<value>Softpack</value>
<value>25</value>
</row>
(...)
<row>
<value>88697919802</value>
<value>2CELLOS (Sulic & Hauser)</value>
<value>2CELLOS</value>
<value>Three Language Booklet Version</value>
<value>39.6</value>
</row>
</data>
I have an ever increasing number of BCP (t-sql) format files in XML that I need to read. I create the xsd file using xsd.exe and a number of BCP format files and attempt to read the xml file as an object. But it fails like this:
Unhandled Exception: System.InvalidOperationException: There is an error in XMLdocument (4, 6). ---> System.InvalidOperationException: The specified type was not recognized: name='CharTerm', namespace='http://schemas.microsoft.com/sqlserver/2004/bulkload/format', at .
The XML file is like this:
<?xml version="1.0" encoding="utf-8" ?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="32"/>
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="4"/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="4"/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR=";" MAX_LENGTH="20"/>
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR="\r\n" MAX_LENGTH="16"/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="col1" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="2" NAME="col2" xsi:type="SQLINT"/>
<COLUMN SOURCE="3" NAME="col3" xsi:type="SQLINT"/>
<COLUMN SOURCE="4" NAME="col4" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="5" NAME="col5" xsi:type="SQLFLT4"/>
</ROW>
</BCPFORMAT>
I read the XML file like this:
FileStream fs = File.OpenRead(formatFileName);
XmlSerializer serializer = new XmlSerializer(typeof(FormatSchemasXml.BCPFORMAT));
FormatSchemasXml.BCPFORMAT bcp_format = (FormatSchemasXml.BCPFORMAT)serializer.Deserialize(fs);
fs.Close();
The external xmlns reference does not seem to be used. I have searched a lot of documentation, but failed at seeing how I can fix this. Preferably without having to modify the BCP XML format files (I'd like to use them as is).
Suggestions?
my code gives me error : "'.', hexadecimal value 0x00, is an invalid character. Line 2, position 1."
string FileName = "20110606 100419 ServerForShop 1.xml";
string root = Server.MapPath("~/Include/Xml Files/Patch/");
var custs = from c in XElement.Load(root + FileName).Elements("Update")
select c;
I want to read and execute command a big xml file it is about 350MB how I can read it ? here is my xml file structure :
<?xml version="1.0" encoding="utf-8"?>
<Update>
<Object Name="Good">
<Insert Table="Good">
<Field Name="GoodCode" Value="1" Type="Integer" />
<Field Name="GoodUserCode" Value="" Type="String" />
.
.
.
</Insert>
</Object>
</Update>
I would recommend looking here for some samples http://support.microsoft.com/kb/307548
and perhaps here How does one parse XML files?