this 링크를 사용하고 있습니다.여러 값을 가진 sql 열 (cpp 파일의 쿼리 구현)
나는 3 개 테이블 (두 가지 간단한 테이블 Person
및 Item
그들을 연결하는 세 번째 PersonItem
) 내 데이터베이스에 이클립스 내 CPP 파일을 연결했다. 여러 항목을 가지고
CREATE TABLE PersonsItems(PersonsItemsId int not null auto_increment primary key,
Person_Id int not null,
Item_id int not null,
constraint fk_Person_id foreign key (Person_Id) references Person(PersonId),
constraint fk_Item_id foreign key (Item_id) references Items(ItemId));
그래서, 다음 C 임베디드 SQL과 내가 원하는 사람 : 세 번째 테이블에서 나는 그런 간단한 기본 및 두 개의 외래 키를 사용합니다.
내 코드 :
mysql_query(connection, \
"INSERT INTO PersonsItems(PersonsItemsId, Person_Id, Item_id) VALUES (1,1,5), (1,1,8);");
printf("%ld PersonsItems Row(s) Updated!\n", (long) mysql_affected_rows(connection));
//SELECT newly inserted record.
mysql_query(connection, \
"SELECT Order_id FROM PersonsItems");
//Resource struct with rows of returned data.
resource = mysql_use_result(connection);
// Fetch multiple results
while((result = mysql_fetch_row(resource))) {
printf("%s %s\n",result[0], result[1]);
}
내 결과가
-1 PersonsItems Row(s) Updated!
5
하지만 난 그 이유
이-1 PersonsItems Row(s) Updated!
5 8
가 somone에이 말해 줄 수 싶습니다 VALUES (1,1,5), (1,1,8);
함께 이 일이 일어나지 않았나요? 친절하게 생각합니다.
Duplicate entry '1' for key 'PRIMARY'
당신은 기본 키가 너무 고유해야되는 PersonsItemsId
에 두 번 1
를 삽입하려고하기 때문에 (이것은이다 :
가 아니, 그건 중요하지 않았다 죄송합니다. 어디에서나 Item_id를 사용합니다. 그것은 동일합니다. 나는 이것을 유감스럽게 생각한다. 편집 됨. –