Beispiel #1
0
    //Add the word list title
    private void addListTitle()
    {
        bool lastInsert = false;

        deactivateLists();
        string sql = "INSERT INTO SM_WordList (title, isActive) VALUES(?,?) ";

        dbManager.Execute(sql, txtListName.text, 1);

        string   lastRowQuery = "SELECT id from SM_WordList order by id DESC limit 1";
        lastDBId lastWordID   = dbManager.QueryFirstRecord <lastDBId> (out lastInsert, lastRowQuery);

        PlayerPrefs.SetInt("ActiveWordList", int.Parse(lastWordID.id));
    }
    private string loadListName(int listID)
    {
        string    listName     = "";
        bool      recordExists = false;
        string    sql          = "SELECT * FROM SM_WordList WHERE id = " + listID;
        wordTitle myTitle      = dbManager.QueryFirstRecord <wordTitle>(out recordExists, sql);

        if (recordExists)
        {
            listName = myTitle.title;
        }

        return(listName);
    }
Beispiel #3
0
    //void OnPlayerConnected(NetworkPlayer client) {
    //	connectionCount++;
    //	Debug.Log("Client " + connectionCount + " connected from " + client.ipAddress + ":" + client.port);
    //	outputTxt.text = outputTxt.text + "Client " + connectionCount + " connected from " + client.ipAddress + ":" + client.port + "\n";

    //	//WORDLIST NAME
    //	string listname = getListName ();

    //	//AUDIO
    //	List<wordPackage> myWordPkg = new List<wordPackage>();


    //	List<wordContent> myWords = getWords ();
    //	foreach (wordContent word in myWords) {
    //		wordPackage newPkg = new wordPackage();
    //		newPkg.word = word.word;
    //		newPkg.audio = "";
    //		//Add audio
    //		if(wordHasAudio (word.id.ToString ())){
    //			byte[] bytes = File.ReadAllBytes(Application.persistentDataPath + "/" + word.id + ".wav");
    //			newPkg.audio = Convert.ToBase64String (bytes);
    //		}
    //		myWordPkg.Add(newPkg);
    //	}

    //	listPayload testPayload = new listPayload{ listName=listname,wordsPackage=myWordPkg };

    //	BinaryFormatter binFormatter = new BinaryFormatter(); // Create Formatter and Stream to process our data
    //	MemoryStream memStream = new MemoryStream();

    //	binFormatter.Serialize(memStream, testPayload); // We Serialize our plInfo object using the memStream
    //	byte[] serializedWLInfo = memStream.ToArray(); // We convert the contents of the stream (which now contains our object) into a byte array.

    //	memStream.Close(); // Close our stream!

    //	//SEND PAYLOAD
    //	//networkView.RPC ("GetPayload", client, serializedWLInfo);
    //	Debug.Log ("Sent Payload Via RPC!");
    //}

    private string getListName()
    {
        string        curShareId   = PlayerPrefs.GetInt("ShareWordList").ToString();
        string        listName     = "";
        bool          recordExists = false;
        string        sql          = "SELECT * FROM SM_WordList WHERE id = " + curShareId;
        wordListTitle myTitle      = dbManager.QueryFirstRecord <wordListTitle>(out recordExists, sql);

        if (recordExists)
        {
            listName = myTitle.title;
        }

        return(listName);
    }
        ///  <summary>
        /// Adds and image to the database as a blob
        ///  </summary>
        public void AddImage()
        {
            var path = imagePath.text.Trim();

            // check that the path exists
            if (!File.Exists(path))
            {
                Debug.LogError("Path does not exist! " + imagePath.text);
                return;
            }

            var id = 1;
            // read the bytes of the file from the path
            var imageData = File.ReadAllBytes(path);

            // get the next ID from the database
            var  sql = "SELECT MAX(ID) + 1 ID FROM Images";
            bool recordExists;
            var  result = dbManager.QueryFirstRecord <Images>(out recordExists, sql);

            if (recordExists)
            {
                id = result.ID;
            }

            // insert the image as a byte array
            sql = "INSERT INTO Images (ID, ImageData) VALUES (?, ?)";
            dbManager.Execute(sql, id, imageData);

            // reload images
            LoadImages();
        }
    private bool wordHasAudio()
    {
        bool hasAudio = false;

        string       sql     = "SELECT fileName FROM SM_WordAudio WHERE wordID = " + PlayerPrefs.GetInt("CurGameWord");
        audioContent myAudio = dbManager.QueryFirstRecord <audioContent> (out hasAudio, sql);

        return(hasAudio);
    }
    private int getActiveList()
    {
        bool lastInsert   = false;
        int  activeListID = 0;
        //listDB lastWordID = new listDB();
        string lastRowQuery = "SELECT id from SM_WordList WHERE isActive = 1 ORDER BY id DESC limit 1";
        listDB lastWordID   = dbManager.QueryFirstRecord <listDB>(out lastInsert, lastRowQuery);

        if (lastInsert)
        {
            activeListID = int.Parse(lastWordID.id);
        }

        return(activeListID);
    }
        /// <summary>查找一条数据</summary>
        public CacheInfo QueryFirstRecord(string dataName)
        {
            bool recordExists;

            return(m_DbManager.QueryFirstRecord <CacheInfo>(out recordExists, "SELECT * FROM CacheInfo WHERE Name = ?", dataName));
        }