private static void CreateTable( PetaPoco.Database db, string tableName, List<ColumnDefinition> columns ) { var pkColumn = columns.FirstOrDefault( delegate( ColumnDefinition d ) { return d.IsPrimaryKey; } ); var uniqueColumns = columns.FindAll( delegate( ColumnDefinition d ) { return d.OnlyAtCreate && ( pkColumn == null || pkColumn.Name != d.Name ); } ); string columnStrings = null; if( pkColumn != null ) columnStrings += GetColumnString( pkColumn ); foreach( var column in uniqueColumns ) columnStrings += ", " + GetColumnString( column ); string sql = "CREATE TABLE IF NOT EXISTS " + tableName; if( !string.IsNullOrEmpty( columnStrings ) ) sql += " ( " + columnStrings + " )"; db.Execute( sql ); }
public static void Resolve(PetaPoco.Database dataBase, string tipo, string tableName, int id) { dataBase.Execute("CALL RESOLVE_TABLE_RELATION_DEPENDENCY('" + tipo + "', '" + tableName + "', " + id + ")"); }
private bool CheckAndUpdateSajdas(PetaPoco.Database DBContext, IVerseRepository verseRepo) { if (DBContext != null && sajdas.Count > 0) { Debug.WriteLine(string.Format("Inserting sajda data: {0}", sajdas.Count)); foreach (int sajda in sajdas) { Verse vFound = verseRepo.Get(verse => verse.Chapter == this.ID && verse.Ayah == sajda); if (vFound != null) { if (DBContext.Execute("insert into Sajda(AyahId) values (@0)", vFound.Id) <= 0) { Debug.WriteLine("###### Error: chapter sajda data insertion failed ######"); return false; } } else { Debug.WriteLine("###### Error: chapter sajda data insertion failed. Couldn't find the related verse data from DB. ######"); return false; } } } return true; }
private bool CheckAndUpdateRukus(PetaPoco.Database DBContext, IVerseRepository verseRepo) { if (DBContext != null && rukus.Count > 0) { Debug.WriteLine(string.Format("Inserting ruku data: {0}", rukus.Count)); foreach (int ruku in rukus) { Verse vFound = verseRepo.Get(verse => verse.Chapter == this.ID && verse.Ayah == ruku); if (vFound != null) { if (DBContext.Execute("insert into Ruku(ScriptId, AyahId) values (@0, @1)", vFound.ScriptId, vFound.Id) <= 0) { Debug.WriteLine("###### Error: chapter ruku data insertion failed ######"); return false; } } else { Debug.WriteLine("###### Error: chapter ruku data insertion failed. Couldn't find the related verse data from DB. ######"); return false; } } } return true; }
private void Save(PetaPoco.Database db, int[] ChannelOids = null) { if (!IsShared) { this.Name = this.Name.Trim(); // sanity checks if (String.IsNullOrWhiteSpace(this.Name)) throw new ArgumentException("Name must not be blank."); if (db.FirstOrDefault<int>("select count(*) from channelgroup where useroid = @0 and name = @1 and oid <> @2", this.UserOid, this.Name, this.Oid) > 0) throw new ArgumentException("A group with the name '{0}' already exists.".FormatStr(this.Name)); } if (this.Oid == 0) // new group { this.OrderOid = db.FirstOrDefault<int>("select ifnull(max(orderoid),0) + 1 from channelgroup where useroid = @0", this.UserOid); if (this.IsShared) { // special case, insert missing shared, so need to make sure name isnt inserted as it comes from the parent channel group this.Name = ""; } db.Insert("channelgroup", "oid", true, this); if (this.Oid < 1) throw new Exception("Failed to insert channel group."); } else // update { // only allow updating of the name here.. maybe add order too? if(IsShared) db.Update(this, this.Oid, new string[] { "orderoid", "enabled" }); else db.Update(this, this.Oid, new string[] { "name", "orderoid" }); } if (ChannelOids != null && !IsShared) { // insert the channels db.Execute("delete from channelgroupchannel where channelgroupoid = @0", this.Oid); foreach (int channeloid in ChannelOids) db.Execute("insert into channelgroupchannel (channelgroupoid, channeloid) values (@0, @1)", this.Oid, channeloid); } }
private static void CreateTableColumns( PetaPoco.Database db, string tableName, List<ColumnDefinition> columns ) { var statements = new List<string>( ); var columnNames = GetDatabaseColumns( db, tableName ); foreach( var column in columns ) { if( column.Ignore ) continue; if( columnNames.Contains( column.Name ) ) continue; // These were added at the CREATE TABLE statement if( column.OnlyAtCreate ) continue; string sql = "ALTER TABLE " + tableName + " ADD COLUMN " + GetColumnString( column ); statements.Add( sql ); } foreach( string sql in statements ) db.Execute( sql ); }
private static void ExtraStuff( PetaPoco.Database db ) { db.Execute( "CREATE UNIQUE INDEX IF NOT EXISTS MemberDogIndex ON MemberDog ( MemberId, DogId )" ); }
public bool Delete(PetaPoco.Database db = null) { if (db == null) db = DbHelper.GetDatabase(); return db.Execute("delete from xmltvsource where oid=@0", this.Oid) > 0; }