Hi,
While trying to generate an continuous sequence values for non-auto_increment
column in mysql, the soci is failing with exception "Column count doesn't match
value count", but same sql statements work fine from mysql command prompt.
Here is the small test code to reproduce the error:
---clip--
#include <soci/soci.h>
#include <soci/mysql/soci-mysql.h>
main() {
soci::session sql("mysql","service=dbrepl user=scott password=tiger" );
sql << " CREATE TABLE a ( a_c1 int, a_c2 int)";
sql << "CREATE TABLE b (b_c1 int)";
sql << " INSERT INTO b values (10)";
sql << " INSERT INTO b values (20)";
sql << " INSERT INTO b values (30)";
sql << " SELECT @row := 0";
sql << " INSERT INTO a(a_c1,a_c2) SELECT @row := @row+1 as a_c1, b_c1 as
a_c2 from b ";
}
---clap--
On running this, I get error as below:
---
[dbrepl@SRadiusDEV tmp]$ ./a.out
terminate called after throwing an instance of 'soci::mysql_soci_error'
what(): Column count doesn't match value count at row 1
Aborted
[dbrepl@SRadiusDEV tmp]$
---clap-
From mysql command prompt, I get results as expected:
--clip--
mysql> CREATE TABLE a ( a_c1 int, a_c2 int);
Query OK, 0 rows affected (0.25 sec)
mysql> cREATE TABLE b (b_c1 int);
Query OK, 0 rows affected (0.07 sec)
mysql> INSERT INTO b values (10);
Query OK, 1 row affected (0.04 sec)
mysql> INSERT INTO b values (20);
Query OK, 1 row affected (0.07 sec)
mysql> INSERT INTO b values (30);
Query OK, 1 row affected (0.04 sec)
mysql> SELECT @row := 0;
+-----------+
| @row := 0 |
+-----------+
| 0 |
+-----------+
1 row in set (0.00 sec)
mysql> INSERT INTO a(a_c1,a_c2) SELECT @row := @row+1 as a_c1, b_c1 as a_c2
from b ;
Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
mysql>
mysql> select * from a;
+------+------+
| a_c1 | a_c2 |
+------+------+
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
+------+------+
3 rows in set (0.00 sec)
mysql>
--clap--
Please suggest how to fix this problem.
Thanks,
Lalit------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent
caught up. So what steps can you take to put your SQL databases under
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users