SqlDlg.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SqlDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "LYFZIPManage.h"
  5. #include "SqlDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // SqlDlg dialog
  13. SqlDlg::SqlDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(SqlDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(SqlDlg)
  17. m_sql = _T("");
  18. //}}AFX_DATA_INIT
  19. }
  20. void SqlDlg::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. //{{AFX_DATA_MAP(SqlDlg)
  24. DDX_Text(pDX, IDC_EDIT1, m_sql);
  25. //}}AFX_DATA_MAP
  26. }
  27. BEGIN_MESSAGE_MAP(SqlDlg, CDialog)
  28. //{{AFX_MSG_MAP(SqlDlg)
  29. //}}AFX_MSG_MAP
  30. END_MESSAGE_MAP()
  31. /////////////////////////////////////////////////////////////////////////////
  32. // SqlDlg message handlers
  33. extern BOOL MyExecuteSQL(CDatabase *pdb, CString sql);
  34. void SqlDlg::OnOK()
  35. {
  36. // TODO: Add extra validation here
  37. UpdateData();
  38. MyExecuteSQL(&g_db, m_sql);
  39. if(m_sql.GetLength ()<6)return;
  40. if(m_sql.Left (6)!="select")return;
  41. int i;CString temp,str;
  42. int colcount;
  43. CODBCFieldInfo fieldinfo;
  44. CRecordset myset(&g_db);
  45. myset.Open (CRecordset::forwardOnly, m_sql);
  46. while(!myset.IsEOF ())
  47. {
  48. colcount=myset.GetODBCFieldCount ();
  49. for( i=0; i<colcount; i++)
  50. {
  51. myset.GetFieldValue(i, temp);
  52. str+="'"+temp+"',";
  53. }
  54. str.TrimRight (",");
  55. str+="\r\n";
  56. myset.MoveNext ();
  57. }
  58. myset.Close();
  59. AfxMessageBox(str);
  60. }
  61. BOOL SqlDlg::OnInitDialog()
  62. {
  63. CDialog::OnInitDialog();
  64. // TODO: Add extra initialization here
  65. GetDlgItem(IDC_EDIT1)->SetFocus();
  66. return false; // return TRUE unless you set the focus to a control
  67. // EXCEPTION: OCX Property Pages should return FALSE
  68. }