//Dictionary<string, string> GetTableInfo(string databaseName, string filterName) //{ // Dictionary<string, string> tableInfo = new Dictionary<string, string>(); // string sqlString = "select * from sqlite_master WHERE type = \"table\""; // using (SQLiteCommand cmd = mSqliteConn.CreateCommand()) // { // cmd.CommandText = sqlString; // SQLiteDataAdapter da = new SQLiteDataAdapter(cmd); // DataTable dt = new DataTable(); // da.Fill(dt); // DataColumn nameCol = dt.Columns["name"]; // foreach (DataRow row in dt.Rows) // { // string key = row[nameCol].ToString(); // if (filterName != "") // { // Regex regex = new Regex(@"^[" + filterName + "]"); // if (!regex.IsMatch(key)) // { // continue; // } // } // tableInfo.Add(key, null); // //System.Diagnostics.Trace.WriteLine("Unhandled sqlite type [" + + "]"); // } // } // return tableInfo; //} //string GetString(SQLiteDataReader reader, string ordinal) //{ // return reader.GetString(reader.GetOrdinal(ordinal)); //} ///// <summary> ///// Convsert specified xml file to cs file object ///// </summary> CSFile ConvertTable(string xmlFile, string[] impledInterface) { CSFile writer = new CSFile(); writer.name = Path.GetFileName(xmlFile); //read xml file writer.AddReferencedLib("System"); CSClass classObj = writer.AddCSClass("public", writer.name, impledInterface); using (XmlReader reader = XmlReader.Create("")) { XmlSchemaInference schema = new XmlSchemaInference(); XmlSchemaSet schemaSet = schema.InferSchema(reader); //schemaSet. } // string sqlString = string.Format("PRAGMA table_info([{0}]);", tableName); // using (SQLiteCommand cmd = mSqliteConn.CreateCommand()) // { // cmd.CommandText = sqlString; // //using // writer.AddReferencedLib("System"); // CSClass classObj = writer.AddCSClass("public", tableName, impledInterface); // SQLiteDataAdapter da = new SQLiteDataAdapter(cmd); // DataTable dt = new DataTable(); // da.Fill(dt); // DataColumn nameCol = dt.Columns["name"]; // DataColumn typeCol = dt.Columns["type"]; // CSParseFunc parseFunc = new CSParseFunc("public", tableName, "ReadData"); // CSVar dataForm = parseFunc.AddParam(string.Empty, "ASteinGameDataHolder", "dataForm"); // classObj.AddFuncDeclare(parseFunc); // foreach (DataRow row in dt.Rows) // { // CSField dataVar = classObj.AddVar("public", SqliteType2CsType(row[typeCol].ToString()), row[nameCol].ToString()); // CSFuncCall parseCall = new CSFuncCall(string.Empty, SqliteType2CsType(row[typeCol].ToString()), SqliteType2CsReadType(row[typeCol].ToString())); // parseCall.AddParam("string", row[nameCol].ToString()); // parseCall.targetObj = dataForm; // parseCall.returnVar = dataVar; // parseFunc.AddParseCall(parseCall); // } // } // //System.Diagnostics.Trace.WriteLine(writer.GenerateFilsString()); return(writer); }
/// <summary> /// Convsert specified data table to cs file object /// </summary> /// <param name="dBName"></param> /// <param name="tableName"></param> /// <param name="comment"></param> /// <param name="impledInterface"></param> /// <returns></returns> CSFile ConvertTable(string dBName, string tableName, string comment, string[] impledInterface) { CSFile writer = new CSFile(); string sqlString = string.Format("PRAGMA table_info([{0}]);", tableName); using (SQLiteCommand cmd = mSqliteConn.CreateCommand()) { cmd.CommandText = sqlString; //using writer.AddReferencedLib("System"); CSClass classObj = writer.AddCSClass("public", tableName, impledInterface); SQLiteDataAdapter da = new SQLiteDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); DataColumn nameCol = dt.Columns["name"]; DataColumn typeCol = dt.Columns["type"]; CSParseFunc parseFunc = new CSParseFunc("public", tableName, "ReadData"); CSVar dataForm = parseFunc.AddParam(string.Empty, "ASteinGameDataHolder", "dataForm"); classObj.AddFuncDeclare(parseFunc); foreach (DataRow row in dt.Rows) { CSField dataVar = classObj.AddVar("public", SqliteType2CsType(row[typeCol].ToString()), row[nameCol].ToString()); CSFuncCall parseCall = new CSFuncCall(string.Empty, SqliteType2CsType(row[typeCol].ToString()), SqliteType2CsReadType(row[typeCol].ToString())); parseCall.AddParam("string", row[nameCol].ToString()); parseCall.targetObj = dataForm; parseCall.returnVar = dataVar; parseFunc.AddParseCall(parseCall); } } //System.Diagnostics.Trace.WriteLine(writer.GenerateFilsString()); return(writer); }