<commit_before>
/*
 * Copyright (C) 2015 <NAME>. All rights reserved.
 */

package org.jsimpledb.cli.cmd;

import org.jsimpledb.cli.CliSession;
import org.jsimpledb.core.Schema;
import org.jsimpledb.core.SchemaMismatchException;
import org.jsimpledb.core.Transaction;
import org.jsimpledb.schema.SchemaModel;

abstract class AbstractSchemaCommand extends AbstractCommand {

    AbstractSchemaCommand(String spec) {
        super(spec);
    }

    // Get the schema having the specified version
    protected static SchemaModel getSchemaModel(CliSession session, final int version) {

        // Version zero means "the configured schema"
        if (version == 0) {
            final SchemaModel schemaModel = session.getSchemaModel();
            if (schemaModel == null) {
                session.getWriter().println("No schema configured on this session");
                return null;
            }
            return schemaModel;
        }<commit_msg>Fix corner case bug in `show-schema' command.<commit_after>
/*
 * Copyright (C) 2015 <NAME>. All rights reserved.
 */

package org.jsimpledb.cli.cmd;

import org.jsimpledb.JSimpleDB;
import org.jsimpledb.cli.CliSession;
import org.jsimpledb.core.Schema;
import org.jsimpledb.core.SchemaMismatchException;
import org.jsimpledb.core.Transaction;
import org.jsimpledb.schema.SchemaModel;

abstract class AbstractSchemaCommand extends AbstractCommand {

    AbstractSchemaCommand(String spec) {
        super(spec);
    }

    // Get the schema having the specified version
    protected static SchemaModel getSchemaModel(CliSession session, final int version) {

        // Version zero means "the configured schema"
        if (version == 0) {
            SchemaModel schemaModel = session.getSchemaModel();
            if (schemaModel == null) {
                final JSimpleDB jdb = session.getJSimpleDB();
                if (jdb != null)
                    schemaModel = jdb.getSchemaModel();
            }
            if (schemaModel == null) {
                session.getWriter().println("No schema configured on this session");
                return null;
            }
            return schemaModel;
        }
{'fraction_non_alphanumeric': 0.08969641214351426, 'fraction_numerical': 0.004599816007359705, 'mean_word_length': 2.589108910891089, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '536006', 'n_tokens_mistral': 596, 'n_tokens_neox': 567, 'n_words': 157}