Ejemplo n.º 1
0
        public void columnDefinition(bool maxWidth, bool hasHeaderRow, bool minWidth, bool nullable, String expected)
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(ECONOMIC_FREEDOM);
                p.parseTab(hasHeader: hasHeaderRow);
                p.columnDefinition(null, maxWidth, hasHeaderRow, minWidth, nullable, swapRowsAndColumns: false);
                actual = p.processToString();
            }
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public void tabInOutImplicit()
        {
            String actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(ECONOMIC_FREEDOM);
                p.parseTab();
                actual = p.processToString();
            }

            Assert.Equal(ECONOMIC_FREEDOM, actual);
        }
Ejemplo n.º 3
0
        public void tabHasHeader()
        {
            const String source = "headerA\theaderB\nvalueA1\tvalueB1";
            String       actual;

            using (Pnyx p = new Pnyx())
            {
                p.readString(source);
                p.parseTab(hasHeader: true);
                p.sed("[AB]", "X");
                actual = p.processToString();
            }

            const String expected = "headerA\theaderB\nvalueX1\tvalueX1";

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 4
0
        public static int main()
        {
            using (Pnyx p = new Pnyx())
            {
                p.read("nya.csv");
                p.parseCsv();
                p.rowTransformerFunc(row =>
                {
                    var fullName = row[1];

                    var name = pnyx.net.util.NameUtil.parseFullName(fullName);
                    if (name == null)
                    {
                        return(null);
                    }

                    return(pnyx.net.util.RowUtil.replaceColumn(row, 2, name.firstName, name.lastName));
                });
                p.selectColumns(2, 3, 5);
                p.columnTransformer(3, new pnyx.net.impl.DateTransform {
                    formatSource = "M-d-yyyy", formatDestination = "yyyy-M-d"
                });
                p.lineTransformerFunc(x => pnyx.net.util.TextUtil.encodeSqlValue(x));
                p.print("insert into tmp_name values($1,$2,$3);");
                p.write("nya.sql");
            }

            using (Pnyx p = new Pnyx())
            {
                p.read(@"C:\dev\asclepius\prod_import\alt.txt");
                p.parseTab();
                p.rowTransformerFunc(row =>
                {
                    var fullName = row[0];

                    var name = pnyx.net.util.NameUtil.parseFullName(fullName);
                    if (name == null)
                    {
                        return(null);
                    }

                    return(pnyx.net.util.RowUtil.replaceColumn(row, 1, name.firstName, name.middleName, name.lastName));
                });
                p.lineTransformerFunc(x => pnyx.net.util.TextUtil.encodeSqlValue(x));
                p.sortRow(new[] { 1, 3 });
                p.writeCsv(@"C:\dev\asclepius\prod_import\alt.csv");
            }

            using (Pnyx p = new Pnyx())
            {
                p.read(@"C:\dev\asclepius\prod_import\alt_names.csv");
                p.parseCsv();
                p.columnTransformer(3, new DateTransform {
                    formatSource = DateUtil.FORMAT_MDYYYY, formatDestination = DateUtil.FORMAT_ISO_8601_DATE
                });
                p.rowTransformerFunc(row =>
                {
                    for (int i = 0; i < row.Count; i++)
                    {
                        row[i] = TextUtil.encodeSqlValue(row[i]);
                    }
                    return(row);
                });
                p.print("insert into to_import value($1,$2,$3);");
                p.write(@"C:\dev\asclepius\prod_import\names.sql");
            }

            return(0);
        }