(a) Whenever in the judgment of the Attorney General or any district attorney the testimony of any person or the production of evidence of any kind by any person in any criminal proceeding before a court or grand jury is necessary to the public interest, the Attorney General or the district attorney may request in writing the superior court to order such person to testify or produce the evidence. Upon order of the court, such person shall not be excused on the basis of the privilege against self-incrimination from testifying or producing any evidence required, but no testimony or other evidence required under the order or any information directly or indirectly derived from such testimony or evidence shall be used against the person in any proceeding or prosecution for a crime or offense concerning which he or she testified or produced evidence under court order. However, such person may nevertheless be prosecuted or subjected to penalty or forfeiture for any perjury, false swearing, or contempt committed in testifying or failing to testify or in producing or failing to produce evidence in accordance with the order but shall not be required to produce evidence that can be used in any other court of this state, the United States, or any other state. Any order entered under this Code section shall be entered of record in the minutes of the court so as to afford a permanent record thereof, and any testimony given by a person pursuant to such order shall be transcribed and filed for permanent record in the office of the clerk of the court.
(b) If a person refuses to testify after being granted immunity from prosecution and after being ordered to testify as set forth in this Code section, such person may be adjudged in contempt and committed to the county jail until such time as such person purges himself or herself of contempt by testifying as ordered without regard to the expiration of the grand jury. If the grand jury before which such person was ordered to testify has been dissolved, such person may purge himself or herself by testifying before the court.