public List<Table> GetTables(string serverName, string databaseName) { var res = new List<Table>(); string conString = string.Format("Data Source={0}; Initial Catalog={1}; Integrated Security=true; Connect Timeout=5;", serverName, databaseName); using (SqlConnection con = new SqlConnection(conString)) { con.Open(); using (SqlCommand cmd = new SqlCommand("SELECT sobjects.name FROM sysobjects sobjects WHERE sobjects.xtype = 'U'", con)) { using (IDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { var tmpTable = new Table(dr[0].ToString()); tmpTable.Columns = GetTableColumns(serverName, databaseName, tmpTable.TableName); res.Add(tmpTable); } } } } return res; }
public string GetMainTypeClass(Table table, bool ParcelableFunctions, bool FromJSon_Function, bool FromCursor_Function, string javaPackageName) { var res = Properties.Resources.ClassDef; res = res.Replace("{PackageName}", javaPackageName); var declarationsList = new List<string>(); var columnNamesAsStringList = new List<string>(); var constructorAssignmentList = new List<string>(); var constructorParametersList = new List<string>(); var parcelAssignmentList = new List<string>(); var writeToParcelList = new List<string>(); var parcelToStringList = new List<string>(); var fromJSonList = new List<string>(); var fromCursorList = new List<string>(); var toStringList = new List<string>(); foreach (var item in table.Columns) { // variable declarations declarationsList.Add(item.AsJavaPropertyDeclaration()); // Column Names as string for strongly coding columnNamesAsStringList.Add(string.Format("public static String Column_{0} = \"{0}\";", item.ColumnName)); // Constructor parameters constructorParametersList.Add(item.AsJavaParameter()); // Constructor assignments constructorAssignmentList.Add(item.AsConstructorAssignment()); // Parcel assignments constructor parcelAssignmentList.Add(item.AsParcelAssignment()); // Write to Parcel writeToParcelList.Add(item.AsWriteToParcel()); // ToString() if (item.IsPK) parcelToStringList.Add(string.Format("\"{0}: \" + this.{0}", item.ColumnName)); // FromJSon fromJSonList.Add(item.AsFromJSon()); // FromCursor fromCursorList.Add(item.AsFromCursor()); // toString() toStringList.Add(string.Format("\", {0}: \" + this.{0}", item.ColumnName)); } res = res.Replace("{ConstructorParameters}", string.Join(", ", constructorParametersList)); res = res.Replace("{ConstructorAssignments()}", string.Join("\n\t\t", constructorAssignmentList)); res = res.Replace("{PropertyDeclaration()}", string.Join("\n\t", declarationsList)); res = res.Replace("{columnNamesAsStringList()}", string.Join("\n\t", columnNamesAsStringList)); res = res.Replace("{ParcelAssignments()}", string.Join("\n\t\t", parcelAssignmentList)); res = res.Replace("{WriteToParcel()}", string.Join("\n\t\t", writeToParcelList)); res = res.Replace("{ParcelToString()}", string.Join(" + \"\\n\" + ", parcelToStringList).Replace("\" + \"", "")); res = res.Replace("{FromJSonAssignment()}", string.Join("\n\t\t", fromJSonList)); res = res.Replace("{FromCursorAssignment()}", string.Join("\n\t\t", fromCursorList)); res = res.Replace("{ToString()}", "\"" + string.Join(" + ", toStringList).Substring("\", ".Length)); res = res.Replace("{TableName}", table.TableName); return res; }
public string GetOpenHelperClass(Table table, string androidDatabaseName, string javaPackageName) { var res = Properties.Resources.OpenHelper; res = res.Replace("{PackageName}", javaPackageName); res = res.Replace("{TableName}", table.TableName); res = res.Replace("{DatabaseName}", androidDatabaseName); // add columns // this.{TableName}Table.AddColumn("{FieldName}", "{DataType}", false, false); var tmp = new List<string>(); foreach (var item in table.Columns) { tmp.Add("this.{TableName}Table.AddColumn(\"{FieldName}\", \"{DataType}\", false, false);".Replace("{TableName}", table.TableName) .Replace("{FieldName}", item.ColumnName) .Replace("{DataType}", item.SQLiteDataType)); } res = res.Replace("{AddColumns()}", string.Join("\n\t\t", tmp)); return res; }
public string GetDataSourceClass(Table table, string androidDatabaseName, string javaPackageName) { var res = Properties.Resources.DataSource; res = res.Replace("{PackageName}", javaPackageName); var tmpColNames = new List<string>(); var tmpInsert = new List<string>(); var tmpUpdate = new List<string>(); tmpColNames.Add("\"1 as _id\""); // for cursors foreach (var item in table.Columns) { // add column names tmpColNames.Add("\"{FieldName}\"".Replace("{FieldName}", item.ColumnName)); // insert function // values.put("{FieldName}", new{TableName}Values.{FieldName}); tmpInsert.Add("values.put(\"{FieldName}\", new{TableName}Values.{FieldName});".Replace("{FieldName}", item.ColumnName)); // update function // values.put("{FieldName}", new{TableName}Values.{FieldName}); if (!item.IsPK) tmpUpdate.Add("values.put(\"{FieldName}\", new{TableName}Values.{FieldName});".Replace("{FieldName}", item.ColumnName)); } // where clauses var pks = table.GetPrimaryKeyColumns(); res = res.Replace("{WhereClausesCount}", pks.Count.ToString()); var tmpWhereList = new List<string>(); var tmpDeleteParamsList = new List<string>(); for (int i = 0; i < pks.Count; i++) { var whereString = (pks[i].JavaDataType != "String") ? "whereArgs[{whereArgItemIndex}] = String.valueOf(new{TableName}Values.{FieldName});" : "whereArgs[{whereArgItemIndex}] = new{TableName}Values.{FieldName};"; tmpWhereList.Add(whereString.Replace("{whereArgItemIndex}", i.ToString()) .Replace("{FieldName}", pks[i].ColumnName)); tmpDeleteParamsList.Add(string.Format("{0} {1}", pks[i].JavaDataType, pks[i].ColumnName)); } res = res.Replace("{ColumnNames()}", string.Join(",\n\t\t", tmpColNames)); res = res.Replace("{InsertParameterValues()}", string.Join("\n\t\t", tmpInsert)); res = res.Replace("{UpdateParameterValues()}", string.Join("\n\t\t", tmpUpdate)); res = res.Replace("{WhereArgsList()}", string.Join("\n\t\t", tmpWhereList)); res = res.Replace("{DeleteWhereArgsList()}", string.Join("\n\t\t", tmpWhereList).Replace("new{TableName}Values.", "")); res = res.Replace("{DeleteParams()}", string.Join(", ", tmpDeleteParamsList)); var tmpWhereClauseList = pks.Select(w => w.ColumnName + " = ?").ToList(); res = res.Replace("{WhereClauseString}", string.Join(" and ", tmpWhereClauseList)); res = res.Replace("{TableName}", table.TableName); res = res.Replace("{DatabaseName}", androidDatabaseName); var tmpPKsAsParameterValuesFromObjectVariableList = pks.Select(w=> string.Format("new{0}Values.{1}", table.TableName, w.ColumnName)); res = res.Replace("{PKsAsParameterValuesFromObjectVariable}", string.Join(", ", tmpPKsAsParameterValuesFromObjectVariableList)); return res; }