reset password
Author Message
linacute
Posts: 22
Posted 21:26 Nov 09, 2013 |

Does it mean we still keep the insert into tbl (field) values() work? 

and add " insert into tbl values()"

 

cysun
Posts: 2935
Posted 09:25 Nov 10, 2013 |

Yes, of course.

talisunep
Posts: 140
Posted 17:20 Nov 10, 2013 |

Professor Sun
does that mean we need to create two seperate methods since both statements should work for 
insert into tbl values (1, 'abcd') and
insert into table (id, name) values (2, 'test')

or should one method be able to handle both queries?
 

cysun
Posts: 2935
Posted 17:35 Nov 10, 2013 |
talisunep wrote:

Professor Sun
does that mean we need to create two seperate methods since both statements should work for 
insert into tbl values (1, 'abcd') and
insert into table (id, name) values (2, 'test')

or should one method be able to handle both queries?

I don't know what you mean by "creating two methods". You seem to think that you need to create one method for each possible syntax, and that's not how parsing works.

harry_520
Posts: 76
Posted 21:58 Nov 10, 2013 |

Is this a correct output if the insert statement is incomplete like "insert into ", and the result is 0 records processed?

Last edited by harry_520 at 21:58 Nov 10, 2013.
cysun
Posts: 2935
Posted 22:40 Nov 10, 2013 |
harry_520 wrote:

Is this a correct output if the insert statement is incomplete like "insert into ", and the result is 0 records processed?

It should be an exception, just like any other syntax error in SimpleDB.

harry_520
Posts: 76
Posted 22:55 Nov 10, 2013 |

I got "insert into tbl values (1, 'abcd')" out put correctly. It returns 1 record. But when I input an incomplete insert statement, it returns 0 records. So, is this a correct solution for this problem? 

cysun
Posts: 2935
Posted 22:58 Nov 10, 2013 |
harry_520 wrote:

I got "insert into tbl values (1, 'abcd')" out put correctly. It returns 1 record. But when I input an incomplete insert statement, it returns 0 records. So, is this a correct solution for this problem? 

No, as I said, it should throw an exception for syntax errors. Also instead of checking the "output" of an insert statement, you should do a select query to see if the record is inserted.

harry_520
Posts: 76
Posted 23:08 Nov 10, 2013 |

The select query didn't retrieve the records I inserted. Thanks, Dr Sun.

Last edited by harry_520 at 23:15 Nov 10, 2013.
cysun
Posts: 2935
Posted 23:11 Nov 10, 2013 |
harry_520 wrote:

I tested using select query, and it returns the results I inserted. But why do I still need to throw an exception for the incomplete statement?

Because that's what software is supposed to do? Have you ever seen a DBMS that silently accepts syntactically incorrect SQL statements?

linacute
Posts: 22
Posted 13:26 Nov 12, 2013 |

Do we have to throw an error message if we input more column values than the fields? Since it works fine if input more than fields now

cysun
Posts: 2935
Posted 13:39 Nov 12, 2013 |
linacute wrote:

Do we have to throw an error message if we input more column values than the fields? Since it works fine if input more than fields now

No. It'll throw an exception later during execution, but not during parsing as it's syntactically correct.