21 #include "emb_samples.h"
29 bool b_new_line =
false;
30 const char *server_groups[] = {
31 "",
"embedded",
"server", NULL
36 #pragma package(smart_init)
37 #pragma resource "*.dfm"
45 while ((row=mysql_fetch_row(res)) != 0)
47 mysql_field_seek(res,0);
48 for (
unsigned int i=0 ;
i < mysql_num_fields(res);
i++)
49 rows.push_back(row[
i]);
54 __fastcall TForm1::TForm1(TComponent* Owner)
60 void __fastcall TForm1::Timer1Timer(TObject *Sender)
62 if (is_server_started)
64 ToggleButton->Caption =
"Quit";
65 Timer1->Enabled =
false;
69 void __fastcall TForm1::FormCreate(TObject *Sender)
71 is_server_started =
false;
74 db_root = DBView->Items->Add(NULL, db_root_caption.UpperCase());
75 db_root->ImageIndex = 0;
79 void __fastcall TForm1::ToggleButtonClick(TObject *Sender)
81 if (!is_server_started)
83 mysql_server_init(NULL, NULL, (
char **)server_groups) ;
94 void __fastcall TForm1::computer_ip(
void)
96 WORD wVersionRequested;
98 wVersionRequested = MAKEWORD(1,1);
99 WSAStartup(wVersionRequested,&WSAData);
106 P = gethostbyname(s);
107 db_root_caption = P->h_name;
108 in.S_un.S_un_b.s_b1 = P->h_addr_list[0][0];
109 in.S_un.S_un_b.s_b2 = P->h_addr_list[0][1];
110 in.S_un.S_un_b.s_b3 = P->h_addr_list[0][2];
111 in.S_un.S_un_b.s_b4 = P->h_addr_list[0][3];
113 db_root_caption +=
" ( " + (AnsiString)P2 +
" )";
116 bool __fastcall TForm1::connect_server()
118 bool ret_value =
false;
120 MySQL = mysql_init(MySQL);
123 if (mysql_real_connect(MySQL, NULL, NULL, NULL, NULL, 0, NULL, 0))
126 is_server_started =
true;
132 void __fastcall TForm1::FormDestroy(TObject *Sender)
134 if (is_server_started)
139 void __fastcall TForm1::DBViewClick(TObject *Sender)
141 if (DBView->Selected != db_root && DBView->Selected != NULL)
143 get_tables(DBView->Selected->Text);
148 bool __fastcall TForm1::get_tables(
String db_name)
153 TableView->Items->Clear();
155 s_cmd+= db_name.c_str();
157 if (mysql_query(MySQL, s_cmd.c_str()) ||
158 !(res=mysql_list_tables(MySQL,
"%")))
161 tables_node = TableView->Items->Add(NULL, db_name.c_str());
162 tables_node->ImageIndex = 1;
163 tables_node->SelectedIndex = 1;
165 deque<string> rows = fill_rows(res);
167 mysql_free_result(res);
168 fill_tree(rows,tables_tree,tables_node,TableView,2);
173 bool __fastcall TForm1::get_dbs(
void)
177 if (!is_server_started)
180 if (!(res=mysql_list_dbs(MySQL,
"%")))
183 deque<string> rows = fill_rows(res);
185 mysql_free_result(res);
186 fill_tree(rows,MySQLDbs,db_root,DBView,1);
187 info_server->Text = mysql_get_server_info(MySQL);
192 void __fastcall TForm1::fill_tree(deque<string> rows,
198 deque<string>::iterator r;
199 for(r = rows.begin(); r != rows.end() ; r++)
201 root = View->Items->AddChild(child, (*r).c_str());
202 root->ImageIndex = image_index;
203 root->SelectedIndex = image_index;
205 child->Expanded =
true;
212 AnsiString use_db, show_cols, show_desc;
213 unsigned int num_fields;
214 int fields_control = 0, grid_row = 1, fields_number;
219 use_db+= DBView->Selected->Text.c_str();
221 show_cols =
"show full columns from ";
222 show_cols+= table_name.c_str();
223 show_desc+= table_name.c_str();
225 if (mysql_query(MySQL, use_db.c_str() ))
228 if (mysql_query(MySQL, show_cols.c_str() ) ||
229 !(res1=mysql_store_result(MySQL)))
231 if (mysql_query(MySQL, show_desc.c_str() ) ||
232 !(res1=mysql_store_result(MySQL)))
235 mysql_fetch_row(res1);
236 mysql_field_seek(res1,0);
237 fields_number = (mysql_num_fields(res1) - 2);
238 mysql_free_result(res1);
240 if (mysql_query(MySQL, show_cols.c_str() ) ||
241 !(res=mysql_store_result(MySQL)))
243 if (mysql_query(MySQL, show_desc.c_str() ) ||
244 !(res=mysql_store_result(MySQL)))
248 while ((row=mysql_fetch_row(res)) != 0)
250 mysql_field_seek(res,0);
251 for (num_fields=0 ; num_fields < mysql_num_fields(res); num_fields++)
253 if (fields_control <= fields_number )
255 desc_table_grid->Cells[fields_control][grid_row] = row[num_fields];
260 desc_table_grid->Cells[(fields_control)][grid_row] = row[num_fields];
263 desc_table_grid->RowCount++;
267 desc_table_grid->RowCount--;
268 mysql_free_result(res);
272 void __fastcall TForm1::TableViewClick(TObject *Sender)
274 if (DBView->Selected != db_root && DBView->Selected != NULL)
275 if (DBView->Selected != tables_tree)
276 get_desc_table(TableView->Selected->Text);
279 void __fastcall TForm1::clean_desc_grid(
void)
281 desc_table_grid->RowCount= 2;
282 desc_table_grid->Cells[0][1] =
"";
283 desc_table_grid->Cells[1][1] =
"";
284 desc_table_grid->Cells[2][1] =
"";
285 desc_table_grid->Cells[3][1] =
"";
286 desc_table_grid->Cells[4][1] =
"";
287 desc_table_grid->Cells[5][1] =
"";
290 void __fastcall TForm1::titles_grid(
void)
292 desc_table_grid->Cells[0][0] =
"Field";
293 desc_table_grid->Cells[1][0] =
"Type";
294 desc_table_grid->Cells[2][0] =
"Null";
295 desc_table_grid->Cells[3][0] =
"Key";
296 desc_table_grid->Cells[4][0] =
"Default";
297 desc_table_grid->Cells[5][0] =
"Extra";
298 desc_table_grid->Cells[6][0] =
"Privileges";