public void __mysqli_query(
            string sql,
            Action<string> __y,
            Action<string, string> yield_field,
            Action<XElement> yield_resultset
            )
        {
            __y.ToConsoleOut();

            Action<string> y = x => Console.WriteLine("__mysqli_query" + x);

            Console.WriteLine("hey!");

            var h = new History();


            h.Insert(
                new HistoryQueries.Insert
                {
                    query = sql,
                    context = "__mysqli_query"
                }
            );

            var m = new mysqli(
                "localhost",
                "root",
                ""
            );

            var flag = m.multi_query(sql);

            var sqlindex = 0;

            {
                var message = new
                {
                    sqlindex,
                    m.errno,
                    m.error,
                    m.insert_id,
                };
                y(message.ToString());
            }

            while (flag)
            {

                var rr = m.store_result();

                //Native.Dump(rr);

                (rr as mysqli_result).With(
                    result =>
                    {
                        #region mysqli_result
                        //var f0 = result.fetch_field_direct(0);
                        //var d0 = Native.DumpToString(f0);

                        var message = new
                        {
                            sqlindex,

                            m.errno,
                            m.error,

                            result.field_count,
                            result.num_rows,

                            m.insert_id,

                            //, d0 
                        };
                        y(message.ToString());

                        //Console.WriteLine("before fields");

                        var resultset = new XElement("table");

                        var resultset_th = new XElement("th");

                        resultset.Add(resultset_th);


                        var fields = Enumerable.Range(0, result.field_count).Select(
                            // jsc can we have implicit delegates to natives?
                            x => result.fetch_field_direct(x)
                        ).Select(
                            (f, i) =>
                            {
                                var n = new { f.name, i, f.type };

                                //Console.WriteLine("field: " + n);
                                resultset_th.Add(
                                    new XElement("td",
                                        new XAttribute("title", "type " + f.type),
                                         f.name
                                    )
                                );

                                yield_field(f.name, "" + f.type);

                                return n;
                            }
                        ).ToArray();

                        //Console.WriteLine("after fields");


                        for (int row = 0; row < result.num_rows; row++)
                        {
                            result.data_seek(row);

                            var resultset_row = new XElement("tr");

                            resultset_row.Add(
                                new XAttribute("title", "row " + row)
                            );

                            var row_data = result.fetch_row();

                            //Console.WriteLine("row: " + row);

                            // broken?
                            //fields.WithEach(

                            for (int i = 0; i < fields.Length; i++)
                            {
                                fields[i].With(
                                               f =>
                                               {
                                                   //Console.WriteLine("field: " + f.name);

                                                   var data = row_data[f.i];

                                                   resultset_row.Add(
                                                       new XElement("td",
                                                           "" + data
                                                       )
                                                   );

                                               }

                                           );
                            }

                            //resultset_row.Add(
                            //    new XElement("dump", Native.DumpToString(row_data))
                            //);


                            resultset.Add(resultset_row);
                        }


                        yield_resultset(resultset);

                        result.close();
                        #endregion


                    }
                );

                //  mysqli::next_result(): There is no next result set. Please, call mysqli_more_results()/mysqli::more_results() to check whether to call this function/method

                flag = m.more_results();

                if (flag)
                {
                    flag = m.next_result();

                    {
                        var message = new
                        {
                            sqlindex,
                            m.errno,
                            m.error,
                            m.insert_id,
                        };
                        y(message.ToString());
                    }
                }

                sqlindex++;
            }

            m.close();
        }