Пример #1
0
int
main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);

  create_box_window ();
  create_table_window ();

  gtk_main ();

  return 0;
}
Пример #2
0
int
main (int argc, char *argv[])
{
  gtk_init (&argc, &argv);

  if (g_getenv ("RTL"))
    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);

  create_box_window ();
  create_table_window ();

  gtk_main ();

  return 0;
}
Пример #3
0
void __cdecl thread(void *args)
{
	int id;
	HANDLE *event_list=args;
	HANDLE event=0,event_idle=0;
	if(args==0)
		return;
	event=event_list[0];
	event_idle=event_list[1];
	if(event==0 || event_idle==0)
		return;
	printf("worker thread started\n");
	while(TRUE){
		stop_thread_menu(FALSE);
		SetEvent(event_idle);
		id=WaitForSingleObject(event,INFINITE);
		if(id==WAIT_OBJECT_0){
			stop_thread_menu(TRUE);
			strncpy(localinfo,taskinfo,sizeof(localinfo));
			printf("db=%s\n",localinfo);
			switch(task){
			case TASK_CLOSE_DB:
				{
					DB_TREE *db=0;
					if(find_db_tree(localinfo,&db)){
						intelli_del_db(db->name);
						mdi_remove_db(db);
						set_status_bar_text(ghstatusbar,0,"closed %s",localinfo);
					}
					else
						set_status_bar_text(ghstatusbar,0,"cant find %s",localinfo);
				}
				break;
			case TASK_OPEN_DB_AND_TABLE:
			case TASK_OPEN_DB:
				{
					DB_TREE *db=0;
					char *table;
					int result=FALSE;
					table=strstr(localinfo,";TABLE=");
					if(table!=0){
						table[0]=0;
						table++;
					}
					SetWindowText(ghstatusbar,"opening DB");
					if(!wait_for_treeview()){
						SetWindowText(ghstatusbar,"treeview error");
						break;
					}
					acquire_db_tree(localinfo,&db);
					if(!mdi_open_db(db)){
						char str[512];
						mdi_remove_db(db);
						_snprintf(str,sizeof(str),"Cant open %s",localinfo);
						str[sizeof(str)-1]=0;
						MessageBox(ghmainframe,str,"OPEN DB FAIL",MB_OK);
						SetWindowText(ghstatusbar,"error opening DB");
						set_focus_after_open(db);
					}
					else{
						intelli_add_db(db->name);
						set_focus_after_open(db);
						reassign_tables(db);
						if(task==TASK_OPEN_DB_AND_TABLE &&
							table!=0 && strncmp(table,"TABLE=",sizeof("TABLE=")-1)==0){
							table+=sizeof("TABLE=")-1;
							ResetEvent(event);
							task_open_table(db->name,table);
							continue;
						}
						else{
							load_tables_if_empty(db);
							if(keep_closed)
								close_db(db);
							result=TRUE;
						}
					}
					set_status_bar_text(ghstatusbar,0,"open DB %s %s",result?"done":"failed",keep_closed?"(closed DB)":"");
				}
				break;
			case TASK_GET_COL_INFO:
				{
					void *db=0;
					char table[80]={0};
					sscanf(localinfo,"DB=0x%08X;TABLE=%79[ -~]",&db,table);
					table[sizeof(table)-1]=0;
					if(db!=0){
						int result;
						set_status_bar_text(ghstatusbar,0,"getting col info for %s",table);
						result=get_col_info(db,table);
						if(keep_closed)
							close_db(db);
						if(result)
							set_status_bar_text(ghstatusbar,0,"col info done, %s",keep_closed?"(closed DB)":"");
						set_focus_after_open(db);
					}
				}
				break;
			case TASK_GET_INDEX_INFO:
				{
					void *db=0;
					char table[80]={0};
					sscanf(localinfo,"DB=0x%08X;TABLE=%79[ -~]",&db,table);
					table[sizeof(table)-1]=0;
					if(db!=0){
						int result;
						set_status_bar_text(ghstatusbar,0,"getting index info for %s",table);
						result=get_index_info(db,table);
						if(keep_closed)
							close_db(db);
						if(result)
							set_status_bar_text(ghstatusbar,0,"index info done, %s",keep_closed?"(closed DB)":"");
						set_focus_after_open(db);
					}
				}
				break;
			case TASK_GET_FOREIGN_KEYS:
				{
					void *db=0;
					char table[80]={0};
					sscanf(localinfo,"DB=0x%08X;TABLE=%79[ -~]",&db,table);
					table[sizeof(table)-1]=0;
					if(db!=0){
						int result;
						set_status_bar_text(ghstatusbar,0,"getting foreign keys for %s",table);
						result=get_foreign_keys(db,table);
						if(keep_closed)
							close_db(db);
						if(result)
							set_status_bar_text(ghstatusbar,0,"index info done, %s",keep_closed?"(closed DB)":"");
						set_focus_after_open(db);
					}
				}
				break;
			case TASK_UPDATE_ROW:
				{
					int result=FALSE;
					void *win=0;
					int row=0;
					sscanf(localinfo,"WIN=0x%08X;ROW=%i",&win,&row);
					if(win!=0){
						char *s=strstr(localinfo,"DATA=");
						if(s!=0){
							s+=sizeof("DATA=")-1;
							result=update_row(win,row,s);
							if(keep_closed){
								void *db=0;
								acquire_db_tree_from_win(win,&db);
								close_db(db);
							}
						}
					}
					set_status_bar_text(ghstatusbar,0,"update row %s %s",
						result?"done":"failed",
						keep_closed?"(closed DB)":"");
				}
				break;
			case TASK_DELETE_ROW:
				{
					int result=FALSE;
					void *win=0;
					int row=0;
					sscanf(localinfo,"WIN=0x%08X;ROW=%i",&win,&row);
					if(win!=0){
						result=delete_row(win,row);
						if(keep_closed){
							void *db=0;
							acquire_db_tree_from_win(win,&db);
							close_db(db);
						}
					}
					set_status_bar_text(ghstatusbar,0,"delete row %s",
						result?"done":"failed",
						(win!=0 && keep_closed)?"(closed DB)":"");
				}
				break;
			case TASK_INSERT_ROW:
				{
					int result=FALSE;
					void *win=0,*hlistview=0;
					sscanf(localinfo,"WIN=%08X,HLISTVIEW=0x%08X",&win,&hlistview);
					if(win!=0 && hlistview!=0){
						int msg=IDOK;
						result=insert_row(win,hlistview);
						if(!result)
							msg=IDCANCEL;
						PostMessage(GetParent(hlistview),WM_USER,msg,hlistview);
						if(keep_closed){
							void *db=0;
							acquire_db_tree_from_win(win,&db);
							close_db(db);
						}
					}
					set_status_bar_text(ghstatusbar,0,"inserting row %s %s",
						result?"done":"failed",
						(win!=0 && hlistview!=0 && keep_closed)?"(closed DB)":"");

				}
				break;
			case TASK_EXECUTE_QUERY:
				{
					void *win=0;
					int result=FALSE;
					win=strtoul(localinfo,0,0);
					if(win==0)
						mdi_get_current_win(&win);
					if(win!=0){
						char *s=0;
						int size=0;
						reopen_db(win);
						mdi_create_abort(win);
						mdi_get_edit_text(win,&s,&size);
						if(s!=0){
							sql_remove_comments(s,size);
							result=execute_sql(win,s,TRUE);
							free(s);
						}
						mdi_destroy_abort(win);
						if(keep_closed){
							void *db=0;
							acquire_db_tree_from_win(win,&db);
							close_db(db);
						}
						set_focus_after_result(win,result);
					}
					if(!result)
						set_status_bar_text(ghstatusbar,0,"execute sql failed %s",
							keep_closed?"(closed DB)":"");
				}
				break;
			case TASK_NEW_QUERY:
				{
					void *db=0;
					find_selected_tree(&db);
					if(db!=0){
						void *win=0;
						char *tname="new_query";
						if(acquire_table_window(&win,tname)){
							create_table_window(ghmdiclient,win);
							set_focus_after_result(win,FALSE);
							assign_db_to_table(db,win,tname);
						}
					}
				}
				break;
			case TASK_REFRESH_TABLES:
			case TASK_REFRESH_TABLES_ALL:
				{
					int result=FALSE;
					DB_TREE *db=0;
					SetWindowText(ghstatusbar,"refreshing tables");
					if(acquire_db_tree(localinfo,&db)){
						if(!mdi_open_db(db)){
							mdi_remove_db(db);
							SetWindowText(ghstatusbar,"error opening DB");
						}
						else{
							intelli_add_db(db->name);
							result=refresh_tables(db,task==TASK_REFRESH_TABLES_ALL);
							if(keep_closed)
								close_db(db);
						}
						if(result)
							set_status_bar_text(ghstatusbar,0,"refreshed tables %s",
								keep_closed?"(closed DB)":"");
					}
					else
						SetWindowText(ghstatusbar,"error refreshing cant acquire table");
				}
				break;
			case TASK_LIST_TABLES:
				{
					int result=FALSE;
					DB_TREE *db=0;
					SetWindowText(ghstatusbar,"listing tables");
					if(acquire_db_tree(localinfo,&db)){
						if(!mdi_open_db(db)){
							mdi_remove_db(db);
							SetWindowText(ghstatusbar,"error opening DB");
						}
						else{
							intelli_add_db(db->name);
							result=get_table_list(db);
							if(keep_closed)
								close_db(db);
						}
						if(result){
							set_status_bar_text(ghstatusbar,0,"done listing tables %s",
								keep_closed?"(closed DB)":"");
						}else{
							SetWindowText(ghstatusbar,"error listing tables");
						}
					}
					else
						SetWindowText(ghstatusbar,"error refreshing cant acquire tree");
				}
				break;
			case TASK_LIST_PROCS:
				{
					int result=FALSE;
					DB_TREE *db=0;
					SetWindowText(ghstatusbar,"listing stored procedures");
					if(acquire_db_tree(localinfo,&db)){
						if(!mdi_open_db(db)){
							mdi_remove_db(db);
							SetWindowText(ghstatusbar,"error opening DB");
						}
						else{
							intelli_add_db(db->name);
							result=get_proc_list(db);
							if(keep_closed)
								close_db(db);
						}
						if(result){
							set_status_bar_text(ghstatusbar,0,"done listing stored procs %s",
								keep_closed?"(closed DB)":"");
						}else{
							SetWindowText(ghstatusbar,"error listing stored procs");
						}
					}
					else
						SetWindowText(ghstatusbar,"error refreshing cant acquire tree");
				}
				break;
			case TASK_OPEN_TABLE:
				{
					int result=FALSE;
					char dbname[MAX_PATH*2]={0},table[80]={0},*p;
					p=strrchr(localinfo,';');
					if(p!=0){
						void *db=0;
						p[0]=0;
						strncpy(dbname,localinfo,sizeof(dbname));
						strncpy(table,p+1,sizeof(table));
						if(find_db_tree(dbname,&db)){
							void *win=0;
							if(acquire_table_window(&win,table)){
								char sql[256]={0};
								create_table_window(ghmdiclient,win);
								open_db(db);
								assign_db_to_table(db,win,table);
								if(strchr(table,' ')!=0)
									_snprintf(sql,sizeof(sql),"SELECT * FROM [%s]",table);
								else
									_snprintf(sql,sizeof(sql),"SELECT * FROM %s",table);
								mdi_set_edit_text(win,sql);
								mdi_create_abort(win);
								result=execute_sql(win,sql,TRUE);
								mdi_destroy_abort(win);
								load_tables_if_empty(db);
								set_focus_after_result(win,result);
								if(keep_closed)
									close_db(db);

							}
							else
								free_window(win);

						}
					}
					if(!result)
						set_status_bar_text(ghstatusbar,0,"open table:%s %s %s",
							table,"failed",keep_closed?"(closed DB)":"");
				}
				break;
			case TASK_INTELLISENSE_ADD_ALL:
				{
					void *win=0;
					int result=FALSE;
					win=strtoul(localinfo,0,0);
					if(win==0)
						mdi_get_current_win(&win);
					if(win!=0){
						reopen_db(win);
						mdi_create_abort(win);
						result=intellisense_add_all(win);
						mdi_destroy_abort(win);
						if(keep_closed){
							void *db=0;
							acquire_db_tree_from_win(win,&db);
							close_db(db);
						}
						set_focus_after_result(win,FALSE);
					}
					if(!result)
						set_status_bar_text(ghstatusbar,0,"intellisense add all failed %s",
							keep_closed?"(closed DB)":"");
				}
				break;
			default:
				break;
			}
		}
		ResetEvent(event);
	}
	CloseHandle(event);
	hworker=0;
}