what does "out of range" mean? - mysql

I have checked these statements with mysql and no error will happen and also the out put will be 0 rows BUT my friend checked it and he found an error for SELECT becaouse it is out of range !! IS he correct? thanks
CREATE TABLE T1(A INTEGER NULL);
SELECT * FROM T1;

There is nothing wrong with those two lines.
"Out of range" normally means that some value is outside the expected range of valid values. For example if you have an array of length 2, trying to access position number 10 in that array could lead to an "array index out of range" error (depending on your programming language).

I don't immediately see anything wrong with it - but I haven't got an install of mysql handy at the moment to test with.

Related

SQL Error "Column count doesn't match value count at row" - yet I've checked that the number of columns equals number of values

I've been trying to set up a very simple SQL table that links to a bigger table - that table works fine but the second table constantly throws up the classic "column count doesn't match value count at row" error.
CREATE TABLE NonHeadlessDistro
(
Headless INT,
Proprietary INT,
EaseInstall INT,
SimilarTo VARCHAR(28),
Gnome INT,
KDE INT,
LXDE INT,
XFCE INT,
MATE INT,
Cinna INT
);
INSERT INTO NonHeadlessDistro (Headless, Proprietary, EaseInstall,
SimilarTo, Gnome, KDE, LXDE, XFCE, MATE, Cinna)
VALUES ('0','1','2','macOS','1','1','1','1','1','0'),
('0','4','4','Linux','1','1','1','1','0','0'),
('0','1','1','Windows','0','1','0','1','1','1'),
('0','2','2','Windows','0','0','1','1','0','0'),
('0','1','5','Linux','1','0','0','0','0','0'),
('0','1','4','Linux','1','0','0','0','0','0'),
('0','2','2','Linux','1','1','1','1','1','1'),
('0','3','5','Linux','1','1','1','1','1','1'),
('0','2','2','Linux','0','1','0','0','1','0'),
('0','1','2','Linux','0','0','1','0','0','0'),
('0','1','4','Linux' '1','1','0','0','0','0'),
('0','3','5','Linux','1','1','1','1','1','1'),
('0','2','3','Linux','0','0','0','0','1','0'),
('0','3','5','Linux','1','1','1','1','1','1'),
('0','1','4','Linux','1','1','0','0','0','0'),
('0','5','2','Linux','1','0','1','0','1','0'),
('0','5','5','Linux','0','0','1','0','1','0'),
('0','5','4','Linux','1','0','0','0','0','0'),
('0','5','5','Linux','1','0','1','1','0','0'),
('0','2','3','Linux','1','1','1','0','0','0'),
('0','2','3','Linux','1','1','0','1','1','1'),
('0','2','3','Linux','0','0','1','0','0','0'),
('0','2','3','Linux','1','1','1','1','1','0'),
('0','2','1','Linux','1','1','1','1','1','1'),
('0','2','1','Linux','1','1','0','1','1','0');
SELECT linux_distro
FROM linux_distro LEFT JOIN NonHeadlessDistro
ON Headless
WHERE Headless ="0";
The exact error message appears as:
1 errors were found during analysis
1. 10 values were expected, but found 9. (near "(" at position 596)
MySQL said:
#1136 - Column count doesn't match count at row 11
Using online SQL error checkers, the problem appears to be within the INSERT INTO line, but I'm at a complete loss as to why one of the columns hasn't been acknowledged, as I've checked that the number of columns is equal to the number of VALUES. Reading up on other solutions for the error, the problem usually appears as a result of misplaced quotation marks, or missing values/columns, but for the life of me I can't see what is wrong with my SQL. It is most likely a incredibly simple mistake given that my initial errors with the first table were solved with adding a missing semi-colon. Any help would be greatly appreciated.
EDIT: I'm blind, I couldn't see my missing comma on line 11. However, I've opened up another can of worms - before MySQL was expecting 10 values and only found 9 values, but with the edit it now expects 11 values and it can only find 10. It now also affects all 24 lines from
INSERT INTO NonHeadlessDistro (Headless, Proprietary, EaseInstall,
SimilarTo, Gnome, KDE, LXDE, XFCE, MATE, Cinna)
to the final
('0','2','1','Linux','1','1','0','1','1','0');
line, so I have the same error replicated 24 times. I'm guessing that there's probably a pretty fundamental problem here:
MySQL said:
#1136 - Column count doesn't match value count at row 1
This line
('0','1','4','Linux' '1','1','0','0','0','0'),
has a comma missing

QSqlRecord: Access numeric value from SQLite Table in QT, results are empty

The question I have is similar to a few I've seen, but the solutions don't seem to work for me, so I'll add a new one:
I am trying to access a numeric value (the highest user ID) from an SQLite table into my QT Program, with the following query:
SELECT Name, MAX(ID) FROM User_lib;
This works from the command shell, with the expected result.
I then attempt to access the maximal ID value with:
QSqlQuery qry_ID;
qry_ID.prepare("SELECT Name, MAX(User_lib.ID) FROM User_lib");
qry_ID.exec()
qDebug() << qry_ID.record().value("ID").toInt();
The result is zero (and empty if I access "Name" with toString())
Also, as a test
qDebug() << "Number of Rows: " << qry_ID.size();
which I've seen in several other answers gives me -1.
On the other hand,
qDebug() << "Number of columns: " << qry_ID.record().count();
gives me "Number of columns 2" as expected. It appears that the query gives no results.
At first I thought that I had a problem with my query, but the same thing is happening when I attempt to count the rows in queries that clearly work correctly (table is displayed, I can add elements correctly, etc), so I think I must be doing something wrong in QT.
Let's see what you actually get in the command-line shell:
sqlite> .mode columns
sqlite> .header on
sqlite> SELECT Name, MAX(ID) FROM User_lib;
Name MAX(ID)
---------- ----------
user30248 8562493
So in the output that you get from the query, the second column is not named ID but MAX(ID).
The documentation actually says:
The name of a result column is the value of the "AS" clause for that column, if there is an AS clause. If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next.
So use AS, or access the column by its index.
SQLite computes output rows on demand, so it is not possible to give a count of rows before they have all been read. Therefore, the QuerySize feature is not supported by the SQLite driver.
I haven't checked CL's answer above, which I am sure will work as well, but I have managed to find an alternative solution that worked for me and may be interesting. Since QsqlQuery's internal pointer is set to one field ahead of the first record, I have to advance with next. This is the code that worked:
QSqlQuery qry_ID;
qry_ID.prepare("SELECT Name, MAX(ID) FROM User_lib");
qry_ID.exec();
qry_ID.next();
QString name = qry_ID.value(0).toString();
int IDmax = qry_ID.value(1).toInt();
If you need to access various rows, a while loop is required, but that is a different question.

cfm websql queries error

I have this websql script (http://pastebin.com/gvJseBAn) which doesn't perform correctly.
If I run the statement select * from news where id=0772348890 , I get the error The conversion of the varchar value ' 0017707787068' overflowed an int column.
If I run the statement select * from news where id='0772348890' , I get the error Incorrect syntax near '0772348890'.
If I run the statement select * from news where id="0772348890" , I get Invalid column name '0772348890'
Any other variation of '#0772348890#' or #0772348890# or "#0772348890#" I have tried gives the error "incorrect column" or "incorrect syntax near ..."
Any ideas on how to fix this error, or a better method of creating a simple websql query form?
A) the issue here is that db column will not under any conditions accept "0772348890" as a valid input because it is mismatched. The column is an "int" type (according to your first error), but your value has a padded 0 prependedto the front as in 0 772...
What is the purpose of this zero? Ordinarily prepended zeros appear in fixed length character fields where a space is not allowed. Should the value not be "772348890"?
B) Remember that ColdFusion will escape your single quotes in your query. In your second error example (where you use single quotes), this code:
<cfquery name="runsql" datasource="#Form.datasource#" timeout="30">
#Form.sql#
</cfquery>
Produces this SQL statement:
select * from news where id=''0772348890''
Which would give you your syntax error. If you wish to successfully test your second example you will need to alter your code to:
<cfquery name="runsql" datasource="#Form.datasource#" timeout="30">
#preservesinglequotes(Form.sql)#
</cfquery>
Preservesinglequotes() gets you past the second error issue and MSSQL's implicit conversion may strip off the prepended zero and allow the query to succeed - though I'm not sure will give you what you want.
C) Finally you should probably never do what you are trying to do - at least not in this fashion (sorry to be so direct!). Your opening up your DB to arbitrary queries from a web form. The resulting damage from even casual mistakes could be catastrophic to your data, let alone a malicious user bent on stealing or altering or using your site for malicious purposes. That's my take. :)

count(*) on mysql giving me value 0

select count(*) FROM antecedente_delito WHERE rut_polichile = NEW.rut_polichile
this statement is giving de value 0, when it should give me 18 :/ ive been trying a lot to find any bug in it.
Here's the working solution that I mocked up using/changing your code in SqlFiddle. http://sqlfiddle.com/#!2/ac2e9/1
To trouble shoot this, I would view your actual values and verify that NEW. is returning what you think it should. Sometimes it may be doing some trims or removal of special characters, especially the _ and % signs are likely to stripped in subprocedures.
I would start with the query:
select top 50 rut_polichile, NEW.rut_plichile FROM antecedente_delito
If the issue is not obvious from that add in a varbinary check:
select top 50 cast( rut_polichile as varbinary), cast(NEW.rut_plichile as varbinary) from antecedente_delito
If the table only has 18 records, then you should be good to go with the above troubleshooting, but if there is more data, I would suggest limiting your results from the above by the rowid or other identifier in a where statement.
It's not the answer, but I hope it helps you find the answer.
The SELECT privilege for the subject table if references to table columns occur via OLD.col_name or NEW.col_name in the trigger definition.
but in your trigger i can't see any trigger definition. so try without NEW.
for more info: http://www.sqlinfo.net/mysqldocs/v51/triggers.html or
http://bugs.mysql.com/bug.php?id=31068

Limit mysql data value to 100.0

I want to put completion of task in percentage (eg. 24.5,88.4,12.9,100.0,etc), the maximum value is 100.0
I have try using decimal(3,1) but it gave me maksimum of 99.9 ,
decimal(4,1) gave me maksimum of 999.9
is there any other correct data type for my problem ?
I believe MySQL still doesn't support check constraints. However, you can use an INSERT/UPDATE trigger that verifies the new value of the column and throws an error if it's outside a range that you specify.
I don't think MySQL has a native way of doing this. You are left to do it either with your external application or using a stored procedure.