1 line
9.2 KiB
JavaScript
1 line
9.2 KiB
JavaScript
"use strict";(self.webpackChunkdocusaurus=self.webpackChunkdocusaurus||[]).push([[582],{511:(e,s,r)=>{r.r(s),r.d(s,{assets:()=>l,contentTitle:()=>c,default:()=>x,frontMatter:()=>i,metadata:()=>t,toc:()=>o});const t=JSON.parse('{"id":"typedefs/okpacket","title":"OkPacket","description":"Object","source":"@site/docs/typedefs/okpacket.md","sourceDirName":"typedefs","slug":"/typedefs/okpacket","permalink":"/awSQL/typedefs/okpacket","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"sidebar_position":1},"sidebar":"defaultSidebar","previous":{"title":"Typedefs","permalink":"/awSQL/category/typedefs"},"next":{"title":"ColumnStructure","permalink":"/awSQL/typedefs/column-structure"}}');var n=r(4848),d=r(8453);const i={sidebar_position:1},c="OkPacket",l={},o=[{value:"Structure",id:"structure",level:2},{value:"Common <code>serverStatus</code> Flags",id:"common-serverstatus-flags",level:2}];function h(e){const s={admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",header:"header",li:"li",p:"p",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,d.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.header,{children:(0,n.jsx)(s.h1,{id:"okpacket",children:"OkPacket"})}),"\n",(0,n.jsx)(s.p,{children:(0,n.jsx)(s.code,{children:"Object"})}),"\n",(0,n.jsx)(s.p,{children:"The OkPacket is a response object from MySQL that provides metadata about a successfully executed query. It contains details such as the number of affected rows, insert IDs, server status, warnings, and protocol information. This packet is typically returned for INSERT, UPDATE, DELETE, and other non-SELECT statements."}),"\n",(0,n.jsx)(s.h2,{id:"structure",children:"Structure"}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.th,{children:"Property"}),(0,n.jsx)(s.th,{children:"Type"}),(0,n.jsx)(s.th,{children:"Description"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"fieldCount"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"Number"})}),(0,n.jsxs)(s.td,{children:["Defaults to ",(0,n.jsx)(s.code,{children:"0"})," for non-",(0,n.jsx)(s.code,{children:"SELECT"})," queries."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"affectedRows"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"Number"})}),(0,n.jsxs)(s.td,{children:["The number of rows affected by the query (",(0,n.jsx)(s.em,{children:"does not necessarily mean all rows were changed"}),")."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"insertId"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"Number"})}),(0,n.jsxs)(s.td,{children:["The ID of the last inserted row (",(0,n.jsxs)(s.em,{children:["if an auto-increment column exists, otherwise ",(0,n.jsx)(s.code,{children:"0"})]}),")."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"serverStatus"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"Number"})}),(0,n.jsx)(s.td,{children:"A bitmask flag representing the current state of the MySQL server."})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"warningCount"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"Number"})}),(0,n.jsx)(s.td,{children:"The number of warnings generated during query execution."})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"message"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"String"})}),(0,n.jsxs)(s.td,{children:["An optional message providing additional information about the query result (",(0,n.jsx)(s.em,{children:"typically empty"}),")."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"protocol41"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"Boolean"})}),(0,n.jsxs)(s.td,{children:[(0,n.jsx)(s.code,{children:"true"})," if MySQL protocol 4.1 or later is used."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"changedRows"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"Number"})}),(0,n.jsx)(s.td,{children:"The number of rows actually modified by the query."})]})]})]}),"\n",(0,n.jsxs)(s.h2,{id:"common-serverstatus-flags",children:["Common ",(0,n.jsx)(s.code,{children:"serverStatus"})," Flags"]}),"\n",(0,n.jsxs)(s.admonition,{title:"Bitmask Behavior",type:"info",children:[(0,n.jsxs)(s.p,{children:[(0,n.jsx)(s.code,{children:"serverStatus"})," is a ",(0,n.jsx)(s.strong,{children:"bitmask"}),", meaning multiple statuses can be active at the same time."]}),(0,n.jsx)(s.p,{children:"For example:"}),(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsxs)(s.li,{children:[(0,n.jsx)(s.code,{children:"SERVER_STATUS_AUTOCOMMIT"})," (",(0,n.jsx)(s.code,{children:"1"}),") + ",(0,n.jsx)(s.code,{children:"SERVER_STATUS_IN_TRANS"})," (",(0,n.jsx)(s.code,{children:"2"}),")"]}),"\n",(0,n.jsxs)(s.li,{children:["These combine to ",(0,n.jsx)(s.code,{children:"3"})," (",(0,n.jsx)(s.code,{children:"1"})," | ",(0,n.jsx)(s.code,{children:"2"})," = ",(0,n.jsx)(s.code,{children:"3"}),") through a ",(0,n.jsx)(s.strong,{children:"bitwise OR"})," operation."]}),"\n"]})]}),"\n",(0,n.jsxs)(s.table,{children:[(0,n.jsx)(s.thead,{children:(0,n.jsxs)(s.tr,{children:[(0,n.jsxs)(s.th,{children:[(0,n.jsx)(s.code,{children:"serverStatus"}),"-Value"]}),(0,n.jsx)(s.th,{children:"Status"}),(0,n.jsx)(s.th,{children:"Description"})]})}),(0,n.jsxs)(s.tbody,{children:[(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"1"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_AUTOCOMMIT"})}),(0,n.jsxs)(s.td,{children:["The server is in ",(0,n.jsx)(s.strong,{children:"autocommit mode"}),", treating each query as a seperate transaction that commits automatically."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"2"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_IN_TRANS"})}),(0,n.jsxs)(s.td,{children:["The server is currently in a ",(0,n.jsx)(s.strong,{children:"transaction"})," (",(0,n.jsx)(s.em,{children:"queries have not been committed yet"}),")."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"8"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_MORE_RESULTS_EXISTS"})}),(0,n.jsxs)(s.td,{children:["More result sets exist (",(0,n.jsxs)(s.em,{children:["e.g., when executing a ",(0,n.jsx)(s.code,{children:"SELECT ... INTO OUTFILE"})," query"]}),")."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"16"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_NO_GOOD_INDEX_USED"})}),(0,n.jsxs)(s.td,{children:["The server did not use an ",(0,n.jsx)(s.strong,{children:"optimal index"})," for the query, which may indicate inefficient execution."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"32"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_NO_INDEX_USED"})}),(0,n.jsxs)(s.td,{children:["The query was executed ",(0,n.jsx)(s.strong,{children:"without an index"}),", likely causing a full table scan (",(0,n.jsx)(s.em,{children:"may impact performance"}),")."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"64"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_QUERY_NO_GOOD_INDEX_USED"})}),(0,n.jsxs)(s.td,{children:["No ",(0,n.jsx)(s.strong,{children:"suitable index"})," was used during query execution (",(0,n.jsx)(s.em,{children:"could result in performance issues"}),")."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"128"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_CURSOR_EXISTS"})}),(0,n.jsxs)(s.td,{children:["A ",(0,n.jsx)(s.strong,{children:"cursor"})," exists and is in use for this query (",(0,n.jsx)(s.em,{children:"typically seen in more complex queries"}),")."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"256"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_LAST_INSERT_ID"})}),(0,n.jsxs)(s.td,{children:["The ",(0,n.jsxs)(s.strong,{children:["last executed ",(0,n.jsx)(s.code,{children:"INSERT"})," statement"]})," generated an ",(0,n.jsx)(s.code,{children:"AUTO_INCREMENT"})," ID."]})]}),(0,n.jsxs)(s.tr,{children:[(0,n.jsx)(s.td,{children:(0,n.jsx)(s.strong,{children:"512"})}),(0,n.jsx)(s.td,{children:(0,n.jsx)(s.code,{children:"SERVER_STATUS_DB_DROPPED"})}),(0,n.jsxs)(s.td,{children:["A ",(0,n.jsx)(s.strong,{children:"database was dropped"})," as part of the executed query."]})]})]})]})]})}function x(e={}){const{wrapper:s}={...(0,d.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},8453:(e,s,r)=>{r.d(s,{R:()=>i,x:()=>c});var t=r(6540);const n={},d=t.createContext(n);function i(e){const s=t.useContext(d);return t.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function c(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),t.createElement(d.Provider,{value:s},e.children)}}}]); |