php mysql_insert_id на нескольких строках?

Если вам нужен хороший универсальный метод для извлечения данных о сборке, попробуйте следующее:

public string GetAssemblyAttribute<T>(Func<T, string> value)
    where T : Attribute
{
    T attribute = (T)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof (T));
    return value.Invoke(attribute);
}

, так что вы можете затем вызвать

string title = GetAssemblyAttribute<AssemblyTitleAttribute>(a => a.Title);
string copyright = GetAssemblyAttribute<AssemblyCopyrightAttribute>(a => a.Copyright);
string version = GetAssemblyAttribute<AssemblyVersionAttribute>(a => a.Version);
string description = GetAssemblyAttribute<AssemblyDescriptionAttribute>(a => a.Description);
7
задан Dan 5 November 2009 в 09:14
поделиться

3 ответа

As far as I know auto_increment does not fill gaps between ids and the operation is atomic. So you can assume that they will be in a row.

4
ответ дан 7 December 2019 в 05:24
поделиться

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id

If you insert multiple rows using a single INSERT statement, LAST_INSERT_ID() returns the value generated for the first inserted row only.

So no, you can't get all the ids easily, but you can assume that they are continuous. You should never rely on assumptions though. It sounds like you want to guess the next id that would come after your bulk insert? If so, do not even attempt this and think of another way to do whatever it is you want to do. :)

4
ответ дан 7 December 2019 в 05:24
поделиться

Чтобы получить следующий идентификатор auto_increment, вы можете использовать:

SELECT auto_increment FROM information_schema.tables WHERE table_name = 'table-you-want-to-check';

Однако вы можете не захотеть полагаться на auto_increment id или last_insert_id () в логике вашего кода. Например, предположим, что два человека, A и B, добавляют вопросы в вашу базу данных почти в один и тот же момент, и вы используете last_insert_id () для определения идентификатора вопроса человека. Что происходит, когда они оба задают вопрос одновременно? last_insert_id () от человека A или B?

Одним из способов решения этой проблемы является использование «предопределенного»

0
ответ дан 7 December 2019 в 05:24
поделиться
Другие вопросы по тегам:

Похожие вопросы: