help wanted (1 Viewer)

lar282

Portal Pro
July 11, 2004
414
2
Hi
I need some help with my plugin. Somebody wants to help me out?

1/ How do I CLEAR a database? I want to delete all the records, but I can't delete the file itself because MP is locking it.

2/ How do I refresh a view in MP. Example. the skin shows a database content, and the user presses refresh to load a new file in the database. How do I make that new information show up on the screen. Is there a function in MP to RELOAD the screen?


Thanks in advance

//Lasse
 

samuel337

Portal Pro
August 25, 2004
772
0
Melbourne, Australia
lar282 said:
Hi
I need some help with my plugin. Somebody wants to help me out?

1/ How do I CLEAR a database? I want to delete all the records, but I can't delete the file itself because MP is locking it.

2/ How do I refresh a view in MP. Example. the skin shows a database content, and the user presses refresh to load a new file in the database. How do I make that new information show up on the screen. Is there a function in MP to RELOAD the screen?


Thanks in advance

//Lasse

To clear the database, simply use this SQL for each table in the database:
Code:
 DELETE FROM <table name>

For example,
Code:
 DELETE FROM programs
to delete all the tv programs in TVDatabase.

To make MP reload the screen, it depends on what screen, but for most screens with a list in it, just call the LoadDirectory("") method (check to see if it exists - I know it works for the music module).

Sam
 

lar282

Portal Pro
July 11, 2004
414
2
still to dumb

So if I wanted to delete all records in the table DVD, should it look like this

DVD_DB myDVD_db=null;
// Open Database
myDVD_db = new DVD_DB();
myDVD_db.Execute DELETE FROM dvd


Well I know it should look like that since I get a expexted ; here and there, but I can't figure it out. Can u help me some more, please


//Lasse
 

samuel337

Portal Pro
August 25, 2004
772
0
Melbourne, Australia
Re: still to dumb

lar282 said:
So if I wanted to delete all records in the table DVD, should it look like this

DVD_DB myDVD_db=null;
// Open Database
myDVD_db = new DVD_DB();
myDVD_db.Execute DELETE FROM dvd


Well I know it should look like that since I get a expexted ; here and there, but I can't figure it out. Can u help me some more, please


//Lasse

Well first off, there is no DVD database so I'm going to use the video database as an example.

Another thing, in MP you can't use the existing code to clear the database (i.e. reference Databases.dll and use the functions in there) because there is no function to clear the database and you can't access the database variable directly (its not public). So you will need your own code to open the database connection:

Code:
function ClearDatabase() 
{
SQLiteClient m_db=null;
 Log.Write("opening video database");
      try 
      {
        // Open database
				try
				{
        System.IO.Directory.CreateDirectory("database");
				}
				catch(Exception){}
				m_db = new SQLiteClient(@"database\videodatabase2.db");
      } 
      catch (Exception ex) 
      {
        Log.Write("videodatabase exception err:{0} stack:{1}", ex.Message,ex.StackTrace);
      }
      
      Log.Write("video database opened");

//now for each table, do this, replacing movie with the table name.
m_db.Execute("DELETE FROM movie");

//close and dispose of the database
m_db.Close();
m_db = null;
}

EDIT:
whoops, forgot to tell you that you need to add the following statements at the top of the file:
Code:
using SQLite.NET;
using MediaPortal.Util;

HTH

Sam
 

Users who are viewing this thread

Top Bottom