I was testing the code of my colleague and wrote somments for each statement like this:
/*Creating the list of IDs*/
Select ID from table1
Everything worked fine until I saved the Query, closed the session and then started the new one with the same Query.
Now if there is a comment, it results with the error "Query is invalid".
If I delete the comment and write the new one on the same place - it works! LOL
WTF is that?!
thx
Related
I wrote a query where I misspelled the alias I was using (this is pseudocode)
SELECT
ma.name
FROM mytable my
Teradata SQL Assistant did not give its usual error message saying ma does not exist, but ran for a long time and spooled out. I believe Teradata was processing all the rows in mytable.
When I changed the column selector to my.name the query ran as expected.
My question is, is it possible to see what Teradata SQL Assistant thinks the value of ma is?
Is there some setting which might define the default value of ma?
ma is not a column name in mytable
I am using Xojo 2013 Version 1. I am trying to delete a record from a SQLite database. But I am failing miserably. Instead of deleting the record, it duplicates it for some reason.
Here is the code that I use:
command = "DELETE * from names where ID = 10"
namesDB.SQLExecute(command)
I am dynamically generating command. but however I change it it always does the same. Same result with or without quotes.
Any ideas?
The very first thing I would do is check to see if there is an error being generated.
if namesDB.Error then
dim s as string = namesDB.errorMessage
msgbox s
return
end
It will tell you if there's a database error and what the error is. If there's no error then the problem lies elsewhere.
FWIW, always, always, always check the error bit after every db operation. Unlike other languages, Xojo does NOT generate/throw an exception if there's a database error so it's up to you to check it.
Try calling Commit().
I just made a sample SQLite database with a "names" table, and this code worked fine:
db.SQLExecute("Delete from names where ID=2")
db.Commit
I have done a lot of work with XOJO and SQLite, and they work well together. I have never seen a record duplicated erroneously as you report. That is very weird. If this doesn't help, post more of your code. For example, I assume your "command" variable is a String, but maybe it's a Variant, etc.
I think on SQLite you don't need the * between the DELETE and the FROM.
I have a question on creating running totals in MS Access 2010 similar to the one here:
Access 2010 - query showing running total for multiple records, dropping old record and adding new record on each line
However when I input the equivalent code from that thread I get an error saying that the database cannot be found (Access seems to think the table I have specified is the database name)
Here is the code from the original thread:-
SELECT hbep1.EmployeeID, hbep1.PayPeriodID,
(
SELECT Sum(hbep2.HoursUsed)
FROM Hours_by_Empl_PP hbep2
WHERE hbep2.EmployeeID=hbep1.EmployeeID
AND (hbep2.PayPeriodID Between hbep1.[PayPeriodID]-3
And hbep1.[PayPeriodID])
) AS Sum_of_Hours_last_4_PPs
FROM Hours_by_Empl_PP hbep1;
Here is the code I inputted into my query:-
SELECT
V4_Try.ID_NIS_INV_HDR,
V4_Try.ID_ITM,
V4_Try.RunTot3,
V4_Try.BomVsActQty,
DMin("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMin,
DMax("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMax,
(
SELECT Sum([V4_Try].[BomVsActQty])
FROM [V4_Try].[BomVsActQty]
WHERE [V4_Try].[ID_ITM]=[V4_Try].[ID_ITM]
AND (IDItmMax < IDItmMin)
) AS RunTot6
FROM V4_Try
ORDER BY V4_Try.ID_ITM, V4_Try.RunTot3;
One thing I notice is that the main query uses DMax() and DMin() to create some aliased columns
...
DMin("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMin,
DMax("RunTot3","V4_Try","[ID_Itm]=" & [ID_ITM]) AS IDItmMax,
...
and then the subquery tries to use those aliases in its WHERE clause
(
SELECT ...
WHERE...
AND (IDItmMax < IDItmMin)
) AS RunTot6
I'm pretty sure that the subquery will have no knowledge of the column aliases in the "parent" query, so they may be the items that are unrecognized.
Start by running this query:
SELECT * FROM V4_Try;
Then develop for complexity. Build the nested query before anything else. When you know that runs, try adding your aliases, then the DMax() function, and so on. Isolate the point at which you have an error popping up.
This is the process to fix a query.
Oh, and please specify the precise error that is raised by Access. Also, if this is being run from VBA, please let us know because that affects your trouble-shooting.
I have a problem with SQlite. Whenever I execute Queries it goes fine but when I exit by .exit command and open again and execute Select * form emp statement, it renders no table even though I use begin transaction and commit .
Any help please. I'm new to SQLite.
Thanks
Bamadeva
I got the solution:-
Wherever our database is created, in my case it is :-
C:\Sites\databases>
Since my database is contactlist_development, I should have entered it with the following commands:-
C:\Sites\databases>sqlite3 contactlist_development
This takes me to :-
sqlite>.schema
Then i am able to view the table details which i just created:)
I have renamed a table in a SQL Server 2008 database, from eL_CourseStepUserNotes to StepUserNotes. I renamed the table using the SSMA.
The table is used in a ASP.NET 4.0 app. I use LINQ to SQL for all CRUD. The problem is that the following code:
dbDataContext db = new dbDataContext();
var k = (from c in db.StepUserNotes
where ((c.CourseStepFK == q.CourseStepFK) && (c.UserFK == q.UserFK))
select c).FirstOrDefault();
try
{
db.StepUserNotes.InsertOnSubmit(q);
db.SubmitChanges();
}
catch
{
}
Fails on the db.SubmitChanges line, saying:
SqlException was caught. Invalid object name 'eL_CourseStepUserNotes'.
Ie, the old name for the table has come back to haunt me.
I have deleted the old LINQ to SQL dbml file and created a new one. I have searched through all the source code for strings that contain the old table name. Nothing. The code compiles...
Where else can I look?
The error is coming back from SQL Server, and using the utility for listing all foreign keys in a sql server database shown in SO question:
sql:need to change constraint on rename table?
reveals no sign of the old table name in FKs either.
I am at a complete loss as to where to look or what to try next. Any suggestions?
Answer:
The problem, as stated by Stu and Stark was a trigger. Stu gave me the SQL to run that nailed the problem. It is documented here in case anyone else runs into this:
Select Object_Name(ID) From SysComments
Where Text Like '%el_CourseStepUserNotes%'
This revealed a trigger with the following name:
tr_eL_CourseStepUserNotes
The trigger referenced the old name as follows:
SET DateAmended = CURRENT_TIMESTAMP
FROM eL_CourseStepUserNotes PP
INNER JOIN inserted i ON PP.UserNoteId = i.UserNoteId
Everything is now working again.
Silly me, I should have realised that a trigger was the problem as the first error I got was related to the DateAmended field.
I have no idea why a trigger would update when a table name changed. I had checked all Keys and relationships, but forgot this trigger.
Live and learn.
When you recreated your linq to sql file, did you remember to refresh the server browser to reflect the table name change first?
Edit - I mean the visual studio server browser.
you need to rebind your LINQ To SQL class, drop all the tables, then add them again from the Server Explorer
open your project in visual studio.
open your dbml file.
find the table you just have renamed.
select and delete it.
Save.
Open server Explorer.
Connect to your database.
Find the table which you have renamed.
Drag and drop on the designer of your dbml file.
Save the file again.
Compile your project.
It is not necessary to drop the tables from your DBML file. You can simply open the designer, click on the class diagram representing your table and type the new name of the table.
However, if you're recreating from scratch it is important to refresh in Server Explorer otherwise it will still pull the old name from the schema.