Why won't SQLite let me query a specific ATTACHED database? - c++

SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> ATTACH DATABASE 'test.db' AS 12;
sqlite> SELECT * FROM ids;
1|hi
2|hilo
3|hiloa
4|hiloas
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main
2 12 C:\test.db
sqlite> SELECT * FROM 12.ids;
Error: unrecognized token: "12.ids"
Why is it erroring? The data is clearly there.

SELECT * FROM `12`.ids;
If you're going to use odd names (such as all-numeric ones), you'd better escape them properly.

Related

{InternalError}ERROR: Assert false - Invalid type: 705

based on https://pygresql.readthedocs.io/en/latest/contents/pg/adaptation.html
sql = "SELECT * FROM user_table WHERE login = %s AND passwd = %s"
db.query_formatted(sql, (login, passwd)).getresult()[0]
I reused this snippet of code to try to use the library SQL replacement as shown in this example:
import pg
pg.DB(*credentials)
sql = "select %s, %s from my.table limit 10"
c.query_formatted(sql, ("id", "event_time")).getresult()[0]
and trying to query a Redshift table.
Unfortunately I get this error message
{InternalError}ERROR: Assert
DETAIL:
-----------------------------------------------
error: Assert
code: 1000
context: false - Invalid type: 705
query: 9876543
location: tbl_trans.hpp:923
process: padbmaster [pid=6543]
-----------------------------------------------
which I really have no idea how to interpret.
I also tried to query with another client
select *
from stl_error
where pid = 6543;
but all I get is:
userid,process,recordtime,pid,errcode,file,linenum,context,error
100,padbmaster,2021-03-01 12:00:00,6543,1000,/home/ec2-user/padb/src/sys/tbl_trans.hpp,923,Assert,false - Invalid type: 705
Anyone knows what's the problem here? Any other suggestion?
Two problems here:
PyGreSQL does not officially support Redshift.
Though it may work, PyGreSQL was made for PostgreSQL only.
It doesn't contain any special provisions for Redshift and is only tested with PostgreSQL (the current version requires PostgreSQL 9 or newer).
The select list must be specified as literals specifying the columns: select id, event_time from ... Query parameters are only used to insert values into queries.

Django with Oracle database 11g

I am new to the python language and django. I need to connect the django to the oracle database 11g, I have imported the cx_oracle library and using the instant client for connecting oracle with django, but when i run the command manage inspectdb > models.py. I get error as Invalid column identifier in the models.py. How could i solve it. I have only 2 tables in that schema i am connecting?
"Invalid column" suggests that you specified column name that doesn't exist in any of those tables, or you misspelled its name.
For example:
SQL> desc dept
Name
-----------------------------------------
DEPTNO
DNAME
LOC
SQL> select ndame from dept; --> misspelled column name
select ndame from dept
*
ERROR at line 1:
ORA-00904: "NDAME": invalid identifier
SQL> select imaginary_column from dept; --> non-existent column name
select imaginary_column from dept
*
ERROR at line 1:
ORA-00904: "IMAGINARY_COLUMN": invalid identifier
SQL>
Also, pay attention to letter case, especially if you created tables/columns using mixed case and enclosed those names into double quotes (if so, I'd suggest you to drop tables and recreate them, without double quotes. If you can't do that, you'll have to reference them using double quotes and exactly the same letter case).
So - check column names and compare them to your query. If you still can't make it work, post some more information - table description and your code.
I've faced the same problem. The problem is that Django expects your table have primary key (ID), so when your table is without key, it returns Invalid columns identifier.
https://docs.djangoproject.com/en/2.1/topics/db/models/#automatic-primary-key-fields

SQLite C interface doesn't create sqlite_master table

It seems that SQLite C interface create database that doesn't contain sqlite_master table described in the documentation:
From within a C/C++ program (or a script using Tcl/Ruby/Perl/Python
bindings) you can get access to table and index names by doing a
SELECT on a special table named "SQLITE_MASTER". Every SQLite database
has an SQLITE_MASTER table that defines the schema for the database
The following code creates a database that doesn't contain such table (.tables command returns nothing):
#include <sqlite3.h>
int main()
{
sqlite3* db;
sqlite3_open("helper.db", &db);
sqlite3_close(db);
}
Why? What should I do to create it?
The .tables command does not show any of the internal tables, but they do exist:
sqlite> create table t(x);
sqlite> .tables
t
sqlite> select * from sqlite_master;
table|t|t|2|CREATE TABLE t(x)

SQL Error ORA-01002 not autocommit and loop

I'm using pro c/c++ in a unix environment. Inside a c function I create a simple select statement which is not inside a loop and autocommit is disabled.
This is the dynamic sql;
char sql_statement[200];
int num1, num2;
...
snprintf(sql_statement, sizeof(sql_sattement), "select column1, column2 from '%s' where num = '%d' and code_cfg = '%d'", "customer", 0, 0);
exec sql prepare instruction_to_execute from :sql_statement;
exec sql declare crs cursor for instruction_to_execute;
exec sql open crs;
exec sql fetch crs into :num1, :num2;
...
Executing this code gives me ORA-01002 error. As I said before, this code is not inside a loop and autocommit is off.
But if I write this code statically, works fine. Below the code:
EXEC SQL
SELECT column1, column2
INTO :num1, :num2
FROM CUSTOMER
where num = 0
AND code_cfg = 0;
SQL instruction is simple. For my understanding this code should be executed fine.
In SO I found some answers:
ORA-01002: fetch out of sequence C++
ORA-01002: fetch out of sequence
Hibernate error “ORA-01002” when persisting entity with custom Sequence Generator
ORA-01002: fetch out of sequence
java.sql.SQLException: ORA-01002: fetch out of sequence

SQLite - How to use it at terminal level & C++ application?

i am new to sqlite and I just recently installed it. I am familar with mysql but I need to use sqlite as I am using it for a C++ application that I am going to create.
Question 1:
I type this at my command line terminal
root#ubuntu:/home/baoky/version1.2/Assignment 2# sqlite abeserver.db
then I saw this output
sqlite>
So i type .h and i see a list of help commands
But i wanna create a table
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main /home/baoky/version1.2/Assignment 2/abeserver.db
1 temp /var/tmp/sqlite_hjT3FEefcAHRPhn
in my main database
How do i execute this sql command at terminal level
CREATE TABLE abe_account (
username TEXT,
name TEXT,
department TEXT,
password TEXT
);
Question 2:
How do I insert record into the table abe_account using C++
Question 3:
How do I retrieve records from table abe_account and assign it to a string using C++
Sorry I tried google around and search around stack overflow, I am still confused with the usage, if its mysql, it would be much simple for me.
Question 2:
Question 3:
Let me google it for you, friend: An Introduction To The SQLite C/C++ Interface.
If you are using the sqlite terminal, you can just type SQL there, and it will be executed.
A typical cycle of work from your C++ code will look something like this:
sqlite3 * db;//database
sqlite3_stmt * stmt;//sql statement
sqlite3_open( "database.db", & db );//opening database
sqlite3_prepare( db, "SELECT something FROM something else;", -1, &stmt, NULL );//preparing the statement
sqlite3_step( stmt );//executing the statement
while( sqlite3_column_text( stmt, 0 ) )
{
char * str = (char *) sqlite3_column_text( stmt, 0 );///reading the 1st column of the result
//do your stuff
sqlite3_step( stmt );//moving to the next row of the result
}
sqlite3_finalize(stmt);
sqlite3_close(db);
You can easily google the functions to learn about their arguments and what they do in-detail.
To create a new database, just connect to it:
$ sqlite3 your_database_file
This will create your database in the file your_database_file. If this file already exists, the command will open it.
Then you can execute CREATE TABLE or any other SQL.