dsnchooser.c

来自「一个可以替代windows ODBC驱动程序管理器的通用ODBC数据库引擎」· C语言 代码 · 共 1,772 行 · 第 1/4 页

C
1,772
字号
	  gtk_clist_get_text (GTK_CLIST (choose_t->udsnlist),	      GPOINTER_TO_INT (GTK_CLIST (choose_t->udsnlist)->selection->		  data), 2, &szDriver);	}      /* Call the right function */      if (szDSN)	{	  sprintf (connstr, "DSN=%s\0", szDSN);	  size -= (STRLEN (connstr) + 1);	  SQLSetConfigMode (ODBC_USER_DSN);	  if (!SQLGetPrivateProfileString (szDSN, NULL, "", tokenstr,		  sizeof (tokenstr), NULL))	    {	      _iodbcdm_errorbox (choose_t->mainwnd, szDSN,		  "An error occured when trying to configure the DSN : ");	      goto done;	    }	  for (curr = tokenstr, cour = connstr + STRLEN (connstr) + 1; *curr;	      curr += (STRLEN (curr) + 1), cour += (STRLEN (cour) + 1))	    {	      STRCPY (cour, curr);	      cour[STRLEN (curr)] = '=';	      SQLSetConfigMode (ODBC_USER_DSN);	      SQLGetPrivateProfileString (szDSN, curr, "",		  cour + STRLEN (curr) + 1, size - STRLEN (curr) - 1, NULL);	      size -= (STRLEN (cour) + 1);	    }	  *cour = 0;	  SQLSetConfigMode (ODBC_USER_DSN);	  if (!SQLConfigDataSource (choose_t->mainwnd, ODBC_CONFIG_DSN,		  szDriver, connstr))	    {	      if (SQLInstallerError (1, &error, connstr, sizeof (connstr),		      NULL) != SQL_NO_DATA		  && error != ODBC_ERROR_REQUEST_FAILED)		_iodbcdm_errorbox (choose_t->mainwnd, szDSN,		    "An error occured when trying to configure the DSN : ");	      goto done;	    }	  adddsns_to_list (choose_t->udsnlist, FALSE);	}    done:      if (GTK_CLIST (choose_t->udsnlist)->selection == NULL)	{	  if (choose_t->uremove)	    gtk_widget_set_sensitive (choose_t->uremove, FALSE);	  if (choose_t->uconfigure)	    gtk_widget_set_sensitive (choose_t->uconfigure, FALSE);	  if (choose_t->utest)	    gtk_widget_set_sensitive (choose_t->utest, FALSE);	}    }  return;}voiduserdsn_test_clicked (GtkWidget *widget, TDSNCHOOSER *choose_t){  HENV henv;  HDBC hdbc;  SWORD buflen;  char connstr[4096] = { 0 };  char outconnstr[4096] = { 0 };  char *szDSN;  if (choose_t)    {      /* Retrieve the DSN name */      if (GTK_CLIST (choose_t->udsnlist)->selection != NULL)	gtk_clist_get_text (GTK_CLIST (choose_t->udsnlist),	    GPOINTER_TO_INT (GTK_CLIST (choose_t->udsnlist)->selection->data),	    0, &szDSN);      if (szDSN && STRLEN (szDSN))	{#if (ODBCVER < 0x300)	  if (SQLAllocEnv (&henv) != SQL_SUCCESS)#else	  if (SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv) != SQL_SUCCESS)#endif	    {	      display_sqlerror (choose_t->mainwnd,		  "The connection test to the DSN failed.", szDSN,		  SQL_NULL_HENV, SQL_NULL_HDBC, SQL_NULL_HSTMT);	      return;	    }#if (ODBCVER < 0x300)	  if (SQLAllocConnect (henv, &hdbc) != SQL_SUCCESS)#else	  SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION,	      (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);	  if (SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc) != SQL_SUCCESS)#endif	    {	      SQLFreeEnv (henv);	      display_sqlerror (choose_t->mainwnd,		  "The connection test to the DSN failed.", szDSN, henv,		  SQL_NULL_HDBC, SQL_NULL_HSTMT);	      return;	    }	  sprintf (connstr, "DSN=%s", szDSN);	  SQLSetConfigMode (ODBC_USER_DSN);	  if (SQLDriverConnect (hdbc, choose_t->mainwnd, connstr, SQL_NTS,		  outconnstr, sizeof (outconnstr), &buflen,		  SQL_DRIVER_PROMPT) != SQL_SUCCESS)	    display_sqlerror (choose_t->mainwnd,		"The connection test to the DSN failed.", szDSN, henv, hdbc,		SQL_NULL_HSTMT);	  else	    {	      _iodbcdm_messagebox (choose_t->mainwnd, szDSN,		  "The connection DSN was tested successfully, and can be used at this time.");	      SQLDisconnect (hdbc);	    }#if (ODBCVER < 0x300)	  SQLFreeConnect (hdbc);	  SQLFreeEnv (henv);#else	  SQLFreeHandle (SQL_HANDLE_DBC, hdbc);	  SQLFreeHandle (SQL_HANDLE_ENV, henv);#endif	}      if (GTK_CLIST (choose_t->udsnlist)->selection == NULL)	{	  if (choose_t->uremove)	    gtk_widget_set_sensitive (choose_t->uremove, FALSE);	  if (choose_t->uconfigure)	    gtk_widget_set_sensitive (choose_t->uconfigure, FALSE);	  if (choose_t->utest)	    gtk_widget_set_sensitive (choose_t->utest, FALSE);	}    }}voidsystemdsn_add_clicked (GtkWidget *widget, TDSNCHOOSER *choose_t){  char connstr[4096] = { 0 };  char drv[1024] = { 0 };  int sqlstat;  DWORD error;  if (choose_t)    {      /* Try first to get the driver name */      SQLSetConfigMode (ODBC_SYSTEM_DSN);      if (_iodbcdm_drvchoose_dialbox (choose_t->mainwnd, drv, sizeof (drv),	      &sqlstat) == SQL_SUCCESS)	{	  if (!SQLConfigDataSource (choose_t->mainwnd, ODBC_ADD_SYS_DSN,		  drv + STRLEN ("DRIVER="), connstr))	    {	      if (SQLInstallerError (1, &error, connstr, sizeof (connstr),		      NULL) != SQL_NO_DATA)		_iodbcdm_errorbox (choose_t->mainwnd, NULL,		    "An error occured when trying to add the DSN : ");	      goto done;	    }	  adddsns_to_list (choose_t->sdsnlist, TRUE);	}    done:      if (GTK_CLIST (choose_t->sdsnlist)->selection == NULL)	{	  if (choose_t->sremove)	    gtk_widget_set_sensitive (choose_t->sremove, FALSE);	  if (choose_t->sconfigure)	    gtk_widget_set_sensitive (choose_t->sconfigure, FALSE);	  if (choose_t->stest)	    gtk_widget_set_sensitive (choose_t->stest, FALSE);	}    }  return;}voidsystemdsn_remove_clicked (GtkWidget *widget, TDSNCHOOSER *choose_t){  char dsn[1024] = { 0 };  char *szDSN = NULL, *szDriver = NULL;  if (choose_t)    {      /* Retrieve the DSN name */      if (GTK_CLIST (choose_t->sdsnlist)->selection != NULL)	{	  gtk_clist_get_text (GTK_CLIST (choose_t->sdsnlist),	      GPOINTER_TO_INT (GTK_CLIST (choose_t->sdsnlist)->selection->		  data), 0, &szDSN);	  gtk_clist_get_text (GTK_CLIST (choose_t->sdsnlist),	      GPOINTER_TO_INT (GTK_CLIST (choose_t->sdsnlist)->selection->		  data), 2, &szDriver);	}      /* Call the right function */      if (szDSN	  && create_confirm (choose_t->mainwnd, szDSN,	      "Are you sure you want to remove this DSN ?"))	{	  sprintf (dsn, "DSN=%s\0", szDSN);	  dsn[STRLEN (dsn) + 1] = 0;	  if (!SQLConfigDataSource (choose_t->mainwnd, ODBC_REMOVE_SYS_DSN,		  szDriver, dsn))	    _iodbcdm_errorbox (choose_t->mainwnd, szDSN,		"An error occured when trying to remove the DSN : ");	  adddsns_to_list (choose_t->sdsnlist, TRUE);	}      if (GTK_CLIST (choose_t->sdsnlist)->selection == NULL)	{	  if (choose_t->sremove)	    gtk_widget_set_sensitive (choose_t->sremove, FALSE);	  if (choose_t->sconfigure)	    gtk_widget_set_sensitive (choose_t->sconfigure, FALSE);	  if (choose_t->stest)	    gtk_widget_set_sensitive (choose_t->stest, FALSE);	}    }}voidsystemdsn_configure_clicked (GtkWidget *widget, TDSNCHOOSER *choose_t){  char connstr[4096] = { 0 };  char tokenstr[4096] = { 0 };  char *szDSN = NULL, *szDriver = NULL, *curr, *cour;  int size = sizeof (connstr);  DWORD error;  if (choose_t)    {      /* Retrieve the DSN name */      if (GTK_CLIST (choose_t->sdsnlist)->selection != NULL)	{	  gtk_clist_get_text (GTK_CLIST (choose_t->sdsnlist),	      GPOINTER_TO_INT (GTK_CLIST (choose_t->sdsnlist)->selection->		  data), 0, &szDSN);	  gtk_clist_get_text (GTK_CLIST (choose_t->sdsnlist),	      GPOINTER_TO_INT (GTK_CLIST (choose_t->sdsnlist)->selection->		  data), 2, &szDriver);	}      /* Call the right function */      if (szDSN)	{	  sprintf (connstr, "DSN=%s\0", szDSN);	  size -= (STRLEN (connstr) + 1);	  SQLSetConfigMode (ODBC_SYSTEM_DSN);	  if (!SQLGetPrivateProfileString (szDSN, NULL, "", tokenstr,		  sizeof (tokenstr), NULL))	    {	      _iodbcdm_errorbox (choose_t->mainwnd, szDSN,		  "An error occured when trying to configure the DSN : ");	      goto done;	    }	  for (curr = tokenstr, cour = connstr + STRLEN (connstr) + 1; *curr;	      curr += (STRLEN (curr) + 1), cour += (STRLEN (cour) + 1))	    {	      STRCPY (cour, curr);	      cour[STRLEN (curr)] = '=';	      SQLSetConfigMode (ODBC_SYSTEM_DSN);	      SQLGetPrivateProfileString (szDSN, curr, "",		  cour + STRLEN (curr) + 1, size - STRLEN (curr) - 1, NULL);	      size -= (STRLEN (cour) + 1);	    }	  *cour = 0;	  if (!SQLConfigDataSource (choose_t->mainwnd, ODBC_CONFIG_SYS_DSN,		  szDriver, connstr))	    {	      if (SQLInstallerError (1, &error, connstr, sizeof (connstr),		      NULL) != SQL_NO_DATA		  && error != ODBC_ERROR_REQUEST_FAILED)		_iodbcdm_errorbox (choose_t->mainwnd, szDSN,		    "An error occured when trying to configure the DSN : ");	      goto done;	    }	  adddsns_to_list (choose_t->sdsnlist, TRUE);	}    done:      if (GTK_CLIST (choose_t->sdsnlist)->selection == NULL)	{	  if (choose_t->sremove)	    gtk_widget_set_sensitive (choose_t->sremove, FALSE);	  if (choose_t->sconfigure)	    gtk_widget_set_sensitive (choose_t->sconfigure, FALSE);	  if (choose_t->stest)	    gtk_widget_set_sensitive (choose_t->stest, FALSE);	}    }  return;}voidsystemdsn_test_clicked (GtkWidget * widget, TDSNCHOOSER * choose_t){  HENV henv;  HDBC hdbc;  SWORD buflen;  char connstr[4096] = { 0 };  char outconnstr[4096] = { 0 };  char *szDSN;  if (choose_t)    {      /* Retrieve the DSN name */      if (GTK_CLIST (choose_t->sdsnlist)->selection != NULL)	gtk_clist_get_text (GTK_CLIST (choose_t->sdsnlist),	    GPOINTER_TO_INT (GTK_CLIST (choose_t->sdsnlist)->selection->data),	    0, &szDSN);      if (szDSN && STRLEN (szDSN))	{#if (ODBCVER < 0x300)	  if (SQLAllocEnv (&henv) != SQL_SUCCESS)#else	  if (SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv) != SQL_SUCCESS)#endif	    {	      display_sqlerror (choose_t->mainwnd,		  "The connection test to the DSN failed.", szDSN,		  SQL_NULL_HENV, SQL_NULL_HDBC, SQL_NULL_HSTMT);	      return;	    }#if (ODBCVER < 0x300)	  if (SQLAllocConnect (henv, &hdbc) != SQL_SUCCESS)#else	  SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION,	      (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER);	  if (SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc) != SQL_SUCCESS)#endif	    {	      SQLFreeEnv (henv);	      display_sqlerror (choose_t->mainwnd,		  "The connection test to the DSN failed.", szDSN, henv,		  SQL_NULL_HDBC, SQL_NULL_HSTMT);	      return;	    }	  sprintf (connstr, "DSN=%s", szDSN);	  SQLSetConfigMode (ODBC_SYSTEM_DSN);	  if (SQLDriverConnect (hdbc, choose_t->mainwnd, connstr, SQL_NTS,		  outconnstr, sizeof (outconnstr), &buflen,		  SQL_DRIVER_PROMPT) != SQL_SUCCESS)	    display_sqlerror (choose_t->mainwnd,		"The connection test to the DSN failed.", szDSN, henv, hdbc,		SQL_NULL_HSTMT);	  else	    {	      _iodbcdm_messagebox (choose_t->mainwnd, szDSN,		  "The connection DSN was tested successfully, and can be used at this time.");	      SQLDisconnect (hdbc);	    }#if (ODBCVER < 0x300)	  SQLFreeConnect (hdbc);	  SQLFreeEnv (henv);#else	  SQLFreeHandle (SQL_HANDLE_DBC, hdbc);	  SQLFreeHandle (SQL_HANDLE_ENV, henv);#endif	}      if (GTK_CLIST (choose_t->sdsnlist)->selection == NULL)	{	  if (choose_t->sremove)	    gtk_widget_set_sensitive (choose_t->sremove, FALSE);	  if (choose_t->sconfigure)	    gtk_widget_set_sensitive (choose_t->sconfigure, FALSE);	  if (choose_t->stest)	    gtk_widget_set_sensitive (choose_t->stest, FALSE);	}    }}voidfiledsn_add_clicked (GtkWidget *widget, TDSNCHOOSER *choose_t){  HENV henv;  HDBC hdbc;  char connstr[4096] = { 0 };  char drv[1024] = { 0 };  char outconnstr[4096] = { 0 };  SWORD buflen;  int sqlstat;  DWORD error;  LPSTR dsn = NULL;  if (choose_t)    {      /* Try first to get the driver name */      SQLSetConfigMode (ODBC_USER_DSN);      if (_iodbcdm_drvchoose_dialbox (choose_t->mainwnd, drv, sizeof (drv),	      &sqlstat) == SQL_SUCCESS)	{	  /* First get the DSN name */	  do	    {	      dsn = (LPSTR) create_filedsn ((HWND) (choose_t->mainwnd));	    }	  while (dsn && !SQLValidDSN (dsn));	  if (!dsn)	    goto quit;	  /* Build the string connection */	  sprintf (connstr, "DSN=%s;%s;SAVEFILE=%s/%s.dsn", dsn, drv,	      choose_t->curr_dir, dsn);	  free (dsn);	  if (SQLAllocEnv (&henv) != SQL_SUCCESS)	    {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?