@* CUT FROM case import_library (MOVED to sospep.
var db_src = Database.Open(@Session["current_db"].ToString());
// NEED = GET conn string name of user selected db, use dbid to look it up in db_owners table OR used jq to pull from select box:selected text
// Select sName from db_owner WHERE id = dbID
var db_dest = Database.Open(destination_sospep);
// GET LIBRARY record
var srcLibrary = db_src.QuerySingle("select * from libraries WHERE id_library=@0",srcLibraryId);
// GET BOOKSinLIBRARY
var srcBooks = db_src.Query("select * from books WHERE parent_id=@0",srcLibraryId);
// PUT BOOKSinLIBRARY
sqlQ="INSERT INTO libraries (name_library,description_library) VALUES (@0,@1)";
db_dest.Execute(sqlQ, srcLibrary.name_library, srcLibrary.description_library);
// PUT THE BOOKS into the destination library
// NEED the id of the library in the destination library
var destLibId = db_dest.QueryValue("SELECT id_library FROM libraries WHERE name_library =@0",srcLibrary.name_library);
sqlQ1="INSERT INTO books (name_book,description_book,parent_id) VALUES (@0,@1,@2)";
// +] NEXT= REPLACE this loop w/ SELECT INTO
// SELECT INTO `destination`.`libraries (SELECT * from `src.libraries WHERE id_library=@0")
foreach(var book in srcBooks) {
db_dest.Execute(sqlQ1, book.name_book, book.description_book,destLibId);
// REV bookIds.Add(book.id_book);
// REV books=books+book.id_book.ToString()+",";
}
// GET the chapters in this book
// var sqlQ2 = "select * from chapters where parent_id IN ("+ bookIds.ToString()+")";
// ERROR - looks like doesnt
//REV // books = books.TrimEnd(',');
@* WORKING - STRUCTURE ONLY - INSERT chapters into each book * @
foreach (var book in srcBooks){
// var bk_id=book.id_book;
var destBkId = db_dest.QueryValue("SELECT id_book FROM books WHERE name_book =@0",book.name_book);
srcChapters =db_src.Query("SELECT * FROM chapters WHERE parent_id=@0",book.id_book);
foreach (var chapter in srcChapters){
sqlQ3 = "INSERT INTO chapters (name_chapter,description_chapter,parent_id) VALUES (@0,@1,@2)";
db_dest.Execute(sqlQ3, chapter.name_chapter, chapter.description_chapter,destBkId);
}
}
@* STRUCTURE + CONTENT (articles) - insert articles into chapters * @
foreach (var book in srcBooks){
// var bk_id=book.id_book;
var destBkId = db_dest.QueryValue("SELECT id_book FROM books WHERE name_book =@0",book.name_book);
srcChapters =db_src.Query("SELECT * FROM chapters WHERE parent_id=@0",book.id_book);
foreach (var chapter in srcChapters){
// var bk_id=book.id_book;
var destChId = db_dest.QueryValue("SELECT id_chapter FROM chapters WHERE name_chapter=@0",chapter.name_chapter);
srcArticles =db_src.Query("SELECT * FROM articles WHERE parent_id=@0",chapter.id_chapter);
foreach (var article in srcArticles){
sqlQ4 = "INSERT INTO articles (name_article,description_article,parent_id,content_article,content_format,priority,photo,status,owner) VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8)";
db_dest.Execute(sqlQ4, article.name_article, article.description_article,destChId,article.content_article,article.content_format,article.priority,article.photo,article.status,article.owner);
}
}
}
//Response.Redirect("~/");
*@
IMPORT BOOK moved to sospep.
@*
// SET src_db, dest_db
db_src = Database.Open(@Session["current_db"].ToString());
db_dest = Database.Open(destination_sospep);
sqlQ4 = "INSERT INTO articles (name_article,description_article,parent_id,content_article,content_format,priority,photo,status,owner) VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8)";
// GET BOOKinLIBRARY to EXPORT - have book id
// var srcBook = db_src.QuerySingle("select * from books WHERE parent_id=@0",srcLibraryId);
var srcBook = db_src.QuerySingle("select * from books WHERE id_book=@0",srcBookId);
// PUT BOOKinLIBRARY
sqlQ1="INSERT INTO books (name_book,description_book,parent_id) VALUES (@0,@1,@2)";
db_dest.Execute(sqlQ1,srcBook.name_book,srcBook.description_book,destLibraryId);
// REV + 2nd conditon
// GET id of book we just added
destBkId2 = db_dest.QueryValue("SELECT (id_book) from books WHERE name_book=@0 && parent_id=@1",srcBook.name_book,destLibraryId);
// GET - all the CHAPTERS from the srcBOOK
srcChapters = db_src.Query("select * from chapters WHERE parent_id=@0",srcBook.id_book);
// PUT - each chapter into the destination library
sqlQ3 = "INSERT INTO chapters (name_chapter,description_chapter,parent_id) VALUES (@0,@1,@2)";
foreach (var chapter in srcChapters){
srcArticles = db_src.Query("SELECT * FROM articles WHERE parent_id=@0",chapter.id_chapter);
db_dest.Execute(sqlQ3, chapter.name_chapter, chapter.description_chapter, destBkId2);
// var destBKId = db_dest.QueryValue("SELECT id_book FROM books WHERE name_book=@0",chapter.name_cha);
// REV - WORKS add parent-par to see if why no articles
destChId2 = db_dest.QueryValue("SELECT id_chapter FROM chapters WHERE name_chapter=@0 && parent_id=@1",chapter.name_chapter,destBkId2);
foreach (var article in srcArticles){
sqlQ4 = "INSERT INTO articles (name_article,description_article,parent_id,content_article,content_format,priority,photo,status,owner) VALUES (@0,@1,@2,@3,@4,@5,@6,@7,@8)";
db_dest.Execute(sqlQ4, article.name_article, article.description_article,destChId2,article.content_article,article.content_format,article.priority,article.photo,article.status,article.owner);
}
}
*@
IMPORT CHAPTER moved to sospep.