NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 54 55 56 57 58 … 93 Next »
How to use MSDE(SQL Server) as GBPVR Database

 
  • 0 Vote(s) - 0 Average
How to use MSDE(SQL Server) as GBPVR Database
KingArgyle
Offline

Posting Freak

Posts: 1,271
Threads: 95
Joined: Nov 2004
#101
2006-01-19, 06:46 PM
You should still be able to use aliases with SQL Server. Every program I've written for SQL Server has always used alias names.
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,723
Threads: 767
Joined: Nov 2003
#102
2006-01-19, 06:54 PM
Quote:trying to shoehorn a numeric into an int variable
An int varible is pretty much how we hold this data type in C#. For these identity fields I dont need to accommodate null, so I dont need to use an object to represent its value.

Quote:You could change programOID to be an System.Int32
This is effectively the equivalent of what I'm doing. Other than one being a primitive and the other being an object, both can represent negative 2,147,483,648 through positive 2,147,483,647. I dont believe this is the cause of the problem.

When you manually run the insert, then do a select @@identy, what value is returned?
Darryl
Offline

Junior Member

Posts: 15
Threads: 1
Joined: Jan 2006
#103
2006-01-19, 07:05 PM
sub Wrote:To be honest, I use this everywhere, and the idea of changing doesnt sound like fun. I originally picked up this syntax from SQL Server 6.5, so I'm surprised its no longer used. It also works in fine Oracle. It was particularly useful for when the subquery contained the same table as the outer query - using the alias would make it clear exactly which one you were talking about.


Looking deeper at the SQL syntax indicates that this can be used for SELECT statements as long as the 'AS' keyword appears between the table name and the alias.

eg: Select * from PROGRAMME AS P where p.oid = 100


However, it doesnt work in the simple DELETE statement.

eg: Delete from PROGRAMME as P where p.oid = 100


You CAN use aliases where referencing another select during the delete.


FROM <table_source>

Specifies an additional FROM clause. This Transact-SQL extension to DELETE allows you to specify data from <table_sources> and delete corresponding rows from the table in the first FROM clause.

This extension, specifying a join, can be used instead of a subquery in the WHERE clause to identify rows to be removed.

table_name [[AS] table_alias ]
Is the name of the table to provide criteria values for the delete operation.


eg: DELETE from authors FROM (SELECT TOP 10 * FROM authors) AS t1
WHERE authors.au_id = t1.au_id

In Summary, the aliases can be used in SELECT statements with the 'AS' keyword, but not in simple delete statements.

Darryl
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,723
Threads: 767
Joined: Nov 2003
#104
2006-01-19, 07:11 PM
My understanding is the "AS" is optional. Its even shown that way in the Microsoft, including your cut & paste above, with [AS] being represented in square brackets meaning it is optional.
Darryl
Offline

Junior Member

Posts: 15
Threads: 1
Joined: Jan 2006
#105
2006-01-19, 07:26 PM
sub Wrote:An int varible is pretty much how we hold this data type in C#. For these identity fields I dont need to accommodate null, so I dont need to use an object to represent its value.

This is effectively the equivalent of what I'm doing. Other than one being a primitive and the other being an object, both can represent negative 2,147,483,648 through positive 2,147,483,647. I dont believe this is the cause of the problem.

When you manually run the insert, then do a select @@identy, what value is returned?


A numeric data type is larger than the integer data type.

Integer
Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647).

Numeric
Fixed precision and scale numeric data from -10^38 +1 through 10^38 –1.


While the value returned is within the integer range ie 17620, its in a numeric data type. The code says to squash the numeric data type (9 bytes) into an integer (4 bytes)


In my case, the @@IDENTITY query returns 17620.

Looks like it needs to be bigger than Int32...


double dblprogramOID = System.Decimal.ToDouble(returnObject);
int programOID = dblprogramOID


Darryl
Darryl
Offline

Junior Member

Posts: 15
Threads: 1
Joined: Jan 2006
#106
2006-01-19, 07:37 PM
sub Wrote:My understanding is the "AS" is optional. Its even shown that way in the Microsoft, including your cut & paste above, with [AS] being represented in square brackets meaning it is optional.


Just to clarify things..


Query Analyser will not accept these.

DELETE from PROGRAMME as p where oid > 0
> Incorrect syntax near the keyword 'as'.

delete from PROGRAMME p where oid > 0
> Incorrect syntax near 'p'.

It will accept these..

delete from PROGRAMME where oid > 0

Select * from PROGRAMME as P where oid > 0

Select * from PROGRAMME P where oid > 0


It appears that the DELETE command cannot have table aliases unless there is a sub query to select rows to be deleted.


Darryl
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,723
Threads: 767
Joined: Nov 2003
#107
2006-01-19, 07:37 PM
Quote:A numeric data type is larger than the integer data type.

Integer
Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647).

Numeric
Fixed precision and scale numeric data from -10^38 +1 through 10^38 –1.
Yes, it can potentially be bigger than an integer, but from what I knew about the way I use data I felt safe that I would never get anywhere near an identity greater than 2^31 - 1. I asked you want SQL Server is generating for its identity on the off-chance it uses some seed values that causes it to start counting at some incredibly high number (which I wouldnt expect).

Quote:While the value returned is within the integer range ie 17620, its in a numeric data type. The code says to squash the numeric data type (9 bytes) into an integer (4 bytes)

In my case, the @@IDENTITY query returns 17620.

Looks like it needs to be bigger than Int32...
No, that is not correct. There is no problem with using the method I mentioned in my earlier to retrieve this numeric 17620 into a 32 bit integer. It would have been a problem if it had been larger than 2^31 - 1.
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,723
Threads: 767
Joined: Nov 2003
#108
2006-01-19, 07:39 PM
Quote:Query Analyser will not accept these.

DELETE from PROGRAMME as p where oid > 0
> Incorrect syntax near the keyword 'as'.

delete from PROGRAMME p where oid > 0
> Incorrect syntax near 'p'.

It will accept these..

delete from PROGRAMME where oid > 0

Select * from PROGRAMME as P where oid > 0

Select * from PROGRAMME P where oid > 0

It appears that the DELETE command cannot have table aliases unless there is a sub query to select rows to be deleted.
If you can provide the equivalent SQL for any of these you find in your testing, I'm happy to change them in my next release.
Darryl
Offline

Junior Member

Posts: 15
Threads: 1
Joined: Jan 2006
#109
2006-01-20, 01:56 AM (This post was last modified: 2006-01-20, 02:04 AM by Darryl.)
I've just read back over the thread and I've defined 2 separate problems that are not related and I've mixed them up together and confused everyone including me.

My apologies for that.


The

"delete from PROGRAMME p ..." Incorrect syntax near 'p'.

error can be resolved by removing the 'p' altogether. It has nothing to do with the @@IDENTITY code.


The 'invalid cast' error also has nothing to do with the @@IDENTITY code. That looks to be something else do do with storing channels.


Darryl
sub
Offline

Administrator

NextPVR HQ, New Zealand
Posts: 106,723
Threads: 767
Joined: Nov 2003
#110
2006-01-20, 02:06 AM
No, I cant do that. You cant gaurantee no other records have been inserted between the original insert and the select (without adding transaction control around every occurance of this). Its pretty unlikely to occur, but is possible. Also, @@identy was really intended to be used exactly the way I'm using, and avoids this potenial problem.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (15): « Previous 1 … 9 10 11 12 13 … 15 Next »
Jump to page 


Possibly Related Threads…
Thread Author Replies Views Last Post
  Determine Server Tuner/Recorder Status from Console App 27InchSony 13 8,301 2016-12-21, 05:03 AM
Last Post: mvallevand
  Looking for C# UPnP Media Server code bgowland 5 7,650 2016-12-16, 08:25 PM
Last Post: mvallevand
  TitanTv Remote Schedule For GBPVR UncleJohnsBand 51 33,731 2015-08-20, 05:11 PM
Last Post: sub
  Delete recordings from database but not from disk? spinnaker 8 3,826 2013-10-26, 10:51 PM
Last Post: spinnaker
  trying to fake npvr database for unit tests reven 3 2,266 2013-05-20, 08:53 AM
Last Post: reven
  Roku & GBPVR pvruser 16 11,523 2011-10-16, 08:31 PM
Last Post: pvruser
  (Yet Another) Rename Helper script for GBPVR & NPVR pvruser 2 2,736 2011-07-22, 01:27 AM
Last Post: pvruser
  Merged database queries mvallevand 4 2,094 2011-06-26, 09:56 PM
Last Post: mvallevand
  NPVR database questions mvallevand 25 9,875 2011-01-06, 12:58 AM
Last Post: jksmurf
  NPVR database - why so stringy with the fields?? :0) carpeVideo 4 2,039 2010-09-21, 01:48 AM
Last Post: sub

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

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

Linear Mode
Threaded Mode