Пример #1
0
        private void Escape(TextWriter sw, char[] buf, string escaping, Action <TextWriter, char> mappings)
        {
            string quoteEscape = null;
            string slashEscape = null;

            if (mappings != null)
            {
                foreach (var c in Value)
                {
                    if (c == '"')
                    {
                        quoteEscape = quoteEscape ?? PostgresTuple.BuildQuoteEscape(escaping);
                        foreach (var q in quoteEscape)
                        {
                            mappings(sw, q);
                        }
                    }
                    else if (c == '\\')
                    {
                        slashEscape = slashEscape ?? PostgresTuple.BuildSlashEscape(escaping.Length);
                        foreach (var q in slashEscape)
                        {
                            mappings(sw, q);
                        }
                    }
                    else
                    {
                        mappings(sw, c);
                    }
                }
            }
            else
            {
                for (int i = 0; i < Value.Length; i++)
                {
                    var c = Value[i];
                    if (c == '"')
                    {
                        quoteEscape = quoteEscape ?? PostgresTuple.BuildQuoteEscape(escaping);
                        sw.Write(quoteEscape);
                    }
                    else if (c == '\\')
                    {
                        slashEscape = slashEscape ?? PostgresTuple.BuildSlashEscape(escaping.Length);
                        sw.Write(slashEscape);
                    }
                    else
                    {
                        sw.Write(c);
                    }
                }
            }
        }
Пример #2
0
            public void InsertRecord(TextWriter sw, char[] buf, string escaping, Action <TextWriter, char> mappings)
            {
                string quoteEscape = null;
                string slashEscape = null;
                int    c;

                if (mappings != null)
                {
                    while ((c = Reader.Read()) != -1)
                    {
                        if (c == '"')
                        {
                            quoteEscape = quoteEscape ?? PostgresTuple.BuildQuoteEscape(escaping);
                            foreach (var q in quoteEscape)
                            {
                                mappings(sw, q);
                            }
                        }
                        else if (c == '\\')
                        {
                            slashEscape = slashEscape ?? PostgresTuple.BuildSlashEscape(escaping.Length);
                            foreach (var q in slashEscape)
                            {
                                mappings(sw, q);
                            }
                        }
                        else
                        {
                            mappings(sw, (char)c);
                        }
                    }
                }
                else
                {
                    while ((c = Reader.Read()) != -1)
                    {
                        if (c == '"')
                        {
                            quoteEscape = quoteEscape ?? PostgresTuple.BuildQuoteEscape(escaping);
                            sw.Write(quoteEscape);
                        }
                        else if (c == '\\')
                        {
                            slashEscape = slashEscape ?? PostgresTuple.BuildSlashEscape(escaping.Length);
                            sw.Write(slashEscape);
                        }
                        else
                        {
                            sw.Write((char)c);
                        }
                    }
                }
            }
Пример #3
0
            public void InsertRecord(TextWriter sw, char[] buf, string escaping, Action <TextWriter, char> mappings)
            {
                var pref = PostgresTuple.BuildSlashEscape(escaping.Length);

                if (mappings != null)
                {
                    foreach (var p in pref)
                    {
                        mappings(sw, p);
                    }
                }
                else
                {
                    sw.Write(pref);
                }
                sw.Write('x');
                BuildArray(sw);
            }
Пример #4
0
            public void InsertRecord(TextWriter sw, char[] buf, string escaping, Action <TextWriter, char> mappings)
            {
                var esc         = PostgresTuple.BuildQuoteEscape(escaping);
                var quoteEscape = new Lazy <string>(() => PostgresTuple.BuildQuoteEscape(escaping + "0"));
                var slashEscape = new Lazy <string>(() => PostgresTuple.BuildSlashEscape(escaping.Length + 1));
                var len         = Value.Count;

                if (mappings != null)
                {
                    foreach (var kv in Value)
                    {
                        len--;
                        foreach (var c in esc)
                        {
                            mappings(sw, c);
                        }
                        foreach (var c in kv.Key)
                        {
                            if (c == '"')
                            {
                                foreach (var e in quoteEscape.Value)
                                {
                                    mappings(sw, e);
                                }
                            }
                            else if (c == '\\')
                            {
                                foreach (var e in slashEscape.Value)
                                {
                                    mappings(sw, e);
                                }
                            }
                            else
                            {
                                mappings(sw, c);
                            }
                        }
                        foreach (var c in esc)
                        {
                            mappings(sw, c);
                        }
                        sw.Write("=>");
                        if (kv.Value == null)
                        {
                            sw.Write("NULL");
                        }
                        else
                        {
                            foreach (var c in esc)
                            {
                                mappings(sw, c);
                            }
                            foreach (var c in kv.Value)
                            {
                                if (c == '"')
                                {
                                    foreach (var e in quoteEscape.Value)
                                    {
                                        mappings(sw, e);
                                    }
                                }
                                else if (c == '\\')
                                {
                                    foreach (var e in slashEscape.Value)
                                    {
                                        mappings(sw, e);
                                    }
                                }
                                else
                                {
                                    mappings(sw, c);
                                }
                            }
                            foreach (var c in esc)
                            {
                                mappings(sw, c);
                            }
                        }
                        if (len > 0)
                        {
                            sw.Write(", ");
                        }
                    }
                }
                else
                {
                    foreach (var kv in Value)
                    {
                        len--;
                        sw.Write(esc);
                        foreach (var c in kv.Key)
                        {
                            if (c == '"')
                            {
                                sw.Write(quoteEscape.Value);
                            }
                            else if (c == '\\')
                            {
                                sw.Write(slashEscape.Value);
                            }
                            else
                            {
                                sw.Write(c);
                            }
                        }
                        sw.Write(esc);
                        sw.Write("=>");
                        if (kv.Value == null)
                        {
                            sw.Write("NULL");
                        }
                        else
                        {
                            sw.Write(esc);
                            foreach (var c in kv.Value)
                            {
                                if (c == '"')
                                {
                                    sw.Write(quoteEscape.Value);
                                }
                                else if (c == '\\')
                                {
                                    sw.Write(slashEscape.Value);
                                }
                                else
                                {
                                    sw.Write(c);
                                }
                            }
                            sw.Write(esc);
                        }
                        if (len > 0)
                        {
                            sw.Write(", ");
                        }
                    }
                }
            }