Index: GSEXmlParser/GSEXmlParser.cpp
===================================================================
--- GSEXmlParser/GSEXmlParser.cpp	(revision 30)
+++ GSEXmlParser/GSEXmlParser.cpp	(revision 37)
@@ -124,4 +124,90 @@
 }
 
+void   GSEParser::ToMySQL(String username, String password, String db, String db_ip)
+{
+	//
+	MySqlSession session;
+	if(!session.Connect("gse", "nchcnchc", "gse", "localhost")) {
+		printf("Can't connect with MySql\n");
+		return;
+	}
+	Sql sql(session);
+	sql.Execute("use gse");	
+	String cmd;
+	//
+	Cout() << "Total Record Count:" << data.GetCount() << "\n";
+	int sid;
+    int did;
+    String name;	
+	for (int i = 0; i < data.GetCount(); i++) {		
+		// check gsefamily record
+		cmd = "select * from gsefamily where iid = \"" + data[i].iid + "\"";
+		sql.Execute(cmd);		
+		if (sql.GetRowsProcessed()>0) {
+			Cout() << "Warnning: IID ["+data[i].iid+"] is exist." << "\n";			
+		} else {
+			// add a new gsefamily record
+			cmd = "insert into gsefamily (iid,source) values (\""+data[i].iid+"\",\""+data[i].source+"\");";
+			if (!sql.Execute(cmd)) {
+				Cout() << "Execution Error: " << sql.GetErrorCodeString() << "  Cmd: " << sql.GetErrorStatement() << "\n";			
+			}
+		}
+		//Cout() << "IID ["+data[i].iid+"]" << "\n";
+		
+		sid = 0;
+		// check supplementary		
+        cmd = "select sid from supplementary where type = \"" + data[i].supp_type + "\";";        
+        sql.Execute(cmd);        
+        if (sql.GetRowsProcessed()==0) {  
+            //new a supplementary record
+            cmd = "insert into supplementary (type) values (\"" + data[i].supp_type + "\");";            
+            if (!sql.Execute(cmd)) {
+                Cout() << "Execution Error: " << sql.GetErrorCode() << "  Cmd: " << sql.GetErrorStatement() << "\n";			
+            }       
+            sid = sql.GetInsertedId();     
+        } else {
+            if (sql.Fetch())
+               sid = sql[0];
+            //Cout() << "sid: " << sid << "\n";
+        }
+        
+        //new a supplementary-map record        
+        cmd = "insert into `supplementary-map` (iid,sid,value) values (\""+data[i].iid+"\",\""+AsString(sid)+"\",\""+data[i].supp_data+"\")";        
+        if (!sql.Execute(cmd)) {            
+            Cout() << "\nExecution Error: " << sql.GetErrorCode() << "  Cmd: " << sql.GetErrorStatement() << "\n";			
+        }
+                       
+        //Cout() << "data[" << i << "].desc.GetCount() = " << data[i].desc.GetCount() << "\n";
+        VectorMap<String, String> desc = data[i].desc;
+        for (int j=0; j<desc.GetCount(); j++) {
+            
+			// check description
+			name = desc.GetKey(j);			
+	        cmd = "select did from description where name = \"" + name + "\"";
+	        sql.Execute(cmd);
+	        
+	        did = 0;
+	        if (sql.GetRowsProcessed()==0) {  
+	            //new a description record
+	            cmd = "insert into description (name) values (\"" + name + "\");";
+	            if (!sql.Execute(cmd)) {
+	                Cout() << "Execution Error: " << sql.GetErrorCodeString() << "  Cmd: " << sql.GetErrorStatement() << "\n";			
+	            }   
+	            did = sql.GetInsertedId();         
+	        } else {
+	            if (sql.Fetch())
+	            	did = sql[0];
+	        }
+	        
+	        cmd = "insert into `description-map` (iid,did,value) values (\"" + data[i].iid + "\",\"" + AsString(did) + "\",\"" + desc.Get(name) + "\")";
+	        if (!sql.Execute(cmd)) {
+	            Cout() << "Execution Error: " << sql.GetErrorCodeString() << "  Cmd: " << sql.GetErrorStatement() << "\n";			
+	        }
+	        	        
+        }
+        
+	}	
+}
+
 String TrimSpace(String str) {
 	while (str.StartsWith(" ") && str.GetLength()) {
@@ -136,5 +222,5 @@
 CONSOLE_APP_MAIN
 {
-	String in, out, fmt, arg_flag;
+	String in, out, fmt, user, pwd, db, ip, arg_flag;
 	/*
 	in = "GSE2109_family.xml";
@@ -153,4 +239,12 @@
 		} else if (arg_flag.IsEqual("-f")) {
 			fmt = cmdline[i];
+		} else if (arg_flag.IsEqual("-u")) {
+			user = cmdline[i];			
+		} else if (arg_flag.IsEqual("-p")) {
+			pwd = cmdline[i];			
+		} else if (arg_flag.IsEqual("-db")) {
+			db = cmdline[i];			
+		} else if (arg_flag.IsEqual("-ip")) {
+			ip = cmdline[i];			
 		} else if (arg_flag.StartsWith("-")) {
 			//Error argument
@@ -160,11 +254,14 @@
 	}
 	
-	if (cmdline.GetCount()==0 || in.IsEmpty() || out.IsEmpty() || fmt.IsEmpty()) {
+	if (cmdline.GetCount()==0 || 
+	    ( (fmt.IsEqual("xml") || fmt.IsEqual("tsv")) && (in.IsEmpty() || out.IsEmpty() || fmt.IsEmpty()) ) ||
+	    ( fmt.IsEqual("mysql") && (in.IsEmpty() || user.IsEmpty() || db.IsEmpty() || ip.IsEmpty()) )
+	   ) {
 		Cout() << "# Usage #\n";
 		Cout() << "For linux:   GSEXmlParser -f (xml|tsv) -i (input file) -o (output file)\n";
 		Cout() << "For windows: GSEXmlParser.exe -f (xml|tsv) -i (input file) -o (output file)\n";
+		Cout() << "             GSEXmlParser.exe -f (mysql) -i (input file) -u (username) -p (password) -db (database) -ip (db host)\n";
 		exit(0);	
-	}
-	
+	}	
 	GSEParser parser;
 	parser.LoadXML(in);
@@ -173,8 +270,11 @@
 	else if (fmt.IsEqual("tsv"))	{
 		SaveFile(out,parser.ToTSV());
-	}
-	
-	
-	
-}
-
+	} else if (fmt.IsEqual("mysql")) {
+		parser.ToMySQL(user,pwd,db,ip);
+		Cout() << "Completed.\n";
+	}
+	
+	
+	
+}
+
