473,748 Members | 8,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why Postgres inserts null value for parameterized statement?

1 New Member
Hi,

I have created table using following sql statement through psql tool in test database using
create table t1(f1 int);
table is created.
Now I am using an odbc script to insert 5 records. But it inserts 6 records NULL value being the first one inserted.
the code snippet is as below.

...
...
retVal = SQLDriverConnec t(dbHdl, NULL, (SQLCHAR*)"psql ",
SQL_NTS,outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_NOPR OMPT);
SQLSetConnectAt tr(dbHdl, SQL_ATTR_AUTOCO MMIT, SQL_AUTOCOMMIT_ OFF, 0);
int f1 = 0;
ret = SQLPrepare(stmt ,(unsigned char*)"INSERT INTO T1 VALUES(?);" ,
SQL_NTS);
ret = SQLBindParamete r (stmt, 1, SQL_PARAM_INPUT , SQL_C_SLONG,
SQL_INTEGER,0,0 ,&f1,0,NULL);
int i,count=0;
// EXECUTE THE STATEMENT
for(i=0;i<5;i++ )
{
f1++;
ret = SQLExecute(stmt );
ret = SQLTransact(env ,dbc,SQL_COMMIT );
count++;
}
...
...

I am using unixodb driver and my odbc.ini file reads as follows.

$ vi ~/.odbc.ini

[psql]
Description = CP resources db
Driver = postgres
Trace = No
TraceFile = sql.log
Database = test
Servername = localhost
UserName = kishoramballi
Password = kishoramballi
Port = 5432
Protocol = 6.4
ReadOnly = No
RowVersioning = No
ShowSystemTable s = No
ShowOidColumn = No
FakeOidIndex = No
ConnSettings =
ExtraSysTablePr efixes =

$ vi /etc/odbcinst.ini

[ODBC]
Trace = yes
TraceFile = /tmp/sql.log

[postgres]
Driver = /usr/lib/libodbcpsql.so
Setup = /usr/lib/libodbcpsqlS.so
Description = Connector Driver DSN
SERVER = localhost
Database = test
ReadOnly = No

[PostgreSQL]
Description = PostgreSQL ODBC driver for Linux
Driver = /usr/lib/libodbcpsql.so. 1
Setup = /usr/lib/libodbcpsqlS.so .1
ExtraSysTablePr efixes =
UsageCount = 1


Am I missing something or have I added some thing more than required for this problem to occur.

Please help
thanks
Oct 14 '09 #1
0 2739

Sign in to post your reply or Sign up for a free account.

Similar topics

2
8780
by: FizzBin | last post by:
We are writing a C application that is using ODBC to insert records into a database. We have a NOT NULL column that can legitimately have an empty value, i.e. we know the value and it is empty (i.e. a zero length string). We are using SQLBindParameter() to bind a variable to the parameterized insert statement <<in the form: INSERT INTO table VALUES (?, ?, ?)>>. We are using SQLExecDirect() to process the SQL. We are running into the...
48
11909
by: Edwin Quijada | last post by:
Hi !! Everybody I am developing app using Delphi and I have a question: I have to save pictures into my database. Each picture has 20 o 30k aprox. What is the way more optimus? That 's table will have 500000 records around. Somebody said the best way to do that was encoder the picture to field bytea but I dont know about this. Another way is save the path to the picture file but I dont like so much because I need to write to disk by OS...
6
2954
by: Prabu Subroto | last post by:
Dear my friends... Usually I use MySQL. Now I have to migrate my database from MySQL to Postgres. I have created a database successfully with "creatdb" and a user account successfully. But I can not access the postgres with pgaccess.
8
9493
by: Nick | last post by:
I have a table with columns (product_id,related_product_id,related_counter) If product A is related to product B then a record should be created, if the record already exists then the related_counter should be incremented. This is very easy to do with MySQL using INSERT... ON DUPLICATE KEY. Standard or not, it is very usefull.
0
1736
by: bunty.gopal | last post by:
I am trying to use the PreparedStatement's addBatch to load data in an ETL-like process into a table. There is a single prepared statement. The parameters are set on it and prepStmt.addBatch() is called. Then the next iteration of setting the params and adding to batch begins. Finally after setting the batch of 2 to 2000 rows, the prepStmt.executeBatch() is called. If the last row contains a null value for a particular DECIMAL field,...
17
2374
by: NuB | last post by:
I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank? example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
9
8680
by: dan | last post by:
within a loop i am building a sql insert statement to run against my (programatically created) mdb. it works but it seems unreasonably SLOW! Sorry, dont have the code here but the jist is very standard (I think!); e.g: # get connection loop
1
5161
by: bunty.gopal | last post by:
This is the solution to the issue in the subject, question itself was posted in a previous thread long back. Use the latest DB2 db2cc.jar fixpack on the client, or add "deferPrepares=false" to the connection string when opening the connection (or connection pool properties, if deployed on a server like weblogic). The issue can be resolved using either of these options. Gopal
0
2705
by: NM | last post by:
Hello, I've got a problem inserting binary objects into the postgres database. I have binary objects (e.g. images or smth else) of any size which I want to insert into the database. Funny is it works for files larger than 8000 Bytes. If a file is less than 1000 Bytes I get the following message: Error message: --invalid input syntax for type oid: "\074\077......";
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.