コード例 #1
0
ファイル: wvdata.t.cs プロジェクト: apenwarr/versaplex
    [Test] public void nulls_test()
    {
	WvAutoCast n = WvAutoCast._null;
	object o = n;
	WVPASS(o != null);
	WVPASS(o.ToString() != null);
	WVPASSEQ((int)n, 0);
	WVPASSEQ((long)n, 0);
	WVPASSEQ((double)n, 0.0);
	
	n = new WvAutoCast("-6");
	o = n;
	WVPASS(o != null);
	WVPASSEQ(o.ToString(), "-6");
	WVPASSEQ((int)n, -6);
	WVPASSEQ((long)n, -6);
	WVPASSEQ((int)(((double)n)*10000), -60000);

	n = new WvAutoCast("-5.5555.p");
	o = n;
	WVPASS(o != null);
	WVPASSEQ(o.ToString(), "-5.5555.p");
	WVPASSEQ((int)n, -5);
	WVPASSEQ((long)n, -5);
	WVPASSEQ((int)(((double)n)*10000), -55555);
    }
コード例 #2
0
ファイル: wvdata.t.cs プロジェクト: apenwarr/versaplex
 public void bool_test()
 {
     WvAutoCast t = new WvAutoCast(true);
     WvAutoCast f = new WvAutoCast(false);
     WVPASSEQ(t.ToString(), "1");
     WVPASSEQ(f.ToString(), "0");
     WVPASSEQ((double)t, 1.0);
     WVPASSEQ((double)f, 0.0);
     WVPASSEQ((int)t, 1);
     WVPASSEQ((int)f, 0);
 }
コード例 #3
0
ファイル: vxdbschema.cs プロジェクト: apenwarr/versaplex
    // Writes straight to file, therefore without sorting
    public void WriteSchemaData(StreamWriter sw, string tablename, int seqnum, string where, 
                                Dictionary<string,string> replaces,
                                List<string> skipfields)
    {
        log.print("GetSchemaData({0},{1},{2})\n", tablename, seqnum, where);
        
        if (replaces == null)
            replaces = new Dictionary<string,string>();
        if (skipfields == null)
            skipfields = new List<string>();
            
        int[] fieldstoskip = new int[skipfields.Count];
        for (int i=0; i < skipfields.Count; i++)
            fieldstoskip[i] = -1;

        string query = "SELECT * FROM " + tablename;

        if (where != null && where.Length > 0)
            if (where.ToLower().StartsWith("select "))
                query = where;
            else
                query += " WHERE " + where;

        System.Type[] types = null;

        string colsstr;
        List<string> result = new List<string>();
        ArrayList values = new ArrayList();
        List<string> cols = new List<string>();
        List<string> allcols = new List<string>();
        WvSqlRows rows = DbiSelect(query);
        types = new System.Type[rows.columns.Count()];

        int ii = 0;
        foreach (WvColInfo col in rows.columns)
        {
            allcols.Add(col.name.ToLower());
            if (skipfields.Contains(col.name.ToLower()))
                fieldstoskip[skipfields.IndexOf(col.name.ToLower())] = ii;
            else if (skipfields.Contains(
                                 tablename.ToLower()+"."+col.name.ToLower()))
                fieldstoskip[skipfields.IndexOf(
                            tablename.ToLower()+"."+col.name.ToLower())] = ii;
            else
            {
                cols.Add(col.name);
                types[ii] = col.type;
            }
            ii++;
        }
        colsstr = "\"" + cols.join("\",\"") + "\"\n";
	sw.Write(colsstr);
        // Read the column name and type information for the query.
        foreach (WvSqlRow row in rows)
        {
            values.Clear();
            int colnum = 0;
            foreach (WvAutoCast _elem in row)
            {
                WvAutoCast elem = _elem;
                if (Array.IndexOf(fieldstoskip,colnum)>=0)
                {
                    colnum++;
                    continue;
                }
                
                if (replaces.ContainsKey(allcols[colnum]))
                    elem = new WvAutoCast(replaces[allcols[colnum]]);
                    
                if (replaces.ContainsKey(
                                    tablename.ToLower()+"."+allcols[colnum]))
                    elem = new WvAutoCast(replaces[
                                    tablename.ToLower()+"."+allcols[colnum]]);

                if (elem.IsNull)
                    values.Add(null);
                else if (types[colnum] == typeof(System.String) || 
                    types[colnum] == typeof(System.DateTime))
                {
                    string str;
                    // The default formatting is locale-dependent, and stupid.
                    if (types[colnum] == typeof(System.DateTime))
                        str = ((DateTime)elem).ToString("yyyy-MM-dd HH:mm:ss");
                    else
                        str = (string)elem;

                    values.Add(str);
                }
                else if (types[colnum] == typeof(System.Byte[]))
                {
                    string temp = System.Convert.ToBase64String(elem);
                    string tmp = "";
                    while (temp.Length > 0)
                    {
                        if (temp.Length > 75)
                        {
                            tmp += temp.Substring(0,76) + "\n";
                            temp = temp.Substring(76);
                        }
                        else
                        {
                            tmp += temp + "\n";
                            break;
                        }
                    }
                    values.Add(tmp);
                }
                else
                    values.Add((string)elem);

                colnum++;
            }
            sw.Write(WvCsv.GetCsvLine(values) + "\n");
        }
    }