(database string)
| 908 | } |
| 909 | |
| 910 | func (s *lockStatementImpl) String(database string) (sql string, err error) { |
| 911 | if !validIdentifierName(database) { |
| 912 | return "", errors.New("Invalid database name specified") |
| 913 | } |
| 914 | |
| 915 | if len(s.locks) == 0 { |
| 916 | return "", errors.New("No locks added") |
| 917 | } |
| 918 | |
| 919 | buf := new(bytes.Buffer) |
| 920 | _, _ = buf.WriteString("LOCK TABLES ") |
| 921 | |
| 922 | for idx, lock := range s.locks { |
| 923 | if lock.t == nil { |
| 924 | return "", errors.Newf("nil table. Generated sql: %s", buf.String()) |
| 925 | } |
| 926 | |
| 927 | if err = lock.t.SerializeSql(database, buf); err != nil { |
| 928 | return |
| 929 | } |
| 930 | |
| 931 | if lock.w { |
| 932 | _, _ = buf.WriteString(" WRITE") |
| 933 | } else { |
| 934 | _, _ = buf.WriteString(" READ") |
| 935 | } |
| 936 | |
| 937 | if idx != len(s.locks)-1 { |
| 938 | _, _ = buf.WriteString(", ") |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | return buf.String(), nil |
| 943 | } |
| 944 | |
| 945 | // NewUnlockStatement returns SQL statement that can be used to release table locks |
| 946 | // grabbed by the current session. |
nothing calls this directly
no test coverage detected