示例#1
0
        protected internal override bool OnReadNextRow(object[] values)
        {
            string[] parts;

            if (ReadNextRowParts(out parts, true))
            {
                // Now parse the parts
                int pi = 0;
                for (int i = 0; i < Columns.Count; i++)
                {
                    if (!Columns[i].IsIdentity)
                    {
                        if (parts[pi] == null && Columns[i].DataType.IsNullable)
                        {
                            values[i] = null;
                        }
                        else if (parts[pi] == null)
                        {
                            throw new ArgumentNullException();  // *** TODO
                        }
                        else if (!ColumnParsers[i](parts[pi], out values[i]))
                        {
                            throw new FormatException();    // TODO: add logic to skip exceptions
                        }

                        pi++;
                    }
                    else
                    {
                        values[i] = null;   // Identity value will be filled in by the data reader
                    }
                }

                // TODO: add logic to handle nulls

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        ///<summary>Reads a TableSchema from an XML element.</summary>
        ///<param name="xml">An XML element created by <see cref="TableSchema.ToXml"/>.</param>
        ///<param name="referencedSchemas">A set of schemas that may be referenced by the foreign keys in the schema being created.</param>
        public static TableSchema FromXml(XElement xml, IEnumerable <TableSchema> referencedSchemas)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }

            var retVal = new TableSchema(xml.Attribute("Name").Value);

            foreach (var elem in xml.Elements())
            {
                ColumnParsers[elem.Name.LocalName](retVal, elem, referencedSchemas);
            }

            var primaryKey = xml.Attribute("PrimaryKey");

            if (primaryKey != null)
            {
                retVal.PrimaryKey = retVal.Columns[primaryKey.Value];
            }

            return(retVal);
        }