Any court, by order, may require an officer having the custody of any person confined in any prison in this state to produce such person before it for oral examination in the county where the person is imprisoned. In all other cases, except as otherwise provided in section 31-03-18, such person must be examined by deposition.
31-03-17. Prisoner in custody of officer while deposition is taken - Officer to provide facilities for taking deposition. While a prisoner's deposition is being taken, the prisoner shall remain in the custody of the officer having the prisoner in charge and such officer shall provide reasonable facilities for the taking of the deposition.
31-03-18. Attendance of prisoners as witnesses for state in criminal actions - How effected. When the testimony of a witness for the state is required in a criminal action, before a court of record of this state, and such witness is confined in the penitentiary or in a county jail, an order for the witness's temporary removal from the penitentiary or such jail, and for the witness's production before such court, may be made by the court in which the action is pending or by the judge authorized by law to preside at the trial of such action. If the penitentiary or such jail is not located in the county in which the application is made, such order shall be made only upon the affidavit of the state's attorney or some other person on behalf of the state showing that the testimony is material and necessary, and even then the granting of the order shall be in the discretion of the court or such judge. The order must be executed by the sheriff of the county in which it is made by delivering to the warden or jailer having such witness in charge a copy of such order, and the warden or jailer shall deliver the person so required to such officer and shall take such officer's receipt for the person endorsed upon the copy of such order. The officer receiving any such person shall take the person before the proper court, shall keep the person safely, and when the person is required no longer as a witness, shall return the person to the custody from which the person was received. Neither the warden nor the jailer shall be responsible for any such person until the person's return, and upon the return of any such person the warden or jailer, as the case may be, shall endorse the warden's or jailer's receipt upon the original order. The sheriff executing any such order shall return the same to the clerk of the district court of the county from which it was issued, and said clerk shall file and preserve the same among the papers in the action. The expense of executing such order shall be paid by the county in which the order shall be made.
31-03-19. Undertaking for appearance of material witness for state who appeared at preliminary examination - Minors. If, after a preliminary examination, a defendant is held to answer, the magistrate before whom the examination was held may require any material witness examined on the part of the state: 1. To enter into a written undertaking, without surety, to the effect that such witness will appear and testify at the court to which the complaint and depositions, if any, are to be sent, or that the witness will forfeit such sum as the magistrate may fix and determine; or 2. To enter into a written undertaking for the witness's appearance with such sureties and in such sum as the magistrate may deem proper, if the magistrate is satisfied, by proof on oath, that there is reason to believe that such witness will not appear and testify unless security is required. If any such material witness is a minor, any adult person may be allowed to give an undertaking for the minor's appearance, or the magistrate may take the undertaking of such minor in a sum not exceeding fifty dollars, which shall be valid and binding in law, notwithstanding the disability of minority.
31-03-20. Undertaking for appearance of material witness for state - When required - Procedure for requiring. If, after any material witness on the part of the prosecution has been discharged on the witness's undertaking without surety, it is satisfactorily shown on the sworn application of the state's attorney or of some other person on behalf of the state made to the magistrate before whom the preliminary examination was held, or to any judge, that the presence of such witness or any other person on the part of the prosecution is material or necessary on the trial in court, such magistrate, justice, or judge may compel such witness, or any other material witness on the part of the state, to give an undertaking with sureties, to appear on said trial and give testimony therein, and for that purpose, such magistrate, justice, or judge may issue a warrant against any such person directed to a sheriff, marshal, or other peace officer, to arrest such person and bring the person before such magistrate, justice, or judge.