NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 24 25 26 27 28 … 93 Next »
datetime format in GB-PVR

 
  • 0 Vote(s) - 0 Average
datetime format in GB-PVR
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#1
2009-03-16, 09:00 AM
I'm having a problem setting dateTime data types in the sqlite3 database

When I place a date, it saves into the database like

Code:
2009-03-26 10:00:00 PM

But I think it should look like

Code:
2009-03-24 09:00:00.0000000

the incorrect format breaks GB-PVR

I'm writing in VB .net.
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
psycik
Offline

Posting Freak

Posts: 5,210
Threads: 424
Joined: Sep 2005
#2
2009-03-16, 09:06 AM
tried using a creating a parameter object, setting the parameter value type then adding it to the dbcommand object.parameters collection?

Might be the best way to do it.

Parameters are placeheld in sql strings with "?"
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,953
Threads: 770
Joined: Nov 2003
#3
2009-03-16, 03:01 PM
Yep, what he said. You should be using parameter objects for dates, not formatted strings.
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#4
2009-03-16, 04:46 PM
Would you mind giving an example?
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,953
Threads: 770
Joined: Nov 2003
#5
2009-03-16, 04:56 PM
Code:
// try to find show with the same name and start time
DbCommand findProgrammeCommand = systemConfig.getDatabaseCommand("SELECT oid FROM PROGRAMME where name=? and start_time=?" , connection);
findProgrammeCommand.Parameters.Add(systemConfig.getDatabaseParameter("@name", System.Data.DbType.String));
findProgrammeCommand.Parameters.Add(systemConfig.getDatabaseParameter("@start_date", System.Data.DbType.DateTime));

findProgrammeCommand.Parameters[0].Value = title;
findProgrammeCommand.Parameters[0].Size = title.Length;
findProgrammeCommand.Parameters[0].DbType = System.Data.DbType.String;

findProgrammeCommand.Parameters[1].Value = startTime;
findProgrammeCommand.Parameters[1].DbType = System.Data.DbType.DateTime;
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#6
2009-03-16, 05:11 PM
sub Wrote:
Code:
// try to find show with the same name and start time
DbCommand findProgrammeCommand = systemConfig.getDatabaseCommand("SELECT oid FROM PROGRAMME where name=? and start_time=?" , connection);
findProgrammeCommand.Parameters.Add(systemConfig.getDatabaseParameter("@name", System.Data.DbType.String));
findProgrammeCommand.Parameters.Add(systemConfig.getDatabaseParameter("@start_date", System.Data.DbType.DateTime));

findProgrammeCommand.Parameters[0].Value = title;
findProgrammeCommand.Parameters[0].Size = title.Length;
findProgrammeCommand.Parameters[0].DbType = System.Data.DbType.String;

findProgrammeCommand.Parameters[1].Value = startTime;
findProgrammeCommand.Parameters[1].DbType = System.Data.DbType.DateTime;

So this retrieves the data into 'findProgrammeCommand' and you read the values out as parameters that have been 'shaped' by the datatypes. I think I get that. I haven't really bee having trouble retrieving from data base yet (I might someday)

How do you shape the data before it is sent into a record with an UPDATE or REPLACE ?
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,953
Threads: 770
Joined: Nov 2003
#7
2009-03-16, 05:54 PM
Using these types of 'prepared statements' is useful for several reasons. Setting parameters this way takes care of different format expectations of the different underlying databases, ie different databases can expect dates in different string formats.

It also provides very significant performance improvements when the same statement needs to be executabled several times with only the parameters varying on each execution.
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#8
2009-03-16, 06:17 PM
I don't have to set stuff into the db often or quickly, but I guess I should learn the best way, just in case

I have been trying to create routine that will send all comums to the SQL statement. Just before I send the data to the record, I change the data.

so here's is my SQL text. 'myDB_Rec_Sched' is a single record class that was filled with existing data. I should then just change one thing or another, send the text to ExceuteNoQuery


Code:
With myDB_Rec_Sched
            'theis record is indexed on oid, so there's no changing it...
            SQLText = "UPDATE OR REPLACE RECORDING_SCHEDULE SET " & _
                    "capture_source_oid = " & .capture_source_oid & "" & _
                    ", status = " & .status & "" & _
                    ", filename = '" & [B].filename[/B] & "'" & _
                    ", recording_type = " & .recording_type & "" & _
                    ", recording_group = " & .recording_group & "" & _
                    ", manual_start_time = '" & .manual_start_time & "'" & _
                    ", manual_end_time = '" & .manual_end_time & "'" & _
                    ", manual_channel_oid = " & .manual_channel_oid & "" & _
                    ", quality_level = " & .quality_level & "" & _
                    ", pre_pad_minutes = " & .pre_pad_minutes & "" & _
                    ", post_pad_minutes = " & .post_pad_minutes & "" & _
                    ", priority = " & .priority & "" & _
                    ", conversion_profile = '" & .conversion_profile & "'" & _
                    ", renamed = " & .renamed & " " & _
                    "WHERE programme_oid =" & param_programme_oid

When I set this up,

Code:
NewFileName = Blah blah

                With myDB_Rec_Sched
                    [B].filename[/B] = NewFileName
                End With

OK. So my problem is that I have to build a Parameter object (supposedly reuseable)

I created a public Object "MyParameters". In another routine I fill 'My Parameters' with parameters

Code:
Dim command As DbCommand = dbProviderFactory.CreateParameter()

        With command
            .Parameters.Add("@manual_start_time")
            .Parameters(0).DbType = System.Data.DbType.DateTime
            .Parameters(0).Value = myDB_Rec_Sched.manual_start_time

            .Parameters.Add("@manual_end_time")
            .Parameters(1).DbType = System.Data.DbType.DateTime
            .Parameters(1).Value = myDB_Rec_Sched.manual_end_time

        End With

        myParameters = command

Now I have this object with the same structure as the Parameters object. I just have to copy it over just before I call the ExcuteNonQuery.

So I have a structure with my parameters, and datatypes
I have my instance structure I want to write to record.

I just don't know how to reference the paramaters structure.

(Thanks for everyones patience. I'm having trouble learning new words AND learning new C# words...)
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
zehd
Offline

Posting Freak

Posts: 5,119
Threads: 249
Joined: Feb 2006
#9
2009-03-16, 06:29 PM
K... THis is C I got from an example on the net. I can't understand something though

Code:
command.CommandText = "insert into items (id, name, icon, level, quality, type) values (?1, ?2, ?3, ?4, ?5, ?6);";
                    command.Parameters.Add(item_id);
                    command.Parameters.Add(item_name);
                    command.Parameters.Add(item_icon);
                    command.Parameters.Add(item_level);
                    command.Parameters.Add(item_quality);
                    command.Parameters.Add(item_type);

Obviously, In C#, you can 'add', and the parameters are auto given the index, (and I read the index starts from 1)

So referencing the parameters, ?1 references the first parameter and so on...

In keeping with this example, I I wanted to set the data type for the first parameter would I type something like

Code:
command.Parameters.Add(item_id);
[B]command.Parameters.(1).DbType = System.Data.DbType.DateTime        [/B]            
command.Parameters.Add(item_name);
command.Parameters.Add(item_icon);
command.Parameters.Add(item_level);
command.Parameters.Add(item_quality);
command.Parameters.Add(item_type);
Frank Z
[COLOR="Gray"]
I used to ask 'why?' Now I just reinstall...
[SIZE="1"]______________________________________________
Author: ZTools: ZProcess, MVPServerChecker; UltraXMLTV Enhancer, Renamer, Manager; [/SIZE]
[/COLOR]
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,953
Threads: 770
Joined: Nov 2003
#10
2009-03-16, 06:42 PM
Sorry, I know nothing about VB.Net syntax. I'm sure googling "VB.NET Prepared Statements" will return some examples.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): 1 2 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  How Does "Use S01E01 File naming format if possible" work puck64 7 5,803 2015-08-25, 10:21 AM
Last Post: puck64
  EPG_EVENT.genres format bgowland 2 2,477 2014-08-10, 05:49 AM
Last Post: bgowland
  N-PVR db3 EPG_EVENT time format question bgowland 3 2,339 2011-03-12, 05:26 AM
Last Post: bgowland
  Access DB and DateTime idkpmiller 5 2,654 2008-04-14, 10:37 AM
Last Post: idkpmiller
  What format to post a plugin? McBainUK 5 2,494 2005-10-28, 12:31 AM
Last Post: sub
  Error: input string was not in a correct format sisuomin 6 3,504 2004-05-11, 08:56 PM
Last Post: Dai

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode