Example #1
0
 /// <summary>
 /// 常量转换字符串
 /// </summary>
 /// <param name="sqlStream">SQL字符流</param>
 /// <param name="value">常量</param>
 private void convertConstant(charStream sqlStream, DateTime value)
 {
     sqlStream.PrepLength(fastCSharp.date.SqlMillisecondSize + 2);
     sqlStream.UnsafeWrite('\'');
     fastCSharp.date.ToSqlMillisecond((DateTime)value, sqlStream);
     sqlStream.UnsafeWrite('\'');
 }
Example #2
0
 /// <summary>
 /// 字符串
 /// </summary>
 /// <param name="value">字符串</param>
 /// <param name="jsonStream">JSON输出流</param>
 public static void ToString(string value, charStream jsonStream)
 {
     jsonStream.PrepLength(value.Length + 2);
     jsonStream.UnsafeWrite(Quote);
     jsonStream.UnsafeWrite(value);
     jsonStream.UnsafeWrite(Quote);
 }
Example #3
0
 /// <summary>
 /// 时间转字符串
 /// </summary>
 /// <param name="time">时间</param>
 /// <param name="jsonStream">JSON输出流</param>
 public static unsafe void ToStringNotNull(DateTime time, charStream jsonStream)
 {
     jsonStream.PrepLength(DateStart.Length + (19 + 1));
     jsonStream.UnsafeSimpleWrite(DateStart);
     toString((long)(((time.Kind == DateTimeKind.Utc ? time.Ticks + pub.LocalTimeTicks : time.Ticks) - JavascriptLocalMinTimeTicks) / date.MillisecondTicks), jsonStream);
     jsonStream.UnsafeWrite(DateEnd);
 }
Example #4
0
        /// <summary>
        /// 查询条件
        /// </summary>
        /// <param name="sqlTable">数据库表格操作工具</param>
        /// <param name="sqlStream">SQL表达式流</param>
        /// <param name="expression">查询条件表达式</param>
        /// <param name="isCreatedIndex">是否已经创建查询索引</param>
        /// <returns></returns>
        internal static unsafe bool WriteWhere(fastCSharp.emit.sqlTable.sqlToolBase sqlTable, charStream sqlStream, Expression <Func <valueType, bool> > expression, ref bool isCreatedIndex)
        {
            if (expression == null)
            {
                return(true);
            }
            sqlStream.PrepLength(6);
            sqlStream.UnsafeAddLength(6);
            int  length                    = sqlStream.Length;
            bool logicConstantWhere        = false;
            keyValue <string, string> name = sqlTable.Client.GetWhere(expression, sqlStream, ref logicConstantWhere);

            if (length == sqlStream.Length)
            {
                sqlStream.UnsafeFreeLength(6);
                return(logicConstantWhere);
            }
            if (name.Key != null)
            {
                byte *where = (byte *)(sqlStream.Char + length);
                *(uint *)(where - sizeof(uint))     = 'e' + (' ' << 16);
                *(uint *)(where - sizeof(uint) * 2) = 'e' + ('r' << 16);
                *(uint *)(where - sizeof(uint) * 3) = 'w' + ('h' << 16);
                isCreatedIndex = true;
                sqlTable.CreateIndex(name.Key, name.Value);
            }
            return(true);
        }
Example #5
0
 /// <summary>
 /// 时间转字符串 第三方格式 /Date(xxx)/
 /// </summary>
 /// <param name="time">时间</param>
 /// <param name="jsonStream">JSON输出流</param>
 public static unsafe void ToStringOther(DateTime time, charStream jsonStream)
 {
     jsonStream.PrepLength(OtherDateStart.Length + (19 + 1 + 4));
     jsonStream.UnsafeWrite(fastCSharp.web.ajax.Quote);
     jsonStream.UnsafeSimpleWrite(OtherDateStart);
     toString((long)(((time.Kind == DateTimeKind.Utc ? time.Ticks + pub.LocalTimeTicks : time.Ticks) - JavascriptLocalMinTimeTicks) / date.MillisecondTicks), jsonStream);
     *(long *)jsonStream.CurrentChar = DateEnd + ('/' << 16) + ((long)fastCSharp.web.ajax.Quote << 32);
     jsonStream.UnsafeAddLength(3);
 }
Example #6
0
 /// <summary>
 /// 数字转换成字符串
 /// </summary>
 /// <param name="value">数字值</param>
 /// <param name="jsonStream">JSON输出流</param>
 public unsafe static void ToString(short value, charStream jsonStream)
 {
     if (value >= 0)
     {
         ToString((ushort)value, jsonStream);
     }
     else
     {
         jsonStream.PrepLength(7);
         jsonStream.UnsafeWrite('-');
         ToString((ushort)-value, jsonStream);
     }
 }
Example #7
0
 /// <summary>
 /// 数字转换成字符串
 /// </summary>
 /// <param name="value"></param>
 /// <param name="jsonStream"></param>
 private unsafe static void toString(long value, charStream jsonStream)
 {
     if (value >= 0)
     {
         toString((ulong)value, jsonStream);
     }
     else
     {
         jsonStream.PrepLength(19);
         jsonStream.UnsafeWrite('-');
         toString((ulong)-value, jsonStream);
     }
 }
Example #8
0
 /// <summary>
 /// 字符串
 /// </summary>
 /// <param name="value">字符串</param>
 /// <param name="jsonStream">JSON输出流</param>
 public static void ToString(ref subString value, charStream jsonStream)
 {
     if (value.value == null)
     {
         WriteNull(jsonStream);
     }
     else
     {
         jsonStream.PrepLength(value.Length + 2);
         jsonStream.UnsafeWrite(Quote);
         jsonStream.Write(ref value);
         jsonStream.UnsafeWrite(Quote);
     }
 }
Example #9
0
 /// <summary>
 /// 数字转换成字符串
 /// </summary>
 /// <param name="value">数字值</param>
 /// <param name="jsonStream">JSON输出流</param>
 /// <param name="isMaxToString">超出最大有效精度是否转换成字符串</param>
 public unsafe static void ToString(ulong value, charStream jsonStream, bool isMaxToString = true)
 {
     if (value <= maxValue || !isMaxToString)
     {
         toString(value, jsonStream);
     }
     else
     {
         jsonStream.PrepLength(22 + 2);
         jsonStream.UnsafeWrite(Quote);
         number.UnsafeToString(value, jsonStream);
         jsonStream.UnsafeWrite(Quote);
     }
 }
Example #10
0
 /// <summary>
 /// 格式化ajax字符串
 /// </summary>
 /// <param name="jsStream">JS字符流</param>
 /// <param name="formatStream">格式化JSON字符流</param>
 public unsafe static void UnsafeFormatJavascript(charStream jsStream, charStream formatStream)
 {
     if (jsStream.Length != 0)
     {
         char *start  = jsStream.Char;
         int   length = formatLength(jsStream);
         if (length == 0)
         {
             char *end = start + (length = jsStream.Length);
             formatStream.PrepLength(length);
             for (char *write = formatStream.CurrentChar; start != end; ++start)
             {
                 *write++ = *start == Quote ? '"' : *start;
             }
             formatStream.UnsafeAddLength(length);
         }
         else
         {
             formatStream.PrepLength(length += jsStream.Length);
             formatJavascript(start, start + jsStream.Length, formatStream.CurrentChar);
             formatStream.UnsafeAddLength(length);
         }
     }
 }
Example #11
0
        /// <summary>
        /// SQL语句字符串格式化(单引号变两个)
        /// </summary>
        /// <param name="sqlStream">SQL字符流</param>
        /// <param name="value">常量</param>
        protected virtual unsafe void convertString(charStream sqlStream, string value)
        {
            fixed(char *valueFixed = value)
            {
                int length = 0;

                for (char *start = valueFixed, end = valueFixed + value.Length; start != end; ++start)
                {
                    if (*start == '\'')
                    {
                        ++length;
                    }
                    else if (*start == '\\')
                    {
                        if ((*(start + 1) == '\r' || *(start + 1) == '\n') && (int)(end - start) >= 2)
                        {
                            length += 2;
                            ++start;
                        }
                    }
                }
                if (length == 0)
                {
                    sqlStream.PrepLength(value.Length + 2);
                    sqlStream.UnsafeWrite('\'');
                    sqlStream.WriteNotNull(value);
                    sqlStream.UnsafeWrite('\'');
                    return;
                }
                sqlStream.PrepLength((length += value.Length) + 2);
                sqlStream.UnsafeWrite('\'');
                byte *write = (byte *)sqlStream.CurrentChar;

                for (char *start = valueFixed, end = valueFixed + value.Length; start != end; ++start)
                {
                    if (*start != '\'')
                    {
                        if (*start == '\\')
                        {
                            if (*(start + 1) == '\n')
                            {
                                if ((int)(end - start) >= 2)
                                {
                                    *(long *)write = '\\' + ('\\' << 16) + ((long)'\n' << 32) + ((long)'\n' << 48);
                                    ++start;
                                    write += sizeof(long);
                                    continue;
                                }
                            }
                            else if (*(start + 1) == '\r' && (int)(end - start) >= 2)
                            {
                                *(long *)write = '\\' + ('\\' << 16) + ((long)'\n' << 32) + ((long)'\r' << 48);
                                ++start;
                                write += sizeof(long);
                                continue;
                            }
                        }
                        *(char *)write = *start;
                        write         += sizeof(char);
                    }
                    else
                    {
                        *(int *)write = ('\'' << 16) + '\'';
                        write        += sizeof(int);
                    }
                }
                sqlStream.UnsafeAddLength(length);
                sqlStream.UnsafeWrite('\'');
            }
        }