小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

last_insert_id()不可靠

 Blex 2011-05-24
看了半天mysql的代碼。mysql_insert_id是這么定義的
my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql)
{
  return mysql->;last_used_con->;insert_id;
}

MYSQL是個(gè)結(jié)構(gòu)體,里面包括數(shù)據(jù)庫鏈接和一些當(dāng)前數(shù)據(jù)庫鏈接的狀態(tài)值,

其中在MYSQL結(jié)構(gòu)體里面有insert_id,mysql_insert_id函數(shù)返回的就是結(jié)構(gòu)體里面的找個(gè)值。




QUOTE:
typedef struct st_mysql
{
  NET           net;                    /* Communication parameters */
  gptr          connector_fd;           /* ConnectorFd for SSL */
  char          *host,*user,*passwd,*unix_socket,*server_version,*host_info,*info;
  char          *db;
  struct charset_info_st *charset;
  MYSQL_FIELD   *fields;
  MEM_ROOT      field_alloc;
  my_ulonglong affected_rows;
  my_ulonglong insert_id;               /* id if insert on table with NEXTNR */
  my_ulonglong extra_info;              /* Used by mysqlshow */
  unsigned long thread_id;              /* Id for connection in server */
  unsigned long packet_length;         
  unsigned int  port;
  unsigned long client_flag,server_capabilities;
  unsigned int  protocol_version;
  unsigned int  field_count;
  unsigned int  server_status;
  unsigned int  server_language;
  unsigned int  warning_count;
  struct st_mysql_options options;
  enum mysql_status status;
  my_bool       free_me;                /* If free in mysql_close */
  my_bool       reconnect;              /* set to 1 if automatic reconnect */
  
  /* session-wide random string */
  char          scramble[SCRAMBLE_LENGTH+1];
  
/*
   Set if this is the original connection, not a master or a slave we have
   added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()
*/
  my_bool rpl_pivot;
  /*
    Pointers to the master, and the next slave connections, points to
    itself if lone connection.
  */
  struct st_mysql* master, *next_slave;

  struct st_mysql* last_used_slave; /* needed for round-robin slave pick */
/* needed for send/read/store/use result to work correctly with replication */
  struct st_mysql* last_used_con;

  LIST  *stmts;                     /* list of all statements */
  const struct st_mysql_methods *methods;
  void *thd;
  /*
    Points to boolean flag in MYSQL_RES  or MYSQL_STMT. We set this flag
    from mysql_stmt_close if close had to cancel result set of this object.
  */
  my_bool *unbuffered_fetch_owner;
} MYSQL;



把insert_id理解成max(id)是錯(cuò)誤的,因?yàn)橛胁l(fā)存在。
結(jié)構(gòu)體里面有insert_id是針對(duì)當(dāng)前MYSQL連接的,而每次mysql_query操作在mysql服務(wù)器上可以理解為一次“原子”操作。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多