C++/MySQL insert syntax issue - c++

I am attempting to build an insert statement within a C++ application to push records to a MariaDB server, but am getting a generic error back from the database citing MySQL syntax errors.
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NSERT INTO test_data (cid,ch1,ch2,ch3,ch4,..' at line1
The code is as follows:
insertString = "INSERT INTO test_data (cid,ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10,ch11,ch12,ch13,ch14,ch15,ch16,value_type) VALUES ('"+cid;"', '"+di_ch[0];"', '"+di_ch[1];"', '"+di_ch[2];"', '"+di_ch[3];"', '"+di_ch[4];"', '"+di_ch[5];"', '"+di_ch[6];"', '"+di_ch[7];"', '"+di_ch[8];"', '"+di_ch[9];"', '"+di_ch[10];"', '"+di_ch[11];"', '"+di_ch[12];"', '"+di_ch[13];"', '"+di_ch[14];"', '"+di_ch[15];"', '"+value_type;"')";
mysql_query_status=mysql_query(connect,insertString.c_str());
The code wouldn't compile without formatting the values with the "+" and ";" preceding and following the variable reference. It still doesn't quite make sense to me why this is required, but then again, I still need to find a good reference document for using this connector, which would also be appreciated. There is a lot of material on installing, configuring and building the connector and its applications, but not many code examples. Of what I've found, I've read I may need to try using a PreparedStatement next.
Table schema here

Related

C++ PostgreSQL Library, describe SQL, without execution

I have asked this question on Github, issue #641, since it seems like a deficiency or an enhancement question.
Most databases (e.g. Oracle, SQL*Server, Sybase, ... ) send back a description of the resultset, even if there are zero rows. I cannot seem to find this in pqxx, nor can I find a way to describe SQL of any kind prior to execution. The only way I have been able to get the SQL metadata is by collection upon the first row retrieved, but this is limited to an actual row being retrieved. If there are zero rows, I have no way to determine the metadata.
Looking at the v15.x code base for libpq (standard C library), I see that psql has a "workaround" for this very problem. In the file src/bin/psql/common.c there is a function called static bool DescribeQuery(const char *query, double *elapsed_msec) (on or about line #1248).
This function has a rather ingenious solution for this very problem. They create an "unnamed" prepared statement, which they do not execute, instead they use the results of that call, which provides the field info, and subsequently query against the pg_catalog for the metadata descriptions (source below).
Unfortunately, the pqxx library doesn't provide enough (that I can tell) to duplicate this functionality. Does anyone have a solution for this problem?
Credit for resolution goes to Jeroen Vermeulen, on the Github issue #641. He suggested that the predicate AND false be added to the query to force a prototype result. By doing this an empty resultset is returned, with the fields available for metadata collection.

Can't access to django models with an external script

I have created a Django project with a series of tables (models) using postgresql. The thing, is that one of them I want to be able to access it also from outside the Django project, because from Django I simply want to see its content, but with an external script I want to insert the data.
The problem I have is that when I try to access any of the tables created in django from an external script, the windows terminal, or even the program that postgresql offers. It tells me that the table does not exist. What am I leaving or doing wrong?
The problem I have is that when I try to access any of the tables created in django from an external script, the windows terminal, or even the program that postgresql offers. It tells me that the table does not exist. What am I leaving or doing wrong?
Below I show a screenshot with the tables I have and how it gives me an error.
As you can see I have the ability to see all the tables, but then it doesn't let me select any of them. I have tried everything with lowercase and neither, removing the prefix Platform_App_ and neither How can I access them?
Here I leave a question that was asked similarly but I can't get it to work.
Thank you.
I will expend answer to be more clear of why this helped.
Short answer: all identifiers without double-quoting are always folded to lower case in PostgreSQL.
Almost that short answer: the main problem is that your table name uses mixed-case table name. PostgreSQL require using double-quotes to make identifier case-sensitive.
So, if your table was named as platform_app_fleet, then this will work:
select * from platform_app_fleet;
because table name is in lower case. But when you have table named with mixing lower and upper cases like Platform_App_fleet - you need to use quoting:
select * from "Platform_App_fleet";

SQL72007: The syntax check failed 'Unexpected end of file occurred.' in batch near :

In SSDT project (using VS2017/VS2015, SSDT version 15.1.61702.140), I cannot get my project to build. The compiler keeps complaining about the sql statement in my PostDeploymentScript (yes, I have set the BuildAction property to PostDeploy). The sql statement is:
if ('$(env)' = 'dvp')
BEGIN
PRINT 'creating users for dvp'
:r .\SecurityAdditions\usersdvp.sql
END
ELSE IF ('$(env)' = 'qat')
BEGIN
PRINT 'creating users for qat'
:r .\SecurityAdditions\usersqat.sql
END
The actual error message is:
D:\My\File\Path\PostDeploymentScript.sql (lineNum, col): Error: SQL72007:
The syntax check failed 'Unexpected end of file occurred.' in the batch near:
The line num referred in the error message in the last line (end). Any idea what's causing this?
Apparently the problem was due to the GO statements I had in the files I was referencing. Having GO statements inside if else block is invalid. Here is an article explaining that. I was able to get it work by removing all GO statements from the referenced files and by splitting if else to two if.
IF ('$(env)' = 'dvp')
BEGIN
:R .\SecurityAdditions\UsersDVP.sql
END
IF ('$(env)' = 'qat')
BEGIN
:R .\SecurityAdditions\UsersQAT.sql
END
GO
I had this same error because I forgot to end one of the scripts being included in the post deployment script with a GO statement. What makes it hard fix is that the error will point to the first line in the next script instead of the script where the GO statement is missing.
I ran into this issue while I was trying to create database users in a SQL Database project. Setting the build action to None is no use because then your script doesn't run during the deployment.
I was using a script like this to create the users:
IF NOT EXISTS (SELECT * FROM sys.sysusers WHERE name='$(DbUserName)')
BEGIN
CREATE USER [$(DbUserName)] WITH PASSWORD = '$(DbPassword)';
ALTER ROLE [db_owner] ADD MEMBER [$(DbUserName)];
END
I had two SQLCMD variables in the project file and setting a default value for one of them actually resolved the issue. It's really weird but I hope this helps some poor soul one day :)
I would like to share my experience here.
I got same error building my sql project but scenario was different and tricky.
I introduced new column in one of my database table and I needed to populate that column for already existing rows in that table. So basically it should be one time process and hence I decided to create post deployment script to do that. This post deployment script
began with IF condition to make sure it run only once for a given database. Please note this does not allow GO statement.
then Create Function to create temporary function. This needs GO statement before Create Function mainly because it makes changes in database schema. This was tricky because IF does not allow GO statement.
then Update query using temp function to achieve my requirement. This is fine without GO statement
then DROP FUNCTION to remove temporary function. This is also database schema change and ideally needs GO statement.
To handle this situation without any GO statement
I created a variable let's say '#CreateFuntion NAVARCHAR(MAX)' and set it with whole Create Function statement.
Executed Create Function using "EXEC sp_executesql #CreateFunction". This runs Create Function in separate batch. I was expecting Drop Function will need same treatment but in my case it worked without GO and "EXEC sp_executesql" may be because it was last statement in the script and would anyway run in next batch.
Everything else as it is
Another reason this could happen is if a post deployment script has a BEGIN statement without a corresponding END line. In such a case, any subsequent GO in anther future script will cause this error. I stumbled across this due to my own absent-mindedness when editing one of the post-deployment scripts.

WebRatio - fill list with custom query

I just started to use WebRatio and I am facing a simple problem, with easy solution if I was not using this fabulous framework .... I was asked to do some sort of glosary app, and what I am trying to do right now is a simple index where appears all letters from A-Z and how many entries starting with each letter there are in my database, quite simple.
I aleady started a database with my entity: name, description and last_modified. I had been looking for some information on how to do this but I found nothing. So what I am trying to do is to fill a list with a custom query that I made (it works good on my sql editor) but I am not able to list the results in a WebRatio list. I tried to use a "query" object linked to a "simpleList" object but when I run the app it gives me error: "Expected at least one element .. inside " I would appreciate any help or resource that explains how to do this.
Thanks in advance
You shouldn't link the query unit with list because the list will make it's own database query. Instead you should specify outputs for query unit and write your custom style template for query unit to visualize the results as html. Or also (not recommended) you can link the results of query unit with a script unit and output desired html within a script unit.

Using the ATL OLE DB Provider template

I am experimenting with trying to write an OLEDB provider. I have started with the ATL OLE DB provider wizard. After fixing an apparent issue with the COM_INTERFACE_ENTRY2 macro I managed to get the default code to compile, but so far I'm not having much success using it.
For example, I have tried using VB.NET to connect to it as such:
Dim testConn As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=TestProvider.Provider.1")
testConn.Open()
Dim strTest As String = "C:\*.*"
Dim testCmd As New OleDb.OleDbCommand(strTest, testConn)
Dim testRd As OleDb.OleDbDataReader
testRd = testCmd.ExecuteReader()
The last line produces an InvalidOperationException with additional information: OleDbDataAdapter internal error: invalid row set accessor: Ordinal=1 Status=BADBINDINFO.
Trying to use ADO from VBA in Access lets me correctly pull the field names, but when I try to get any actual values I get a rather generic "multi-step OLE DB operation produced errors" message.
I have tried reading up on binding and accessors, but there doesn't seem to be anything relevant to change in the template code. Is there something else I might be doing wrong? I have tried creating a new column map and replacing all of the FindFirstFile code with different fields with hardcoded values, but am still getting the same errors.
I am using Visual Studio 2013 RC, but I don't think it's an IDE-related issue.