Example #1
0
        public bool ExecuteCommands_Insert <T>(DataModelFactory <T> dataModelFactory, List <T> dataModels) where T : DataModel
        {
            if (!dataModels.Any())
            {
                return(false);
            }

            var sqliteCommands = new List <SqliteCommand>();

            for (int i = 0; i < dataModels.Count; i++)
            {
                sqliteCommands.Add(dataModelFactory.GetCommand_Insert(dataModels[i] as T));
            }

            ExecuteCommands_Insert(sqliteCommands);
            return(true);
        }
Example #2
0
        public bool CreateAndPopulateTableIfNotExists <T>(DataModelFactory <T> dataModelFactory, List <T> dataModels) where T : DataModel
        // public bool CreateAndPopulateTableIfNotExists(IDataModelFactory dataModelFactory, List<IDataModel> dataModels)
        {
            if (DoesExist_Table(dataModelFactory.TableName))
            {
                return(false);
            }

            CreateTableIfNotExists(dataModelFactory);
            if (dataModels != null)
            {
                LogInDebugMode($"Generated {dataModels.Count} Rows");
                return(ExecuteCommands_Insert(dataModelFactory, dataModels));
            }

            return(true);
        }
Example #3
0
        /*
         * public void ExecuteReader_BasicSelect<T>(DataModelFactory<T> modelFactory, bool selectAll = true, int pageSize = 0, int startIndex = 0) where T : DataModel
         * {
         *  modelFactory.DataModels.Clear();
         *
         *  var query = modelFactory.GetCommandText_BasicSelect(selectAll, pageSize, startIndex);
         *
         *  try
         *  {
         *      using (var dbConnection = new SqliteConnection(Connection))
         *      {
         *          dbConnection.Open();
         *
         *          using (var dbCmd = dbConnection.CreateCommand())
         *          {
         *              dbCmd.CommandText = query;
         *
         *              using (var reader = dbCmd.ExecuteReader())
         *              {
         *                  int index;
         *                  while (reader.Read())
         *                  {
         *                      index = 0;
         *                      modelFactory.GenerateAndGetDataModel(reader, ref index);
         *                  }
         *                  reader.Close();
         *              }
         *          }
         *
         *          dbConnection.Close();
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      LogSQLQueryErrorInDebugMode(query, ex);
         *  }
         * }
         */

        public virtual List <T> ExecuteReader_Select <T>(DataModelFactory <T> modelFactory, List <DataModel.IDataModelColumn> parameters = null, int pageSize = 0, int startIndex = 0) where T : DataModel
        {
            var result = new List <T>();
            var query  = modelFactory.GetCommandText_Select(parameters, pageSize, startIndex);

            try
            {
                using (var dbConnection = new SqliteConnection(Connection))
                {
                    dbConnection.Open();

                    using (var dbCmd = dbConnection.CreateCommand())
                    {
                        dbCmd.CommandText = query;
                        if (parameters != null)
                        {
                            for (int i = 0; i < parameters.Count; i++)
                            {
                                dbCmd.Parameters.Add(parameters[i].ToParameter());
                            }
                        }

                        using (var reader = dbCmd.ExecuteReader())
                        {
                            int index;
                            while (reader.Read())
                            {
                                index = 0;
                                result.Add(modelFactory.GenerateAndGetDataModel(reader, ref index));
                            }
                            reader.Close();
                        }
                    }

                    dbConnection.Close();
                }
            }
            catch (Exception ex)
            {
                LogSQLQueryErrorInDebugMode(query, ex);
            }

            return(result);
        }
Example #4
0
 public bool ExecuteCommands_Insert <T>(DataModelFactory <T> dataModelFactory, T dataModel) where T : DataModel
 {
     return(ExecuteCommands_Insert <T>(dataModelFactory, new List <T> {
         dataModel
     }));
 }
Example #5
0
 public void ExecuteCommand_Insert <T>(DataModelFactory <T> dataModelFactory, T dataModel) where T : DataModel
 {
     ExecuteCommand_Insert(dataModelFactory.GetCommand_Insert(dataModel));
 }
Example #6
0
        public bool CreateAndPopulateTableIfNotExists <T>(DataModelFactory <T> dataModelFactory) where T : DataModel
        {
            var presets = dataModelFactory.GeneratePresets();

            return(CreateAndPopulateTableIfNotExists(dataModelFactory, presets));
        }