Ejemplo n.º 1
0
void VfkStream::Dump()
{
	puts(NFormat("Index file: %s", indexfilename));
	puts(NFormat("%d file group(s):", file_groups.GetCount()));
	for(int i = 0; i < file_groups.GetCount(); i++)
		puts(NFormat("\t[%d] = %d / %s (%n B)", i, file_groups.GetKey(i), file_groups[i],
			streams[i].IsOpen() ? streams[i].GetSize() : 0));
	puts("Tables:");
	for(int t = 0; t < tables.GetCount(); t++) {
		const Table& tbl = tables[t];
		puts(NFormat("\tTable(%d, %s (%s)) sections:\n", t, tbl.name, tbl.rawname));
		for(int s = 0; s < tbl.file_index.GetCount(); s++)
			puts(NFormat("\t\t[%d]: file index [%d], range %n .. %n, %n bytes, %n rows",
				s, tbl.file_index[s], tbl.begin_offset[s], tbl.end_offset[s],
				tbl.end_offset[s] - tbl.begin_offset[s], tbl.row_count));
/*
		for(int c = 0; c < tbl.columns.GetCount(); c++) {
			const Column& col = tbl.columns[c];
			puts(NFormat("\t\t(%d, %s): %s %~d", c, col.name, GetVTypeName(col.vtype), col.width));
		}
*/
		Data data = GetData(tbl.name);
		puts(NFormat("%d row(s):", data.GetCount()));
		for(int i = 0; i < 10 && i < data.GetCount(); i++) {
			const Vector<Value>& row = data[i];
			String out;
			for(int v = 0; v < row.GetCount(); v++)
				out << (v ? ";" : "") << StdFormat(row[v]);
			puts(out);
		}
	}
}
Ejemplo n.º 2
0
HRESULT OcxObject::RawInvoke(IRef<ITypeInfo>& typeinfo, IDispatch *dispatch, DISPID dispid, word flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *excep, unsigned *arg_err)
{
	LOGINVOKE("IDispatch::Invoke");
	if(dispid == 0) { // convert object to dispatch value
		if(!result) return E_INVALIDARG;
		result->vt = VT_DISPATCH;
		result->pdispVal = dispatch;
		if(dispatch) dispatch->AddRef();
		return S_OK;
	}
	if(!typeinfo) {
		LOG("dispid = " << FormatIntHex(dispid) << ": typeinfo = NULL");
		return E_FAIL;
	}
#if LOG_INVOKES >= 1
	BSTR names[1] = { NULL };
	unsigned count = 0;
	typeinfo->GetNames(dispid, names, 1, &count);
	String name;
	if(names[0])
		name = BSTRToString(names[0]);
	else
		name = FormatIntHex(dispid);
	switch(flags) {
	case DISPATCH_METHOD:         name << " - method"; break;
	case DISPATCH_PROPERTYGET:    name << " - propget"; break;
	case DISPATCH_PROPERTYPUT:    name << " - propput"; break;
	case DISPATCH_PROPERTYPUTREF: name << " - propputref"; break;
	}
	LOG("Member name: " << name);
#endif
	if(!typeinfo)
		return E_FAIL;
	TYPEATTR *attr;
	typeinfo->GetTypeAttr(&attr);
	LOGINVOKE("GetTypeInfo: typekind = " << (int)attr->typekind);
//	HRESULT res = typeinfo->Invoke(dispatch, dispid, flags, params, result, excep, arg_err);
	HRESULT res = DispInvoke(dispatch, ~typeinfo, dispid, flags, params, result, excep, arg_err);
	if(FAILED(res)) {
		RLOG("failure: dispid = " << (int)dispid << ", #args = " << (int)params->cArgs
			<< ", #named args = " << (int)params->cNamedArgs << ", return " << FormatIntHex(result));
		for(int i = 0; i < (int)params->cArgs; i++) {
			RLOG("arg[" << i << "] (vt = " << (int)params->rgvarg[i].vt << "): " << StdFormat(AsValue(params->rgvarg[i])));
		}
		RLOG("#funcs = " << attr->cFuncs);
		for(int i = 0; i < attr->cFuncs; i++) {
			FUNCDESC *func;
			typeinfo->GetFuncDesc(i, &func);
			RLOG("memid = " << func->memid << ", cParams " << func->cParams
			<< ", cParamsOpt = " << func->cParamsOpt << ", cScodes " << func->cScodes
			<< ", funckind = " << (int)func->funckind << ", invkind " << (int)func->invkind
			<< ", flags = " << FormatIntHex(func->wFuncFlags));

			typeinfo->ReleaseFuncDesc(func);
		}
	}
	typeinfo->ReleaseTypeAttr(attr);
	LOGINVOKE("//IDispatch::Invoke");
	return LOGRESULT(res);
}
Ejemplo n.º 3
0
void RulerCtrl::Paint(Draw& draw)
{
	Size client = GetSize();
	int csize = is_vert ? client.cy : client.cx;
	int cheight = is_vert ? client.cx : client.cy;
	Rect clip = GetSize();
	int cy = font.Info().GetHeight();
	double pos1 = FromClient(0);
	double pos2 = FromClient(csize);
	if(pos1 > pos2)
		Swap(pos1, pos2);
	double lrange = min_range, rrange = max_range;
	if(!IsNull(min_range) && pos1 < min_range) pos1 = min_range;
	if(!IsNull(max_range) && pos2 > max_range) pos2 = max_range;
	int cli1 = 0, cli2 = csize;
	if(scale < 0)
		Swap(lrange, rrange);
	if(!IsNull(lrange))
		cli1 = max<int>(cli1, ToClient(lrange));
	if(!IsNull(rrange))
		cli2 = min<int>(cli2, ToClient(rrange));
	Rect nclip;
	if(is_vert) {
		draw.DrawRect(0, 0, client.cx, cli1, outer_color);
		if(!IsNull(lrange))
			draw.DrawRect(0, cli1++, client.cx, 1, SBlack);
		draw.DrawRect(0, cli2, client.cx, client.cy - cli2, outer_color);
		if(!IsNull(rrange))
			draw.DrawRect(0, --cli2, client.cx, 1, SBlack);
		draw.DrawRect(0, cli1, 1, cli2 - cli1, SGray);
//		draw.DrawRect(0, cli1, 1, cli2 - cli1, SBlack);
		draw.DrawRect(client.cx - 1, cli1, 1, cli2 - cli1, SBlack);
		nclip = RectC(1, cli1, client.cx - 2, cli2 - cli1);
	}
	else {
		draw.DrawRect(0, 0, cli1, client.cy, outer_color);
		if(!IsNull(lrange))
			draw.DrawRect(cli1++, 0, 1, client.cy, SBlack);
		draw.DrawRect(cli2, 0, client.cx - cli2, client.cy, outer_color);
		if(!IsNull(rrange))
			draw.DrawRect(--cli2, 0, 1, client.cy, SBlack);
		draw.DrawRect(cli1, 0, cli2 - cli1, 1, SGray);
		draw.DrawRect(cli1, client.cy - 1, cli2 - cli1, 1, SBlack);
		nclip = RectC(cli1, 1, cli2 - cli1, client.cy - 2);
	}
	draw.DrawRect(nclip, background);
	draw.Clip(nclip);

	enum {
		SMALL_LIMIT = 100,
//		TEXT_LIMIT = 50,
		TGAP = 3,
		HGAP = 2,
		VGAP = 0,
		HXGAP = 3,
		VXGAP = 2,
		SMALL_SIZE = 5,
	};

	double rep_count = 1;
	double rep_delta = 0;
	if(!IsNull(small_repeat)) {
		rep_delta = small_repeat * floor(pos1 / small_repeat);
		rep_count = ceil(pos2 / small_repeat) - floor(pos1 / small_repeat);
	}
	if(!small_step.IsEmpty() && rep_count > 0
	&& rep_count * small_step.GetCount() <= cli2 - cli1) {
		int ix = BinFindIndex(small_step, pos1 - rep_delta);
		int ppos = (is_right ? 0 : cheight - SMALL_SIZE);
		for(int c = fround(rep_count); --c >= 0; ix = 0, rep_delta += small_repeat) {
			int lim = small_step.GetCount();
			if(small_step.Top() > pos2 - rep_delta)
				lim = BinFindIndex(small_step, pos2 - rep_delta);
			for(; ix < lim; ix++) {
				int cli = ToClient(small_step[ix] + rep_delta);
				if(is_vert)
					draw.DrawRect(ppos, cli, SMALL_SIZE, 1, Gray());
				else
					draw.DrawRect(cli, ppos, 1, SMALL_SIZE, Gray());
			}
		}
	}
	rep_count = 1;
	double rep_index = 0;
	if(!IsNull(text_repeat)) {
		rep_index = floor(pos1 / text_repeat);
		rep_count = ceil(pos2 / text_repeat) - floor(pos1 / text_repeat) + 1;
	}
	if(!text_step.IsEmpty() && (!text_value.IsEmpty() || text_convert)
	&& rep_count > 0 /*&& rep_count * text_step.GetCount() <= TEXT_LIMIT*/) {
		int ix = BinFindIndex(text_step, pos1 - rep_index * text_repeat);
		int ppos = (is_right ? SMALL_SIZE : cheight - cy - SMALL_SIZE);
		int rpos = (is_right ? 0 : cheight - SMALL_SIZE - 1);
		for(int c = fround(rep_count); --c >= 0; ix = 0, rep_index++) {
			int lim = text_step.GetCount();
			double dp2 = pos2 - rep_index * text_repeat;
			if(text_step.Top() > dp2) {
				lim = BinFindIndex(text_step, dp2);
				if(lim + 1 < text_step.GetCount() && text_step[lim + 1] - dp2 < dp2 - text_step[lim])
					lim++;
			}
			for(; ix < lim; ix++) {
				double value = text_step[ix] + rep_index * text_repeat;
				int cli = ToClient(value);
				String text;
				if(ix < text_value.GetCount())
					text = text_value[ix];
				else if(text_convert)
					text = StdFormat(text_convert -> Format(value));
				else
					text = StdFormat(value);
				Size tsize = GetTextSize(text, font);
				int half = tsize.cx >> 1;
				if(is_vert) {
					draw.DrawRect(0, cli, ppos, 1, Black());
					draw.DrawRect(rpos, cli, SMALL_SIZE + 1, 1, Black());
//					draw.DrawRect(ppos - VGAP, cli - half - HGAP, tsize.cy + 2 * VGAP, tsize.cx + 2 * HGAP, background);
					draw.DrawText(ppos, cli + half, 900, text, font, Gray());
				}
				else {
					draw.DrawRect(cli, 0, 1, ppos, Black());
					draw.DrawRect(cli, rpos, 1, SMALL_SIZE + 1, Black());
//					draw.DrawRect(cli - half - HGAP, ppos - VGAP, tsize.cx + 2 * HGAP, tsize.cy + 2 * VGAP, background);
					draw.DrawText(cli - half, ppos, text, font, Gray());
				}
			}
		}
	}
Ejemplo n.º 4
0
void SIC_StdFormat(EscEscape& e)
{
	e = StdFormat(StdValueFromEsc(e[0]));
}
Ejemplo n.º 5
0
void DlgSqlExport::Run(Sql& cursor, String command, String tablename)
{
	Title(Nvl(tablename, t_("SQL query")) + t_(" export"));
	object_name <<= tablename;
	if(!cursor.Execute(command)) {
		Exclamation(NFormat(t_("Error executing [* \1%s\1]: \1%s"), command, cursor.GetLastError()));
		return;
	}
	for(int i = 0; i < cursor.GetColumns(); i++) {
		const SqlColumnInfo& sci = cursor.GetColumnInfo(i);
		String type;
		switch(sci.valuetype) {
			case BOOL_V:
			case INT_V: type = t_("integer"); break;
			case DOUBLE_V: type = t_("real number"); break;
			case STRING_V:
			case WSTRING_V: type = t_("string"); break;
			case DATE_V: type = t_("date"); break;
			case TIME_V: type = t_("date/time"); break;
			case /*ORA_BLOB_V*/-1: type = t_("BLOB"); break;
			case /*ORA_CLOB_V*/-2: type = t_("CLOB"); break;
			default: type = FormatInt(sci.valuetype); break;
		}
		columns.Add(sci.name, sci.valuetype, sci.width, 1);
	}
	static String cfg;
	LoadFromString(*this, cfg);
	SyncUI();
	while(TopWindow::Run() == IDOK)
		try {
			String out_table = ~object_name;
			String delim;
			switch((int)~delimiters) {
				case DELIM_TAB: delim = "\t"; break;
				case DELIM_SEMICOLON: delim = ";"; break;
			}
			Vector<int> out;
			String colstr;
			String title;
			for(int i = 0; i < columns.GetCount(); i++)
				if(columns.Get(i, 3)) {
					out.Add(i);
					String cname = cursor.GetColumnInfo(i).name;
					colstr << (i ? ", " : "") << cname;
					if(i) title << delim;
					title << cname;
				}
			if(out.IsEmpty()) {
				throw Exc(t_("No columns selected!"));
				continue;
			}
			String rowbegin, rowend;
			int fmt = ~format;
			FileSel fsel;
			String ext;
			switch(fmt) {
				case FMT_TEXT: {
					rowend = "";
					ext = ".txt";
					fsel.Type(t_("Text files (*.txt)"), "*.txt");
					break;
				}
				case FMT_SQL: {
					if(identity_insert)
						rowbegin << "set identity_insert " << out_table << " on ";
					rowbegin << "insert into " << out_table << "(" << colstr << ") values (";
					rowend = ");";
					ext = ".sql";
					fsel.Type(t_("SQL scripts (*.sql)"), "*.sql");
					break;
				}
			}
			fsel.AllFilesType().DefaultExt(ext.Mid(1));
			if(!IsNull(recent_file))
				fsel <<= ForceExt(recent_file, ext);
			if(!fsel.ExecuteSaveAs(t_("Save export as")))
				continue;
			recent_file = ~fsel;
			FileOut fo;
			if(!fo.Open(recent_file)) {
				Exclamation(NFormat(t_("Error creating file [* \1%s\1]."), recent_file));
				continue;
			}
			if(fmt == FMT_TEXT)
				fo.PutLine(title);
			Progress progress(t_("Exporting row %d"));
			while(cursor.Fetch()) {
				String script = rowbegin;
				for(int i = 0; i < out.GetCount(); i++) {
					Value v = cursor[out[i]];
					switch(fmt) {
						case FMT_TEXT: {
							if(i)
								script.Cat(delim);
							if(IsString(v) && quote) {
								String s = v;
								script << '\"';
								for(const char *p = s, *e = s.End(); p < e; p++)
									if(*p == '\"')
										script.Cat("\"\"");
									else
										script.Cat(*p);
								script << '\"';
							}
							else
								script << StdFormat(v);
							break;
						}
						case FMT_SQL: {
							if(i) script.Cat(", ");
//							script << SqlCompile(SQLD_ORACLE, SqlFormat(v));
							break;
						}
					}
				}
				script << rowend;
				fo.PutLine(script);
/*
				if(autocommit && --left <= 0) {
					fo.PutLine("commit;");
					left = autocommit;
				}
*/
				if(progress.StepCanceled()) {
					Exclamation(t_("Export aborted!"));
					return;
				}
			}
			fo.Close();
			if(fo.IsError())
				throw Exc(NFormat(t_("Error writing file %s."), recent_file));
			break;
		}
		catch(Exc e) {
			ShowExc(e);
		}

	cfg = StoreAsString(*this);
}