TableAdapter: Number of query values and destination fields are not the same - vb.net

I have been scratching my head about why this TableAdapter is giving me the error Number of query values and destination fields are not the same when calling the Update command for a couple days now. It looks good to me, with 5 parameters everywhere except where previously spotted in the comments, but obviously there is something I am missing.
Here's the relevant portions of the xml backing it:
<TableAdapter BaseClass="System.ComponentModel.Component" DataAccessorModifier="AutoLayout, AnsiClass, Class, Public" DataAccessorName="UomListTableAdapter" GeneratorDataComponentClassName="UomListTableAdapter" Name="UomList" UserDataComponentName="UomListTableAdapter">
<MainSource>
<DbSource ConnectionRef="DataConnectionString (MySettings)" DbObjectName="UomList" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="true" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="true" UserGetMethodName="GetData" UserSourceName="Fill">
<DeleteCommand>
<DbCommand CommandType="Text" ModifiedByUser="true">
<CommandText>DELETE FROM UomList
WHERE (SetID = ?) AND (Name = ?)</CommandText>
<Parameters>
<Parameter AllowDbNull="true" AutogeneratedName="Param1" ColumnName="" DataSourceName="" DataTypeServer="unknown" DbType="String" Direction="Input" ParameterName="SetID" Precision="0" ProviderType="VarWChar" Scale="0" Size="50" SourceColumn="SetID" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="false" AutogeneratedName="Param2" ColumnName="" DataSourceName="" DataTypeServer="unknown" DbType="String" Direction="Input" ParameterName="Name" Precision="0" ProviderType="VarWChar" Scale="0" Size="31" SourceColumn="Name" SourceColumnNullMapping="false" SourceVersion="Original" />
</Parameters>
</DbCommand>
</DeleteCommand>
<InsertCommand>
<DbCommand CommandType="Text" ModifiedByUser="true">
<CommandText>INSERT INTO UomList
(SetID, Name, Abbr, Qty, IsBase)
VALUES (?, ?, ?, ?)</CommandText>
<Parameters>
<Parameter AllowDbNull="true" AutogeneratedName="Param3" ColumnName="SetID" DataSourceName="" DataTypeServer="unknown" DbType="String" Direction="Input" ParameterName="SetID" Precision="0" ProviderType="VarWChar" Scale="0" Size="50" SourceColumn="SetID" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="false" AutogeneratedName="Param4" ColumnName="Name" DataSourceName="" DataTypeServer="unknown" DbType="String" Direction="Input" ParameterName="Name" Precision="0" ProviderType="VarWChar" Scale="0" Size="31" SourceColumn="Name" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="false" AutogeneratedName="Param5" ColumnName="Abbr" DataSourceName="" DataTypeServer="unknown" DbType="String" Direction="Input" ParameterName="Abbr" Precision="0" ProviderType="VarWChar" Scale="0" Size="31" SourceColumn="Abbr" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="false" AutogeneratedName="Param6" ColumnName="Qty" DataSourceName="" DataTypeServer="unknown" DbType="Double" Direction="Input" ParameterName="Qty" Precision="0" ProviderType="Double" Scale="0" Size="0" SourceColumn="Qty" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="false" AutogeneratedName="Param1" ColumnName="IsBase" DataSourceName="" DataTypeServer="unknown" DbType="Boolean" Direction="Input" ParameterName="IsBase" Precision="0" ProviderType="Boolean" Scale="0" Size="0" SourceColumn="IsBase" SourceColumnNullMapping="false" SourceVersion="Current" />
</Parameters>
</DbCommand>
</InsertCommand>
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="true">
<CommandText>SELECT SetID, Name, Abbr, Qty, IsBase
FROM UomList</CommandText>
<Parameters />
</DbCommand>
</SelectCommand>
<UpdateCommand>
<DbCommand CommandType="Text" ModifiedByUser="true">
<CommandText>UPDATE UomList
SET Abbr = ?, Qty = ?, IsBase = ?
WHERE (SetID = ?) AND (Name = ?)</CommandText>
<Parameters>
<Parameter AllowDbNull="false" AutogeneratedName="Param1" ColumnName="Abbr" DataSourceName="" DataTypeServer="unknown" DbType="String" Direction="Input" ParameterName="Abbr" Precision="0" ProviderType="VarWChar" Scale="0" Size="31" SourceColumn="Abbr" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="false" AutogeneratedName="Param2" ColumnName="Qty" DataSourceName="" DataTypeServer="unknown" DbType="Double" Direction="Input" ParameterName="Qty" Precision="0" ProviderType="Double" Scale="0" Size="0" SourceColumn="Qty" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="false" AutogeneratedName="Param3" ColumnName="IsBase" DataSourceName="" DataTypeServer="unknown" DbType="Boolean" Direction="Input" ParameterName="IsBase" Precision="0" ProviderType="Boolean" Scale="0" Size="0" SourceColumn="IsBase" SourceColumnNullMapping="false" SourceVersion="Current" />
<Parameter AllowDbNull="true" AutogeneratedName="Param4" ColumnName="SetID" DataSourceName="" DataTypeServer="unknown" DbType="String" Direction="Input" ParameterName="Original_SetID" Precision="0" ProviderType="VarWChar" Scale="0" Size="50" SourceColumn="SetID" SourceColumnNullMapping="false" SourceVersion="Original" />
<Parameter AllowDbNull="false" AutogeneratedName="Param5" ColumnName="Name" DataSourceName="" DataTypeServer="unknown" DbType="String" Direction="Input" ParameterName="Original_Name" Precision="0" ProviderType="VarWChar" Scale="0" Size="31" SourceColumn="Name" SourceColumnNullMapping="false" SourceVersion="Original" />
</Parameters>
</DbCommand>
</UpdateCommand>
</DbSource>
</MainSource>
<Mappings>
<Mapping SourceColumn="SetID" DataSetColumn="SetID" />
<Mapping SourceColumn="Name" DataSetColumn="Name" />
<Mapping SourceColumn="Abbr" DataSetColumn="Abbr" />
<Mapping SourceColumn="Qty" DataSetColumn="Qty" />
<Mapping SourceColumn="IsBase" DataSetColumn="IsBase" />
</Mappings>
<Sources />
</TableAdapter>
<xs:element name="UomList" msprop:Generator_UserTableName="UomList" msprop:Generator_RowDeletedName="UomListRowDeleted" msprop:Generator_RowChangedName="UomListRowChanged" msprop:Generator_RowClassName="UomListRow" msprop:Generator_RowChangingName="UomListRowChanging" msprop:Generator_RowEvArgName="UomListRowChangeEvent" msprop:Generator_RowEvHandlerName="UomListRowChangeEventHandler" msprop:Generator_TableClassName="UomListDataTable" msprop:Generator_TableVarName="tableUomList" msprop:Generator_RowDeletingName="UomListRowDeleting" msprop:Generator_TablePropName="UomList">
<xs:complexType>
<xs:sequence>
<xs:element name="SetID" msprop:Generator_UserColumnName="SetID" msprop:Generator_ColumnPropNameInRow="SetID" msprop:Generator_ColumnVarNameInTable="columnSetID" msprop:Generator_ColumnPropNameInTable="SetIDColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Name" msprop:Generator_UserColumnName="Name" msprop:Generator_ColumnPropNameInRow="Name" msprop:Generator_ColumnVarNameInTable="columnName" msprop:Generator_ColumnPropNameInTable="NameColumn">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="31" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Abbr" msprop:Generator_UserColumnName="Abbr" msprop:Generator_ColumnPropNameInRow="Abbr" msprop:Generator_ColumnVarNameInTable="columnAbbr" msprop:Generator_ColumnPropNameInTable="AbbrColumn" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="31" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Qty" msprop:Generator_UserColumnName="Qty" msprop:Generator_ColumnPropNameInRow="Qty" msprop:Generator_ColumnVarNameInTable="columnQty" msprop:Generator_ColumnPropNameInTable="QtyColumn" type="xs:double" minOccurs="0" />
<xs:element name="IsBase" msprop:Generator_UserColumnName="IsBase" msprop:Generator_ColumnPropNameInRow="IsBase" msprop:Generator_ColumnVarNameInTable="columnIsBase" msprop:Generator_ColumnPropNameInTable="IsBaseColumn" type="xs:boolean" minOccurs="0" />
<xs:element name="ListDisplay" msdata:ReadOnly="true" msdata:Expression="IIF(SetID = '', Name, Name + ' ' + Qty)" msprop:Generator_UserColumnName="ListDisplay" msprop:Generator_ColumnPropNameInRow="ListDisplay" msprop:Generator_ColumnVarNameInTable="columnListDisplay" msprop:Generator_ColumnPropNameInTable="ListDisplayColumn" type="xs:string" minOccurs="0" />
<xs:element name="SelDisplay" msdata:ReadOnly="true" msdata:Expression="IIF(SetID = '', Qty, Abbr + '(' + Qty + ')')" msprop:Generator_UserColumnName="SelDisplay" msprop:Generator_ColumnPropNameInRow="SelDisplay" msprop:Generator_ColumnVarNameInTable="columnSelDisplay" msprop:Generator_ColumnPropNameInTable="SelDisplayColumn" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:unique name="UomKey1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:UomList" />
<xs:field xpath="mstns:SetID" />
<xs:field xpath="mstns:Name" />
</xs:unique>
Where is the mismatch in number of parameters?

Reviewing the XML it seems the Insert command seems to have 4 question marks and 5 parameters.
<InsertCommand>
<DbCommand CommandType="Text" ModifiedByUser="true">
<CommandText>INSERT INTO UomList (SetID, Name, Abbr, Qty, IsBase) VALUES (?, ?, ?, ?)
</CommandText>
The Error referencing "Update" is probably about TableAdapter.Update not necessarily the Update command. The TableAdapter.Update is calling the Insert, Update, and Delete commands as needed depending on the state of the rows in the DataTable.

Related

Constructing a XML in SQL with a table column name as XML tag

I have a requirement to get the schema of a table in XML format.
Consider a table Person with columns:
ID varchar(10) Identity, Name varchar(20), Designation varchar(10)
I need the XML to be of the format
<Persons>
<Person LocalizationSetting = {today's date}>
<ID type=varchar length =10 required=true/>
<Nametype=varchar length =20 required=true/>
<Designation type=varchar length =10 required=true/>
</Person>
</Persons>
I have the following script
DECLARE #TableSchema XML
SELECT #TableSchema = (
select column_name,
data_type as [type],
CHARACTER_MAXIMUM_LENGTH AS maxLength,
case(is_nullable)
when 'YES' then 'false'
else 'true'
end as [required]
from information_schema.columns [column]
where table_name = 'Person'
for xml auto,root('Persons')
)
SELECT #TableSchema
I get the following result:
<Patients>
<column column_name="ID" type="varchar" maxLength="10" required="true" />
<column column_name="Name" type="varchar" maxLength="20" required="true" />
<column column_name="Designation" type="varchar" maxLength="10" required="true" />
</Patients>
Is it possible to have the column_name as a tag as shown in the expected result?
You should solve this ...
I have a requirement to get the schema of a table in XML format.
... with standard built-in features. The schema you provide as expected output is some self-defined structure probably... Check this out:
CREATE TABLE Person (ID VARCHAR(10) NOT NULL
,NameType VARCHAR(20) NOT NULL
,Designation VARCHAR(10) NOT NULL);
INSERT INTO Person VALUES('SomeID','SomeType','SomeDes');
SELECT * FROM Person FOR XML AUTO,XMLDATA;
--XMLDATA returns this schema
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="Person" content="empty" model="closed">
<AttributeType name="ID" dt:type="string" />
<AttributeType name="NameType" dt:type="string" />
<AttributeType name="Designation" dt:type="string" />
<attribute type="ID" />
<attribute type="NameType" />
<attribute type="Designation" />
</ElementType>
</Schema>
--The next possibility
SELECT * FROM Person FOR XML AUTO,XMLSCHEMA;
--XMLSCHEMA returns this schema
<xsd:schema targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" elementFormDefault="qualified">
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" />
<xsd:element name="Person">
<xsd:complexType>
<xsd:attribute name="ID" use="required">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth">
<xsd:maxLength value="10" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="NameType" use="required">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth">
<xsd:maxLength value="20" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Designation" use="required">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth">
<xsd:maxLength value="10" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>
If you really have to fullfill the expected format you are having the problem, that native queries do not support dynamic column names. As a workaround you might use dynamically created SQL to be run with EXEC or this approach, which is using a very ugly hack on string level (something one rather should avoid with XML!) at the end:
WITH AlmostCorrect AS
(
SELECT
(
SELECT GETDATE() AS [#LocalizationSetting]
,(
SELECT COLUMN_NAME AS [#name]
,DATA_TYPE AS [#type]
,CHARACTER_MAXIMUM_LENGTH AS [#length]
,CASE IS_NULLABLE
WHEN 'YES' THEN 'false'
ELSE 'true'
END AS [#required]
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Person'
FOR XML PATH('row'),TYPE
) AS [*]
FOR XML PATH('Person'),ROOT('Persons'),TYPE
) AS TheXML
)
SELECT CAST(REPLACE(REPLACE(CAST(TheXML AS NVARCHAR(MAX)),'<row name="','<'),'" type',' type') AS XML)
FROM AlmostCorrect
The result
<Persons>
<Person LocalizationSetting="2017-04-18T11:05:30.047">
<ID type="varchar" length="10" required="true" />
<NameType type="varchar" length="20" required="true" />
<Designation type="varchar" length="10" required="true" />
</Person>
</Persons>

Is there a standard XML format to add metadata to a generic dataset?

I need to save a generic dataset generated from SQL query result as XML. I'd like do add metadata to my resultset in order to make it reversible so anyone can create a DB table starting from the XML and load the data.
I was wondering if there is a standard XML format that can address this issue.
You did not mention your RDBMS. For SQL Server you might use FOR XML RAW together with XMLDATA or XMLSCHEMA:
DECLARE #Dummy TABLE(ID INT IDENTITY,SomeText VARCHAR(100) NOT NULL, SomeInt INT);
INSERT INTO #Dummy VALUES('row 1',1),('row 2',2);
Example XMLDATA
SELECT * FROM #Dummy FOR XML RAW,XMLDATA
<Schema name="Schema2" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="row" content="empty" model="closed">
<AttributeType name="ID" dt:type="i4" />
<AttributeType name="SomeText" dt:type="string" />
<AttributeType name="SomeInt" dt:type="i4" />
<attribute type="ID" />
<attribute type="SomeText" />
<attribute type="SomeInt" />
</ElementType>
</Schema>
<row xmlns="x-schema:#Schema2" ID="1" SomeText="row 1" SomeInt="1" />
<row xmlns="x-schema:#Schema2" ID="2" SomeText="row 2" SomeInt="2" />
Example XMLSCHEMA (more details)
SELECT * FROM #Dummy FOR XML RAW,XMLSCHEMA
<xsd:schema targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" elementFormDefault="qualified">
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" />
<xsd:element name="row">
<xsd:complexType>
<xsd:attribute name="ID" type="sqltypes:int" use="required" />
<xsd:attribute name="SomeText" use="required">
<xsd:simpleType>
<xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth">
<xsd:maxLength value="100" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="SomeInt" type="sqltypes:int" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
<row xmlns="urn:schemas-microsoft-com:sql:SqlRowSet2" ID="1" SomeText="row 1" SomeInt="1" />
<row xmlns="urn:schemas-microsoft-com:sql:SqlRowSet2" ID="2" SomeText="row 2" SomeInt="2" />
Standard-Schema .Net
Following jdweng's comment this is an approach with C#:
var ds = new System.Data.DataSet("SomeName");
ds.Tables.Add("SomeTable");
ds.Tables.Add("OneMoreTable");
var t1 = ds.Tables["SomeTable"];
t1.Columns.Add("SomeInt", typeof(int));
t1.Columns.Add("SomeString", typeof(string));
var t2 = ds.Tables["OneMoreTable"];
t2.Columns.Add("SomeInt", typeof(int));
t2.Columns.Add("SomeDate", typeof(DateTime));
t1.Rows.Add(new object[] { 1, "test 1" });
t1.Rows.Add(new object[] { 2, "test 2" });
t1.Rows.Add(new object[] { 3, "test 3" });
t2.Rows.Add(new object[] { 1, DateTime.Now });
ds.WriteXml(#"c:\SomePath\test.dataset", XmlWriteMode.WriteSchema);
This is the written content (embedded schema and data)
<?xml version="1.0" standalone="yes"?>
<SomeName>
<xs:schema id="SomeName" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="SomeName" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="SomeTable">
<xs:complexType>
<xs:sequence>
<xs:element name="SomeInt" type="xs:int" minOccurs="0" />
<xs:element name="SomeString" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="OneMoreTable">
<xs:complexType>
<xs:sequence>
<xs:element name="SomeInt" type="xs:int" minOccurs="0" />
<xs:element name="SomeDate" type="xs:dateTime" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<SomeTable>
<SomeInt>1</SomeInt>
<SomeString>test 1</SomeString>
</SomeTable>
<SomeTable>
<SomeInt>2</SomeInt>
<SomeString>test 2</SomeString>
</SomeTable>
<SomeTable>
<SomeInt>3</SomeInt>
<SomeString>test 3</SomeString>
</SomeTable>
<OneMoreTable>
<SomeInt>1</SomeInt>
<SomeDate>2017-02-02T10:23:39.2277162+01:00</SomeDate>
</OneMoreTable>
</SomeName>

SQLXMLBulkLoad query about table relationships

I have created the following Schema:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema id="InventorAssembly"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema"
>
<xsd:annotation>
<xsd:appinfo>
<sql:relationship name="InventorDocuments"
parent="Customer.Projects"
parent-key="Customer.ProjectID"
child="Projects.Documents"
child-key="DocumentID"
/>
<sql:relationship name="Properties"
parent="InventorDocuments"
parent-key="DocumentID"
child="InventorDocuments.Properties"
child-key="DocumentID"
/>
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="root" type="InventorDocumentType" sql:relationship="InventorDocuments" />
<xsd:complexType name="ReferencedDocumentsList">
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="document" type="InventorDocumentType" minOccurs="0" maxOccurs="unbounded"/>
<!--<xsd:element name="assembly" type="InventorAssemblyType" minOccurs="0" maxOccurs="unbounded"/>-->
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="InventorDocumentType">
<xsd:sequence>
<!-- added the following to see if we can nest the resultant XML under the properties and components headings. -->
<xsd:element name="Properties" sql:is-constant="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="property"
type="InventorPropertyType"
minOccurs="0"
maxOccurs="unbounded"
sql:relationship="Properties"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ReferencedDocuments" type="ReferencedDocumentsList" sql:is-constant="1" />
</xsd:sequence>
<xsd:attribute type="xsd:string" name="ID" use="required" sql:field="DocumentID"/>
<xsd:attribute type="xsd:string" name="DocumentType" use="required" sql:field="DocumentType"/>
<xsd:attribute type="xsd:string" name="Filename" use="required" sql:field="FileName"/>
<xsd:attribute type="xsd:string" name="ReferencingDocument" use="optional" sql:field="ReferencingDocument"/>
<xsd:attribute type="xsd:string" name="ParameterCount" use="optional" sql:field="ParameterCount"/>
<xsd:attribute type="xsd:string" name="FeatureCount" use="optional" sql:field="FeatureCount"/>
<xsd:attribute type="xsd:string" name="ConstraintCount" use="optional" sql:field="ConstraintCount"/>
<xsd:attribute type="xsd:string" name="OccurrenceCount" use="optional" sql:field="OccurrenceCount"/>
</xsd:complexType>
<xsd:complexType name="InventorPropertyType">
<xsd:attribute type="xsd:string" name="ParentDocumentID" sql:field="DocumentID"/>
<xsd:attribute type="xsd:string" name="Name" sql:field="PropertyName"/>
<xsd:attribute type="xsd:string" name="Value" sql:field="PropertyValue"/>
<xsd:attribute type="xsd:string" name="Type" sql:field="PropertyType"/>
<xsd:attribute type="xsd:integer" name="PropertyID" sql:field="PropertyID"/>
</xsd:complexType>
</xsd:schema>
Which lets me create this kind of structured XML file:
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ID="1" DocumentType="kAssemblyDocumentObject" Filename="C:\GDR518.iam" ReferencingDocument="Top Level Assembly" ParameterCount="63" FeatureCount="0" ConstraintCount="38" OccurrenceCount="276">
<Properties>
<property ParentDocumentID="1" Name="Description" Value="" PropertyID="ac262fc9-edaf-4570-9b98-42fcb8e1cee9" />
<property ParentDocumentID="1" Name="Part Number" Value="GDR518" Type="String" PropertyID="7b0a8ec2-0b69-40bc-8ae5-d63304ca9378" />
</Properties>
<ReferencedDocuments>
<document ID="4" DocumentType="kAssemblyDocumentObject" Filename="C:\WLD-HF-004.iam" ReferencingDocument="C:\GDR518.iam" ParameterCount="0" FeatureCount="0" ConstraintCount="0" OccurrenceCount="0">
<Properties>
<property ParentDocumentID="4" Name="Description" Value="" PropertyID="846183dd-cc3f-4e24-8e86-dc785fbbab28" />
</Properties>
<ReferencedDocuments />
</document>
<document ID="12" DocumentType="kAssemblyDocumentObject" Filename="C:\GDR520.iam" ReferencingDocument="C:\GDR518.iam" ParameterCount="59" FeatureCount="0" ConstraintCount="42" OccurrenceCount="146">
<Properties>
<property ParentDocumentID="12" Name="Description" Value="" PropertyID="7f6c2de8-dcb6-471c-aa90-8d69b02e61f1" />
</Properties>
<ReferencedDocuments>
<document ID="13" DocumentType="kAssemblyDocumentObject" Filename="C:\WLD-HF-009.iam" ReferencingDocument="C:\GDR520.iam" ParameterCount="0" FeatureCount="0" ConstraintCount="0" OccurrenceCount="0">
<Properties>
<property ParentDocumentID="13" Name="Description" Value="" PropertyID="436ba462-6d54-433c-a435-197bdd4089d8" />
</Properties>
<ReferencedDocuments />
</document>
<Properties>
<property ParentDocumentID="18" Name="Description" Value="" PropertyID="5ced04aa-ec51-4060-a8eb-d23905e694ed" />
</Properties>
</document>
</ReferencedDocuments>
</document>
</ReferencedDocuments>
</root>
which all works just fine, but I am getting the following error when I attempt to use SQLXMLBulkLoad.Execute to pull the XML data above into my empty database:
Schema: the parent/child table of the relationship on 'property' does
not match.
I have tried every variation I can think of to get this working but to no avail.
Can anyone offer any pointers?
Thanks in advance,
Alex.

Magento API adding a new complex type to catalogProductCreateEntity (extra attributes not being passed)

I am trying to extend magento to pass configurable products. I want to do do so by extending catalogProductCreateEntity . What I did was created my own module and extended the catalog modules wsdl by adding the following in the <types> tag. like so...
<complexType name="catalogProductCreateEntity">
<all>
<element name="categories" type="typens:ArrayOfString" minOccurs="0" />
<element name="websites" type="typens:ArrayOfString" minOccurs="0" />
<element name="associated" type="typens:ArrayOfString" minOccurs="0" />
<element name="super_attributes" type="typens:catalogProductLinkEntityArray" minOccurs="0" />
<element name="name" type="xsd:string" minOccurs="0" />
<element name="description" type="xsd:string" minOccurs="0" />
<element name="short_description" type="xsd:string" minOccurs="0" />
<element name="weight" type="xsd:string" minOccurs="0" />
<element name="status" type="xsd:string" minOccurs="0" />
<element name="url_key" type="xsd:string" minOccurs="0" />
<element name="url_path" type="xsd:string" minOccurs="0" />
<element name="visibility" type="xsd:string" minOccurs="0" />
<element name="category_ids" type="typens:ArrayOfString" minOccurs="0" />
<element name="website_ids" type="typens:ArrayOfString" minOccurs="0" />
<element name="has_options" type="xsd:string" minOccurs="0" />
<element name="gift_message_available" type="xsd:string" minOccurs="0" />
<element name="price" type="xsd:string" minOccurs="0" />
<element name="special_price" type="xsd:string" minOccurs="0" />
<element name="special_from_date" type="xsd:string" minOccurs="0" />
<element name="special_to_date" type="xsd:string" minOccurs="0" />
<element name="tax_class_id" type="xsd:string" minOccurs="0" />
<element name="tier_price" type="typens:ArrayOfString" minOccurs="0" />
<element name="meta_title" type="xsd:string" minOccurs="0" />
<element name="meta_keyword" type="xsd:string" minOccurs="0" />
<element name="meta_description" type="xsd:string" minOccurs="0" />
<element name="custom_design" type="xsd:string" minOccurs="0" />
<element name="custom_layout_update" type="xsd:string" minOccurs="0" />
<element name="options_container" type="xsd:string" minOccurs="0" />
<element name="additional_attributes" type="typens:associativeArray" minOccurs="0" />
</all>
</complexType>
<complexType name="catalogProductSuperAttributeEntity">
<all>
<element name="attribute_id" type="xsd:string" minOccurs="0"/>
<element name="product_super_attribute_id" type="xsd:string" minOccurs="0"/>
<element name="product_id" type="xsd:string" minOccurs="0"/>
<element name="position" type="xsd:string" minOccurs="0"/>
<element name="label" type="xsd:string" minOccurs="0"/>
<element name="attribute_code" type="xsd:string" minOccurs="0"/>
<element name="use_default" type="xsd:string" minOccurs="0"/>
<element name="prices" type="xsd:string" minOccurs="0"/>
</all>
</complexType>
<complexType name="catalogProductSuperAttributeEntityArray">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="typens:catalogProductSuperAttributeEntity[]"/>
</restriction>
</complexContent>
</complexType>
I created a new element within catalogProductCreateEntity called super attribute. Its type is catalogProductSuperAttributeEntityArray which is an array of catalogProductSuperAttributeEntity which i also both defined above. When I do a call to the soap server, I do it like so...
foreach($prodInfo->super_attributes as $super_att) {
$sProdInfo['super_attributes'][] = array(
'attribute_id'=>$super_att->attribute_id,
'product_super_attribute_id'=>$super_att->product_super_attribute_id,
'product_id'=>$super_att->product_id,
'position'=>$super_att->position,
'label'=>$super_att->label,
'attribute_code'=>$super_att->attribute_code,
'use_default'=>$super_att->use_default,
'prices'=>12
);
}
All the elements are populated. it looks like this...
[super_attributes] => Array
(
[0] => Array
(
[attribute_id] => 159
[product_super_attribute_id] => 207
[product_id] => 4659
[position] => 0
[label] => Shirt Size
[attribute_code] => shirt_size
[use_default] => 0
[prices] => 12
)
[1] => Array
(
[attribute_id] => 70
[product_super_attribute_id] => 208
[product_id] => 4659
[position] => 0
[label] => Manufacturer
[attribute_code] => manufacturer
[use_default] => 0
[prices] => 12
)
)
Now, I've also extended the Mage_Catalog_Model_Product_Api_V2 class to handle this new attribute. my problem is when I step through the code, magento only recieves 2 attributes within the array.
product_id
position
All other attributes are ignored. I've also empty the soap cache on the server and client side yet nothing seems to change.
Figured it out...
<element name="super_attributes" type="typens:catalogProductLinkEntityArray" minOccurs="0" />
should be my newly created typens...
<element name="super_attributes" type="typens:catalogProductSuperAttributeEntityArray" minOccurs="0" />
within the complex type catalogProductCreateEntity

Extending Magento's API Soap V2 (is not a valid method for this service)

I am trying to create a custom module that extends magento V2 soap calls. Most of my sources came from this post
How to setup custom api for Magento with SOAP V2?
This is the steps I've done to try to get it to work so far.
/app/etc/modules/Namespace_ImportExport.xml
<?xml version="1.0"?>
<config>
<modules>
<Namespace_ImportExport>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Core />
</depends>
</Namespace_ImportExport>
</modules>
</config>
/app/code/local/Namespace/ImportExport/etc/api.xml
<?xml version="1.0"?>
<config>
<api>
<resources>
<importexport>
<model>namespace_importexport/api</model>
<title>api test</title>
<methods>
<foo translate="title" module="importexport">
<title>Foo Test</title>
<method>foo</method>
</foo>
</methods>
</importexport>
</resources>
<v2>
<resources_function_prefix>
<importexport>importexport</importexport>
</resources_function_prefix>
</v2>
</api>
</config>
/app/code/local/Namespace/ImportExport/etc/config.xml
<config>
<modules>
<Namespace_ImportExport>
<version>0.0.1</version>
</Namespace_ImportExport>
</modules>
<global>
<models>
<importexport><class>Namespace_ImportExport_Model</class></importexport>
</models>
<models>
<catalog>
<rewrite>
<product_api_v2>Namespace_ImportExport_Model_Product_Api_V2</product_api_v2>
</rewrite>
</catalog>
</models>
</global>
</config>
/app/code/local/Namespace/ImportExport/etc/wsdl.xml
Here I over wrote some existing modules declarations but you will find my custom module declarations at the bottom
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"
name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/" />
<complexType name="catalogProductCreateEntity">
<all>
<element name="categories" type="typens:ArrayOfString" minOccurs="0" />
<element name="websites" type="typens:ArrayOfString" minOccurs="0" />
<element name="associated" type="typens:ArrayOfString" minOccurs="0" />
<element name="name" type="xsd:string" minOccurs="0" />
<element name="description" type="xsd:string" minOccurs="0" />
<element name="short_description" type="xsd:string" minOccurs="0" />
<element name="weight" type="xsd:string" minOccurs="0" />
<element name="status" type="xsd:string" minOccurs="0" />
<element name="url_key" type="xsd:string" minOccurs="0" />
<element name="url_path" type="xsd:string" minOccurs="0" />
<element name="visibility" type="xsd:string" minOccurs="0" />
<element name="category_ids" type="typens:ArrayOfString" minOccurs="0" />
<element name="website_ids" type="typens:ArrayOfString" minOccurs="0" />
<element name="has_options" type="xsd:string" minOccurs="0" />
<element name="gift_message_available" type="xsd:string" minOccurs="0" />
<element name="price" type="xsd:string" minOccurs="0" />
<element name="special_price" type="xsd:string" minOccurs="0" />
<element name="special_from_date" type="xsd:string" minOccurs="0" />
<element name="special_to_date" type="xsd:string" minOccurs="0" />
<element name="tax_class_id" type="xsd:string" minOccurs="0" />
<element name="tier_price" type="typens:ArrayOfString" minOccurs="0" />
<element name="meta_title" type="xsd:string" minOccurs="0" />
<element name="meta_keyword" type="xsd:string" minOccurs="0" />
<element name="meta_description" type="xsd:string" minOccurs="0" />
<element name="custom_design" type="xsd:string" minOccurs="0" />
<element name="custom_layout_update" type="xsd:string" minOccurs="0" />
<element name="options_container" type="xsd:string" minOccurs="0" />
<element name="additional_attributes" type="typens:associativeArray" minOccurs="0" />
</all>
</complexType>
<complexType name="catalogProductReturnEntity">
<all>
<element name="product_id" type="xsd:string" minOccurs="0" />
<element name="sku" type="xsd:string" minOccurs="0" />
<element name="set" type="xsd:string" minOccurs="0" />
<element name="type" type="xsd:string" minOccurs="0" />
<element name="categories" type="typens:ArrayOfString" minOccurs="0" />
<element name="websites" type="typens:ArrayOfString" minOccurs="0" />
<element name="associated" type="typens:ArrayOfString" minOccurs="0" />
<element name="created_at" type="xsd:string" minOccurs="0" />
<element name="updated_at" type="xsd:string" minOccurs="0" />
<element name="type_id" type="xsd:string" minOccurs="0" />
<element name="name" type="xsd:string" minOccurs="0" />
<element name="description" type="xsd:string" minOccurs="0" />
<element name="short_description" type="xsd:string" minOccurs="0" />
<element name="weight" type="xsd:string" minOccurs="0" />
<element name="status" type="xsd:string" minOccurs="0" />
<element name="url_key" type="xsd:string" minOccurs="0" />
<element name="url_path" type="xsd:string" minOccurs="0" />
<element name="visibility" type="xsd:string" minOccurs="0" />
<element name="category_ids" type="typens:ArrayOfString" minOccurs="0" />
<element name="website_ids" type="typens:ArrayOfString" minOccurs="0" />
<element name="has_options" type="xsd:string" minOccurs="0" />
<element name="gift_message_available" type="xsd:string" minOccurs="0" />
<element name="price" type="xsd:string" minOccurs="0" />
<element name="special_price" type="xsd:string" minOccurs="0" />
<element name="special_from_date" type="xsd:string" minOccurs="0" />
<element name="special_to_date" type="xsd:string" minOccurs="0" />
<element name="tax_class_id" type="xsd:string" minOccurs="0" />
<element name="tier_price" type="typens:ArrayOfString" minOccurs="0" />
<element name="meta_title" type="xsd:string" minOccurs="0" />
<element name="meta_keyword" type="xsd:string" minOccurs="0" />
<element name="meta_description" type="xsd:string" minOccurs="0" />
<element name="custom_design" type="xsd:string" minOccurs="0" />
<element name="custom_layout_update" type="xsd:string" minOccurs="0" />
<element name="options_container" type="xsd:string" minOccurs="0" />
<element name="additional_attributes" type="typens:associativeArray" minOccurs="0" />
</all>
</complexType>
</schema>
</types>
<message name="importexportFooRequest">
<part name="sessionId" type="xsd:string" />
</message>
<message name="importexportFooResponse">
<part name="result" type="typens:boolean" />
</message>
<portType name="{{var wsdl.handler}}PortType">
<operation name="importexportFoo">
<documentation>ImportExport Foo</documentation>
<input message="typens:importexportFooRequest" />
<output message="typens:importexportFooResponse" />
</operation>
</portType>
<binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="importexportFoo">
<soap:operation soapAction="urn:{{var wsdl.handler}}Action" />
<input>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body namespace="urn:{{var wsdl.name}}" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
</definitions>
/app/code/local/Namespace/ImportExport/Model/Api.php
<?php
class Namespace_ImportExport_Model_Api extends Mage_Api_Model_Resource_Abstract
{
/**
* Returns version of the installed magento
* #return String
*/
public function foo() {
return true;
}
}
?>
/app/code/local/Namespace/ImportExport/Model/API/V2.php
<?php
class Namespace_ImportExport_Model_Api_V2 extends Namespace_ImportExport_Model_Api
{
public function foo() {
return true;
}
}
?>
And I make the call, like so...
$fclient = new SoapClient($config['from']['soap_url']);
$fsession = $fclient->login($config['from']['username'], $config['from']['api_key']);
var_dump($fclient->importexportFoo($fsession));
This to my knowledge is the bare necessities to get my custom api V2 module working. So what could I possibly be doing wrong ?
I am getting this for an error
Function ("importexportFoo") is not a valid method for this service
I've just had this kind of issue.
Check the value of $config['from']['soap_url'] when making the API call. If the value looks like http://example.com/api/soap?wsdlthen you are still making a call to V1. Update it to look like this http://example.com/api/v2_soap/?wsdl.