I have the c++ project working on MySQL database.
recently i am moving to the PostgreSQL database so i am facing the difficulties like the queries in sql written is like
select UserName form UserInfo;
will not work in pgSQL it would be like
select "UserName" from "UserInfo";
so i want to make a file that could tackle this two difference syntax could anyone help me?
You should standardize on ANSI SQL, in this case "UserName" which MySQL will understand too under appropriate SQL modes. Then you should look at the minimum you need to do to support this (in this case, if it is MySQL, set the appropriate sql_mode).
Related
I have lots of models in my project like Advertisements, UserDetails etc. Currently I have to delete the entire database every year so as to not create any conflicts between this year data and previous year data.
I want to implement a feature that can allow me to switch between different years. What can be the best way to implement this?
I think you could switch schemas in PostgreSQL. It's not completely straightforward. There are several ways to do that you can look into. The way I did it was to use a default search path for the Django database user account (e.g. user2018, user2019, etc) that only included the schema I wanted to use. I can't check the exact settings right now because my office network is down. You can also do it in settings.py or in each individual model using db_table according to what I've read, although both those solutions seem more convoluted that using the search path.
You would have to shutdown, change the database username in settings.py (or change the search path in PostgreSQL, change the schema over to a new one, and then run migrate to create the tables again. If you have reference data in any of the tables then schema-to-schema copies are easy to do.
Try searching for change django database schema postgresql to see what options there are for specifying the schema.
I never had to deal with database, therefore, sorry in advance!
I was asked to create a database for a project and store data output from a c++ program into the database. I informed on Google about databases, and I came across with MySQL, and in particular database connection. As far as I understood, in the first place a database has to be created (for example with MySQL), and once data are inserted, it’s possible to access to them. However, it’s not totally clear what is possible to achieve with such a connection and how to save data from a c++ program into the database directly.
Based on what I read on the net, these should be related, is it right? I would really need some help, example or clarification about these two questions. Thanks in advance for your time!
First you should create DB and tables.
You can do it in each DB IDE wizards, or you can write it in a script.
So here are scrypt for MySQL
CREATE DATABASE test_db --this create DB called test_db
I guess you should store a message and a timestamp so a possible table (In MySQL) will be:
USE test_db -- from now on the script using test_db unless specified explicit DB
--creating table with id, mmessage and timestamp
CREATE TABLE output_table (
msg_ID INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
msg VARCHAR(max),
msg_TS TIMESTAMP DEFAULT CURRENT_TIMESTAMP)
In the above table you only need to give the message since all the rest are filled automatically. So Insert into the table command may look like this:
INSERT INTO output_table (msg) values ('this is a message')
When you want to check the whole table you run the following:
SELECT * FROM output_table
Now you need to connect this code to your c++ code:
Generally, you'll need to know db name, user name and password in manner to connect to DB.
You can use ODBC + MySQL ODBC Connector. It is better since you are not limitted in your c++ to a specific DB. If you are sure you will use only MySQL you can use also MySQL C++ Connector directly. Anyway, both will give you option to run SQL commands on your DB.
HERE you can fine MySQL c++ connector sample
HERE you can find ODBC sample.
I need to move a series of tables from one datasource to another. Our hosting company doesn't give shared passwords amongst the databases so I can't write a SQL script to handle it.
The best option is just writing a little coldfusion scripty that takes care of it.
Ordinarily I would do something like:
SELECT * INTO database.table FROM database.table
The only problem with this is that cfquery's don't allow you to use two datasources in the same query.
I don't think I could use a QoQ's either because you can't tell it to use the second datasource, but to have a dbType of 'Query'.
Can anyone think of any intelligent ways of getting this done? Or is the only option to just loop over each line in the first query adding them individually to the second?
My problem with that is that it will take much longer. We have a lot of tables to move.
Ok, so you don't have a shared password between the databases, but you do seem to have the passwords for each individual database (since you have datasources set up). So, can you create a linked server definition from database 1 to database 2? User credentials can be saved against the linked server, so they don't have to be the same as the source DB. Once that's set up, you can definitely move data between the two DBs.
We use this all the time to sync data from our live database into our test environment. I can provide more specific SQL if this would work for you.
You CAN access two databases, but not two datasources in the same query.
I wrote something a few years ago called "DataSynch" for just this sort of thing.
http://www.bryantwebconsulting.com/blog/index.cfm/2006/9/20/database_synchronization
Everything you need for this to work is included in my free "com.sebtools" package:
http://sebtools.riaforge.org/
I haven't actually used this in a few years, but I can't think of any reason why it wouldn't still work.
Henry - why do any of this? Why not just use SQL manager to move over the selected tables usign the "import data" function? (right click on your dB and choose "import" - then use the native client and permissions for the "other" database to specify the tables. Your SQL manager will need to have access to both DBs, but the db servers themselves do not need access to each other. Your manager studio will serve as a conduit.
I'm working on a CGI application written using C++ with the C MySQL adapter. I'm trying to run a query on two databases, so I want to connect to a MySQL server without choosing a default database. Is this possible? I'm using mysql_real_connect().
mysql_real_connect() can take a NULL parameter for the database paramter, and this selects the default. Just ensure that the user has no default database set.
I must be missing the point of your question. Seems to me if you want to use two databases, you only need two MYSQL*, one for each DB, calling mysql_real_connect( ) on each and then proceeding normally from there, referring to one or the other MYSQL* as appropriate. Could that work, or am I completely confused?
I have C++ code, and from it I need to access the DB and make a query in table (with name NECE_TABLE, which has 2 columns - IntID and Status).
Here I need to get "status" column value from DB table (NECE_TABLE) using the IntID from C++ code.
Any help will be greatly helpful. Thanks in advance
Your question is very vague, but in summary you need to:
Use an appropriate client library supported by your database to connect to that database using some user credentials with appropriate permissions for SELECTing from your table
Execute a SQL select to fetch the data you want
There's some confusion as to which database you're using.
If you're using Oracle, you can use the OCCI client library to connect to the database and execute SQL statements. See section 2 of the linked document, where it describes connecting to a database and executing SQL queries.
Take a look at this link - it's a simple tutorial on how to get started with MySQL and C++. You say you are using vanilla SQL in your tags, but the two should be compatible as long as you stick to the more basic queries.